diff --git a/internal/services/batch/batch_pool.go b/internal/services/batch/batch_pool.go index 0f8a80f436fc..821e572081d3 100644 --- a/internal/services/batch/batch_pool.go +++ b/internal/services/batch/batch_pool.go @@ -1014,9 +1014,9 @@ func expandBatchPoolAzureBlobFileSystemConfiguration(list []interface{}) (*pool. RelativeMountPath: configMap["relative_mount_path"].(string), } - if accountKey, ok := configMap["account_key"]; ok { + if accountKey, ok := configMap["account_key"]; ok && accountKey != "" { result.AccountKey = utils.String(accountKey.(string)) - } else if sasKey, ok := configMap["sas_key"]; ok { + } else if sasKey, ok := configMap["sas_key"]; ok && sasKey != "" { result.SasKey = utils.String(sasKey.(string)) } else if computedIDRef, err := expandBatchPoolIdentityReference(configMap); err == nil { result.IdentityReference = computedIDRef diff --git a/internal/services/batch/batch_pool_resource_test.go b/internal/services/batch/batch_pool_resource_test.go index 37269a3e887c..94744c6f3dd2 100644 --- a/internal/services/batch/batch_pool_resource_test.go +++ b/internal/services/batch/batch_pool_resource_test.go @@ -536,6 +536,27 @@ func TestAccBatchPool_mountConfigurationAzureBlobFileSystem(t *testing.T) { }) } +func TestAccBatchPool_mountConfigurationAzureBlobFileSystemWithUserAssignedIdentity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") + r := BatchPoolResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.mountConfigurationAzureBlobFileSystemWithUserAssignedIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("mount.0.azure_blob_file_system.#").HasValue("1"), + check.That(data.ResourceName).Key("mount.0.azure_blob_file_system.0.relative_mount_path").HasValue("/mnt/"), + check.That(data.ResourceName).Key("mount.0.azure_blob_file_system.0.identity_id").Exists(), + ), + }, + data.ImportStep( + "stop_pending_resize_operation", + "mount.0.azure_blob_file_system.0.account_key", + ), + }) +} + func TestAccBatchPool_mountConfigurationAzureFileShare(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") r := BatchPoolResource{} @@ -2018,6 +2039,74 @@ resource "azurerm_batch_pool" "test" { `, template, data.RandomString, data.RandomString, data.RandomString, data.RandomString) } +func (BatchPoolResource) mountConfigurationAzureBlobFileSystemWithUserAssignedIdentity(data acceptance.TestData) string { + template := BatchPoolResource{}.template(data) + return fmt.Sprintf(` +%s +resource "azurerm_storage_account" "test" { + name = "accbatchsa%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_container" "test" { + name = "accbatchsc%s" + storage_account_name = azurerm_storage_account.test.name + container_access_type = "blob" +} + +resource "azurerm_batch_account" "test" { + name = "testaccbatch%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +resource "azurerm_user_assigned_identity" "test" { + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + name = "testidentity%s" +} + +resource "azurerm_role_assignment" "blob_contributor" { + principal_id = azurerm_user_assigned_identity.test.principal_id + role_definition_name = "Storage Blob Data Contributor" + scope = azurerm_storage_account.test.id +} + +resource "azurerm_batch_pool" "test" { + name = "testaccpool%s" + resource_group_name = azurerm_resource_group.test.name + account_name = azurerm_batch_account.test.name + display_name = "Test Acc Pool Auto" + vm_size = "Standard_A1" + node_agent_sku_id = "batch.node.ubuntu 20.04" + + fixed_scale { + target_dedicated_nodes = 0 + } + + storage_image_reference { + publisher = "microsoft-azure-batch" + offer = "ubuntu-server-container" + sku = "20-04-lts" + version = "latest" + } + + mount { + azure_blob_file_system { + account_name = azurerm_storage_account.test.name + container_name = azurerm_storage_container.test.name + relative_mount_path = "/mnt/" + identity_id = azurerm_user_assigned_identity.test.id + } + } +} +`, template, data.RandomString, data.RandomString, data.RandomString, data.RandomString, data.RandomString) +} + func (BatchPoolResource) mountConfigurationAzureFileShare(data acceptance.TestData) string { template := BatchPoolResource{}.template(data) return fmt.Sprintf(`