首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Terraform Azure容器组似乎无法装载多个卷?

Terraform Azure容器组似乎无法装载多个卷?
EN

Stack Overflow用户
提问于 2021-02-24 01:24:36
回答 1查看 726关注 0票数 3

当查看Azure容器组的文档时,特别是这个关于secrets:https://docs.microsoft.com/en-us/azure/container-instances/container-instances-volume-secret的页面,我注意到volumes对象是一个似乎是1个或更多个卷的数组。

代码语言:javascript
复制
"volumes": [
      {
        "name": "secretvolume1",
        "secret": {
          "mysecret1": "TXkgZmlyc3Qgc2VjcmV0IEZPTwo=",
          "mysecret2": "TXkgc2Vjb25kIHNlY3JldCBCQVIK"
        }
      }
    ]

在这里查看Terraform文档时:https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_group,我注意到体积对象是单数的。

不能在terraform中制作多个卷吗?这在ARM中也是不可能的,尽管在文档中看起来是这样的?测试表明Terrraform不支持多个卷,尽管我对ARM还不够熟练,无法进行验证。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-24 17:57:29

当然,可以使用Terraform创建多个卷:

在我的工作示例中,它创建了两个卷,一个用于存储文件共享,另一个是秘密卷。

代码语言:javascript
复制
resource "azurerm_resource_group" "example" {
  name     = "${var.prefix}-resources"
  location = var.location
}

resource "azurerm_storage_account" "example" {
  name                     = "${var.prefix}stor"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_storage_share" "example" {
  name                 = "aci-test-share"
  storage_account_name = azurerm_storage_account.example.name
  quota                = 50
}

resource "azurerm_container_group" "example" {
  name                = "${var.prefix}-continst"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  ip_address_type     = "public"
  dns_name_label      = "${var.prefix}-continst"
  os_type             = "Linux"

  container {
    name   = "hello-world"
    image  = "microsoft/aci-helloworld:latest"
    cpu    = "0.5"
    memory = "1.5"

    ports {
      port     = 443
      protocol = "TCP"
    }

    volume {
      name       = "logs"
      mount_path = "/aci/logs"
      read_only  = false
      share_name = azurerm_storage_share.example.name

      storage_account_name = azurerm_storage_account.example.name
      storage_account_key  = azurerm_storage_account.example.primary_access_key

    }

    volume {
      name       = "secretvolume1"
      mount_path = "/mnt/secrets"
      read_only  = false

      secret = {
        "mysecret1"=base64encode("My first secret FOO")
        "mysecret2"=base64encode("My second secret BAR")
      }
    }
  }

}

我使用的是最新的供应商。

代码语言:javascript
复制
PS D:\Terraform> .\terraform.exe -v
Terraform v0.14.7
+ provider registry.terraform.io/hashicorp/azurerm v2.48.0

在Azure门户上验证容器实例的挂载路径->connect->/bin/sh

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

https://stackoverflow.com/questions/66338042

复制
相关文章

相似问题

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