Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_batch_account - allow update for public_network_access_enabled #22095

Merged
merged 1 commit into from Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/services/batch/batch_account_resource.go
Expand Up @@ -108,7 +108,6 @@ func resourceBatchAccount() *pluginsdk.Resource {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
ForceNew: true,
},

"key_vault_reference": {
Expand Down Expand Up @@ -398,6 +397,14 @@ func resourceBatchAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) err
}
}

if d.HasChange("public_network_access_enabled") {
if d.Get("public_network_access_enabled").(bool) {
parameters.Properties.PublicNetworkAccess = utils.ToPtr(batchaccount.PublicNetworkAccessTypeEnabled)
} else {
parameters.Properties.PublicNetworkAccess = utils.ToPtr(batchaccount.PublicNetworkAccessTypeDisabled)
}
}

if d.HasChange("storage_account_id") {
if v, ok := d.GetOk("storage_account_id"); ok {
parameters.Properties.AutoStorage = &batchaccount.AutoStorageBaseProperties{
Expand Down
52 changes: 52 additions & 0 deletions internal/services/batch/batch_account_resource_test.go
Expand Up @@ -256,6 +256,36 @@ func TestAccBatchAccount_autoStorageBatchAuthMode(t *testing.T) {
})
}

func TestAccBatchAccount_publicNetworkAccess(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_account", "test")
r := BatchAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access_enabled").HasValue("true"),
),
},
data.ImportStep(),
{
Config: r.basicWithPublicNetWorkAccessDisabled(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccBatchAccount_removeStorageAccountId(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_batch_account", "test")
r := BatchAccountResource{}
Expand Down Expand Up @@ -953,3 +983,25 @@ resource "azurerm_batch_account" "test" {
}
`, data.RandomInteger, data.Locations.Secondary, data.RandomString, data.RandomString, data.RandomString)
}

func (BatchAccountResource) basicWithPublicNetWorkAccessDisabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "testaccRG-batch-%d"
location = "%s"
}

resource "azurerm_batch_account" "test" {
name = "testaccbatch%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
pool_allocation_mode = "BatchService"

public_network_access_enabled = false
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}
2 changes: 1 addition & 1 deletion website/docs/r/batch_account.html.markdown
Expand Up @@ -57,7 +57,7 @@ The following arguments are supported:

* `pool_allocation_mode` - (Optional) Specifies the mode to use for pool allocation. Possible values are `BatchService` or `UserSubscription`. Defaults to `BatchService`.

* `public_network_access_enabled` - (Optional) Whether public network access is allowed for this server. Defaults to `true`. Changing this forces a new resource to be created.
* `public_network_access_enabled` - (Optional) Whether public network access is allowed for this server. Defaults to `true`.

~> **NOTE:** When using `UserSubscription` mode, an Azure KeyVault reference has to be specified. See `key_vault_reference` below.

Expand Down