I’ve got a deployment to do in azure, using terraform. I’m trying to couple some file shares to an Azure Container Instance, but it doesn’t seem to work well.
I’m using following pieces of code:
resource "azurerm_storage_account" "file_share_storage_account" {
name = "st${var.lztri}${substr(var.st_file_share.name, 0, 3)}${var.env}${var.loc}${var.stage}01"
resource_group_name = azurerm_resource_group.storage_rg.name
location = var.location
account_replication_type = var.st_file_share.account_replication_type
account_kind = var.st_file_share.account_kind
access_tier = var.st_file_share.access_tier
enable_https_traffic_only = var.st_file_share.enable_https_traffic_only
min_tls_version = var.st_file_share.min_tls_version
is_hns_enabled = var.st_file_share.is_hns_enabled // must be true for ADLS Gen2
account_tier = var.st_file_share.account_tier // must be Standard for HNS enabled
public_network_access_enabled = true
default_to_oauth_authentication = true
dynamic "network_rules" {
for_each = local.st_net_rules
content {
default_action = network_rules.value.default_action
bypass = network_rules.value.bypass
ip_rules = network_rules.value.ip_rules
virtual_network_subnet_ids = network_rules.value.virtual_network_subnet_ids
}
}
tags = merge(local.mandatory_tags, { })
lifecycle { ignore_changes = [tags] }
}
/* resource "azurerm_role_assignment" "st_role_assignment" {
for_each = var.st_file_share
scope = azurerm_storage_account.file_share_storage_account[each.key].id
role_definition_name = "Storage Blob Data Contributor"
principal_id = data.azurerm_client_config.client_config.object_id
} */
resource "azurerm_role_assignment" "st_role_assignment" {
for_each = toset(["Storage Blob Data Contributor"])
scope = azurerm_storage_account.file_share_storage_account.id
role_definition_name = each.key
principal_id = data.azurerm_client_config.client_config.object_id
}
resource "azurerm_storage_share" "file_share" {
for_each = { for each in var.shares_config : each.share_name => each }
name = each.value.share_name
quota = each.value.quota_gb
storage_account_name = azurerm_storage_account.file_share_storage_account.name
}
resource "azurerm_container_group" "containergroup" {
name = "ci-${var.lztri}-sonarqube-${var.env}-${var.loc}${var.stage != "" ? "-" : ""}${var.stage}-01"
location = var.location
resource_group_name = azurerm_resource_group.sonarqube_rg.name
ip_address_type = var.ci_sonarqube_ip_address_type
os_type = var.ci_sonarqube_os_type
container {
name = var.ci_sonarqube_container_name
image = var.ci_sonarqube_image_name
cpu = var.ci_sonarqube_cpu_core_number
memory = var.ci_sonarqube_memory_size
ports {
port = var.ci_sonarqube_ports
protocol = var.ci_sonarqube_protocol
}
dynamic "volume" {
for_each = var.shares_config
content {
name = volume.value.share_name
mount_path = "/opt/sonarqube/${volume.value.share_name}"
share_name = volume.value.share_name
storage_account_name = azurerm_storage_account.file_share_storage_account.name
storage_account_key = azurerm_storage_account.file_share_storage_account.primary_access_key
}
}
}
timeouts {
create = "2h"
delete = "15m"
}
}
I’m always getting following error:
polling after ContainerGroupsCreateOrUpdate: Code="Failed" Message="The async operation failed." AdditionalInfo=[{"error":{"message":"Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Failed to mount Azure File Volume.;Subscription deployment didn’t reach a successful provisioning state after ’00:30:00′."}
Strange that the error is repeated this amount of times, there’s only 4 shares…
2
Answers
In the end, it seemed that the networking part of the storage account was to closed down, the container couldn't connect to it.
Here is the updated code to create multiple
Azure File shares
and mount the same to aContainer Instance
Terraform Apply:
After running the above code, three file shares have been created in the
Azure Storage account
and the same shares are mounted to the container instances.Reference: Terraform Azure Container Instance Dynamic Volume – share_name loop over azurerm_storage_share by
Matt Schuchard