首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Terraform容器实例动态卷- share_name循环在azurerm_storage_share上

Terraform容器实例动态卷- share_name循环在azurerm_storage_share上
EN

Stack Overflow用户
提问于 2021-06-02 15:39:45
回答 1查看 386关注 0票数 2

我有下面的terraform代码,创建蔚蓝存储文件共享。

代码语言:javascript
复制
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-共享来获取它的共享名。

代码语言:javascript
复制
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
  ]
}

我被以下错误困住了:

代码语言:javascript
复制
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.

我相信我明白它告诉我的,但我不知道如何设置

代码语言:javascript
复制
share_name           = azurerm_storage_share.jms-sftp-share[volume.value.name]

若要正确引用关联的共享,请执行以下操作。

如果我将share_name更改为

代码语言:javascript
复制
share_name           = azurerm_storage_share.jms-sftp-share[volume.value.name.name]

我得到的输出表明我以前的表示法是正确的,但我只是不知道该去哪里。

代码语言:javascript
复制
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.

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-02 15:55:52

您需要引用导出的资源属性对象中的特定值。错误消息声明:

azurerm_storage_share.jms-sftp共享是具有3个属性的对象。

指示您需要引用对象中的特定元素。这三个属性由您使用的onetwothree字符串表示,这些字符串用作在问题中迭代的键。然后访问特定元素,如:

代码语言:javascript
复制
share_name = azurerm_storage_share.jms-sftp-share["one"].name

它从导出的资源属性访问azurerm_storage_share.jms-sftp-users-share对象的azurerm_storage_share.jms-sftp-users-share元素。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67808307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档