【问题标题】:Terraform Azure Container Groups appear to have no way to mount multiple volumes?Terraform Azure 容器组似乎无法挂载多个卷?
【发布时间】:2021-05-26 00:20:22
【问题描述】:

查看 Azure 容器组的文档时,特别是有关机密的此页面:https://docs.microsoft.com/en-us/azure/container-instances/container-instances-volume-secret 我注意到卷对象是一个包含 1 个或多个卷的数组。

"volumes": [
      {
        "name": "secretvolume1",
        "secret": {
          "mysecret1": "TXkgZmlyc3Qgc2VjcmV0IEZPTwo=",
          "mysecret2": "TXkgc2Vjb25kIHNlY3JldCBCQVIK"
        }
      }
    ]

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

难道不能在 terraform 中制作多个卷吗?尽管在文档中看起来如此,但这在 ARM 中是否也是不可能的?测试表明 Terraform 不支持多卷,尽管我对 ARM 不够熟练,无法验证。

【问题讨论】:

  • 您是否尝试过像使用多个容器块一样添加多个卷块?

标签: azure terraform azure-resource-manager azure-container-instances


【解决方案1】:

当然,可以使用 Terraform 制作多个卷:

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

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")
      }
    }
  }

}

我正在使用最新的提供程序。

PS D:\Terraform> .\terraform.exe -v
Terraform v0.14.7
+ provider registry.terraform.io/hashicorp/azurerm v2.48.0

验证来自容器实例的装载路径--->连接--->Azure 门户上的/bin/sh

【讨论】:

  • 谢谢南希!以我的经验,验证在我尝试时向我抛出了一个错误,说一次只能制作一个卷:2021-02-12T19:34:07.5424698Z 错误:只有empty_dir 卷、git_repo 卷中的一个、secret 卷或存储帐户卷(share_namestorage_account_namestorage_account_key)可以指定我认为我们之间可能存在提供商差异。你能告诉我你的供应商版本吗?也许请包括您的 terraform 配置的其余部分?
  • 我正在使用最新的提供程序。 Terraform v0.14.7 + provider registry.terraform.io/hashicorp/azurerm v2.48.0,请查看我的更新。查看示例用法registry.terraform.io/providers/hashicorp/azurerm/latest/…
  • 非常感谢,我很感激南希
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-22
  • 1970-01-01
  • 2021-06-05
  • 2019-12-19
  • 2018-04-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多