微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决Terraform Azure 容器组似乎无法挂载多个卷?

查看 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 不够精通以进行验证。

解决方法

当然,可以使用 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

enter image description here

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

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?