diff --git a/internal/services/batch/batch_pool.go b/internal/services/batch/batch_pool.go index 08f50ba894c9..579068a82334 100644 --- a/internal/services/batch/batch_pool.go +++ b/internal/services/batch/batch_pool.go @@ -4,6 +4,7 @@ package batch import ( + "encoding/json" "fmt" "log" "strconv" @@ -868,11 +869,17 @@ func expandBatchPoolExtension(ref map[string]interface{}) (*pool.VmExtension, er } if settings, ok := ref["settings_json"]; ok { - result.Settings = pointer.To(settings) + err := json.Unmarshal([]byte(settings.(string)), &result.Settings) + if err != nil { + return nil, fmt.Errorf("unmarshaling `settings_json`: %+v", err) + } } if protectedSettings, ok := ref["protected_settings"]; ok { - result.ProtectedSettings = pointer.To(protectedSettings) + err := json.Unmarshal([]byte(protectedSettings.(string)), &result.ProtectedSettings) + if err != nil { + return nil, fmt.Errorf("unmarshaling `protected_settings`: %+v", err) + } } if tmpItem, ok := ref["provision_after_extensions"]; ok { diff --git a/internal/services/batch/batch_pool_resource.go b/internal/services/batch/batch_pool_resource.go index b330786f36a8..16bf36277461 100644 --- a/internal/services/batch/batch_pool_resource.go +++ b/internal/services/batch/batch_pool_resource.go @@ -1208,7 +1208,10 @@ func resourceBatchPoolRead(d *pluginsdk.ResourceData, meta interface{}) error { extension["automatic_upgrade_enabled"] = *item.EnableAutomaticUpgrade } if item.Settings != nil { - extension["settings_json"] = item.Settings + extension["settings_json"], err = pluginsdk.FlattenJsonToString((*item.Settings).(map[string]interface{})) + if err != nil { + return fmt.Errorf("flattening `settings_json`: %+v", err) + } } for i := 0; i < n; i++ { diff --git a/internal/services/batch/batch_pool_resource_test.go b/internal/services/batch/batch_pool_resource_test.go index 41f118e980d6..1c1bb1f81761 100644 --- a/internal/services/batch/batch_pool_resource_test.go +++ b/internal/services/batch/batch_pool_resource_test.go @@ -692,15 +692,12 @@ func TestAccBatchPool_extensions(t *testing.T) { Config: r.extensions(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("extensions.0.name").HasValue("KeyVaultForLinux"), - check.That(data.ResourceName).Key("extensions.0.publisher").HasValue("Microsoft.Azure.KeyVault"), - check.That(data.ResourceName).Key("extensions.0.type").HasValue("KeyVaultForLinux"), - check.That(data.ResourceName).Key("extensions.0.type_handler_version").HasValue("2.0"), + check.That(data.ResourceName).Key("extensions.0.name").HasValue("OmsAgentForLinux"), + check.That(data.ResourceName).Key("extensions.0.publisher").HasValue("Microsoft.EnterpriseCloud.Monitoring"), + check.That(data.ResourceName).Key("extensions.0.type").HasValue("OmsAgentForLinux"), + check.That(data.ResourceName).Key("extensions.0.type_handler_version").HasValue("1.17"), check.That(data.ResourceName).Key("extensions.0.auto_upgrade_minor_version").HasValue("true"), check.That(data.ResourceName).Key("extensions.0.automatic_upgrade_enabled").HasValue("true"), - check.That(data.ResourceName).Key("extensions.0.settings_json").HasValue("{}"), - check.That(data.ResourceName).Key("extensions.0.protected_settings").HasValue("sensitive"), - check.That(data.ResourceName).Key("extensions.0.provision_after_extensions.0").HasValue("newProv1"), ), }, }) @@ -2360,6 +2357,15 @@ resource "azurerm_batch_account" "test" { resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location } + +resource "azurerm_log_analytics_workspace" "test" { + name = "testaccloganalytics%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku = "PerGB2018" + retention_in_days = 30 +} + resource "azurerm_batch_pool" "test" { name = "testaccpool%s" resource_group_name = azurerm_resource_group.test.name @@ -2367,15 +2373,14 @@ resource "azurerm_batch_pool" "test" { node_agent_sku_id = "batch.node.ubuntu 22.04" vm_size = "Standard_A1" extensions { - name = "KeyVaultForLinux" - publisher = "Microsoft.Azure.KeyVault" - type = "KeyVaultForLinux" - type_handler_version = "2.0" + name = "OmsAgentForLinux" + publisher = "Microsoft.EnterpriseCloud.Monitoring" + settings_json = jsonencode({ "workspaceId" = "${azurerm_log_analytics_workspace.test.id}", "skipDockerProviderInstall" = true }) + protected_settings = jsonencode({ "workspaceKey" = "${azurerm_log_analytics_workspace.test.primary_shared_key}" }) + type = "OmsAgentForLinux" + type_handler_version = "1.17" auto_upgrade_minor_version = true automatic_upgrade_enabled = true - settings_json = "{}" - protected_settings = "sensitive" - provision_after_extensions = ["newProv1"] } fixed_scale { target_dedicated_nodes = 1 @@ -2387,7 +2392,7 @@ resource "azurerm_batch_pool" "test" { version = "latest" } } -`, template, data.RandomString, data.RandomString) +`, template, data.RandomString, data.RandomString, data.RandomString) } func (BatchPoolResource) diskSettings(data acceptance.TestData) string {