如何在Terraform中指定azurerm_linux_web_app存储块的NFS挂载类型
问题描述
将NFS文件共享挂载至Linux App Service时,需指定SMB或NFS协议。已在存储共享中设置enabled_protocol为NFS,但azurerm_linux_web_app资源的storage块无直接的挂载类型输入项,部署时默认使用SMB。请问应在何处指定该类型,或是配置有误?
现有代码片段
azurerm_linux_web_app中的storage块:
storage_account { name = "sonar-data" access_key = module.sonar_storage_account.primary_access_keys[0] account_name = module.sonar_storage_account.sa_names[0] share_name = "sonar-data" type = "AzureFiles" mount_path = "/mnt/sonar-data" }
存储共享代码:
resource "azurerm_storage_share" "sonar_storage_account" { for_each = var.sonarqube_storage_shares name = each.value.name storage_account_name = module.sonar_storage_account.sa_names[0] access_tier = each.value.access_tier quota = each.value.quota enabled_protocol = each.value.enabled_protocol }
存储共享的变量输入:
sonarqube_storage_shares = { data = { name = "sonar-data" quota = 100 access_tier = "Premium" enabled_protocol = "NFS" } sonarqube = { name = "sonarqube" quota = 100 access_tier = "Premium" enabled_protocol = "NFS" } }
解决方案
在azurerm_linux_web_app的storage_account块里,需要新增azure_files_config子块来明确指定使用NFS协议。默认情况下,AzureFiles类型会走SMB,必须显式配置protocol = "NFS"才能切换到NFS。
修改后的storage_account块代码如下:
storage_account { name = "sonar-data" access_key = module.sonar_storage_account.primary_access_keys[0] account_name = module.sonar_storage_account.sa_names[0] share_name = "sonar-data" type = "AzureFiles" mount_path = "/mnt/sonar-data" azure_files_config { protocol = "NFS" } }
关键说明
- 存储账户必须是Premium FileStorage层级,你的配置里已经设置了
access_tier = "Premium",这部分没问题。 - 存储共享的
enabled_protocol已经设为NFS,符合要求,不需要修改。 - Linux App Service的运行时支持NFS挂载,只要配置正确就能生效。
内容的提问来源于stack exchange,提问作者Anthony Miller
相关产品推荐
相关产品推荐

