【发布时间】:2021-06-02 23:55:52
【问题描述】:
我有以下 terraform 代码创建 azure 存储文件共享。
resource "azurerm_storage_share" "jms-sftp-share" {
for_each = toset(["one", "two", "three"])
name = each.key
quota = 5120
storage_account_name = azurerm_storage_account.working-storage_account.name
acl {
id = "${each.key}_this_is_my_id"
access_policy {
permissions = "rwl"
}
}
}
我正在尝试创建一个 azurerm_container_instance,其中包含一个动态卷块,该卷块通过循环 azurerm_storage_share.jms-sftp-share 来获取它的共享名。
resource "azurerm_container_group" "jms-sftp" {
dns_name_label = "doccji-dts-dev-jms-sftp"
exposed_port = [
{
port = 22
protocol = "TCP"
},
]
location = var.resource-location
name = "${local.resource-name-prefix}-sftp-1"
os_type = "Linux"
resource_group_name = local.resource-group-name
restart_policy = "Always"
tags = merge(local.common_tags, tomap({ "type" = "docker-sftp-server" }))
container {
commands = []
cpu = 1
image = "atmoz/sftp:latest"
memory = 1.5
name = "jms-sftp-1"
ports {
port = 22
protocol = "TCP"
}
dynamic "volume" {
for_each = [for v in azurerm_storage_share.jms-sftp-share : {
name = v.name
}]
content {
empty_dir = false
mount_path = "/home/${volume.value.name}"
name = "${volume.value.name}-home-folder"
read_only = false
share_name = azurerm_storage_share.jms-sftp-share[volume.value.name]
storage_account_key = azurerm_storage_account.working-storage_account.primary_access_key
storage_account_name = azurerm_storage_account.working-storage_account.name
}
}
volume {
empty_dir = false
mount_path = "/etc/sftp"
name = "sftp-users-conf"
read_only = true
share_name = azurerm_storage_share.jms-sftp-users-share.name
storage_account_key = azurerm_storage_account.working-storage_account.primary_access_key
storage_account_name = azurerm_storage_account.working-storage_account.name
}
}
depends_on = [
azurerm_storage_share.jms-sftp-share,
azurerm_storage_share.jms-sftp-users-share
]
}
我遇到以下错误:
Error: Incorrect attribute value type
on container-instance.tf line 36, in resource "azurerm_container_group" "jms-sftp":
36: share_name = azurerm_storage_share.jms-sftp-share[volume.value.name]
|----------------
| azurerm_storage_share.jms-sftp-share is object with 3 attributes
Inappropriate value for attribute "share_name": string required.
Error: Incorrect attribute value type
on container-instance.tf line 36, in resource "azurerm_container_group" "jms-sftp":
36: share_name = azurerm_storage_share.jms-sftp-share[volume.value.name]
|----------------
| azurerm_storage_share.jms-sftp-share is object with 3 attributes
Inappropriate value for attribute "share_name": string required.
Error: Incorrect attribute value type
on container-instance.tf line 36, in resource "azurerm_container_group" "jms-sftp":
36: share_name = azurerm_storage_share.jms-sftp-share[volume.value.name]
|----------------
| azurerm_storage_share.jms-sftp-share is object with 3 attributes
Inappropriate value for attribute "share_name": string required.
我相信我明白它的意思,但我不知道如何设置
share_name = azurerm_storage_share.jms-sftp-share[volume.value.name]
正确引用关联的共享。
如果我将 share_name 更改为
share_name = azurerm_storage_share.jms-sftp-share[volume.value.name.name]
我得到的输出表明我之前的符号是正确的,但我只是不确定该去哪里。
Error: Unsupported attribute
on container-instance.tf line 36, in resource "azurerm_container_group" "jms-sftp":
36: share_name = azurerm_storage_share.jms-sftp-share[volume.value.name.name]
|----------------
| volume.value.name is "one"
This value does not have any attributes.
Error: Unsupported attribute
on container-instance.tf line 36, in resource "azurerm_container_group" "jms-sftp":
36: share_name = azurerm_storage_share.jms-sftp-share[volume.value.name.name]
|----------------
| volume.value.name is "two"
This value does not have any attributes.
Error: Unsupported attribute
on container-instance.tf line 36, in resource "azurerm_container_group" "jms-sftp":
36: share_name = azurerm_storage_share.jms-sftp-share[volume.value.name.name]
|----------------
| volume.value.name is "three"
This value does not have any attributes.
有什么想法吗?
【问题讨论】:
标签: terraform terraform-provider-azure