我有下面的terraform代码,创建蔚蓝存储文件共享。
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-共享来获取它的共享名。
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.有什么想法吗?
发布于 2021-06-02 15:55:52
您需要引用导出的资源属性对象中的特定值。错误消息声明:
azurerm_storage_share.jms-sftp共享是具有3个属性的对象。
指示您需要引用对象中的特定元素。这三个属性由您使用的one、two和three字符串表示,这些字符串用作在问题中迭代的键。然后访问特定元素,如:
share_name = azurerm_storage_share.jms-sftp-share["one"].name它从导出的资源属性访问azurerm_storage_share.jms-sftp-users-share对象的azurerm_storage_share.jms-sftp-users-share元素。
https://stackoverflow.com/questions/67808307
复制相似问题