Skip to content

Commit

Permalink
azurerm_batch_account - allow update for `public_network_access_ena…
Browse files Browse the repository at this point in the history
…bled` (#22095)
  • Loading branch information
myc2h6o authored Jun 9, 2023
1 parent 3d10d0a commit e91c8ec
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
9 changes: 8 additions & 1 deletion internal/services/batch/batch_account_resource.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit e91c8ec

Please sign in to comment.