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_pool - fix accessing azure_blob_file_system with user_identity assigned. #20560

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/services/batch/batch_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
89 changes: 89 additions & 0 deletions internal/services/batch/batch_pool_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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(`
Expand Down