gpt4 book ai didi

azure - 如何使用 terraform 将共享卷安装到 Azure 容器应用程序实例上

转载 作者:行者123 更新时间:2023-12-03 01:58:45 25 4
gpt4 key购买 nike

当涉及到容器应用程序时,文档似乎非常缺乏,尤其是 Terraform。到目前为止,我已经成功创建了我的容器应用程序和存储,并且一切正常。但尝试将共享卷安装到容器应用程序上是一件很困难的事情......下面是代码片段

存储和共享创建

resource "azurerm_storage_account" "storage" {
name = "storage1"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_storage_share" "share" {
name = "storage1_share"
quota = "200"
storage_account_name = azurerm_storage_account.storage.name
depends_on = [azurerm_storage_account.storage]
}

有问题的容器应用程序片段...

  template {
container {
name = var.name_prefix
image = "${data.azurerm_container_registry.acr.login_server}/data_svc:latest"
cpu = 0.25
memory = "0.5Gi"

volume_mounts {
name = "${azurerm_storage_account.storage.name}-volume"
path = "/${azurerm_storage_share.share.name}"
}
}

volume {
name = "${azurerm_storage_account.storage.name}-volume"
storage_type = "AzureFile"
storage_name = azurerm_storage_account.storage.name
}
}

当我运行应用程序时,我得到以下内容

│ Container App Name: "data-svc-app"): performing CreateOrUpdate: containerapps.ContainerAppsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error:
│ Code="ManagedEnvironmentStorageNotFound" Message="Storage storage1 not found under managed environment"

我认为要么是我错过了一个步骤,要么是某些值不正确 - 问题是由于缺乏文档,这是一个反复试验的过程。有谁知道正确的配置才能使其在 terraform 中工作?我想我可能需要为容器应用程序环境添加一个配置...不过...文档或示例很少介绍如何操作。

最佳答案

一旦您拥有存储帐户的资源,您应该为容器应用程序创建存储资源

esource "azapi_resource" "storage" {
schema_validation_enabled = false
type = "Microsoft.App/managedEnvironments/storages@2022-10-01"
name = "shared-storage"
parent_id = local.containerapp_environment_id
body = jsonencode({
properties = {
azureFile = {
accountKey = azurerm_storage_account. storage.primary_access_key
accountName = azurerm_storage_account. storage.name
shareName = azurerm_storage_share.share.name
AccessMode = "ReadWrite"
}
}
})
}

然后

  template {
container {
name = var.name_prefix
image = "${data.azurerm_container_registry.acr.login_server}/data_svc:latest"
cpu = 0.25
memory = "0.5Gi"

volume_mounts {
name = azurerm_storage_share.share.name

path = "/${azurerm_storage_share.share.name}"
}
}

volume {
name = azurerm_storage_share.share.name
storage_type = "AzureFile"
storage_name = azapi_resource.storage.name
}
}

如果您不使用 azapi 提供程序,您应该使用 azurerm_container_app_environment_storage

resource "azurerm_container_app_environment_storage" "example" {
name = "mycontainerappstorage"
container_app_environment_id = azurerm_container_app_environment.example.id
account_name = azurerm_storage_account.example.name
share_name = azurerm_storage_share.example.name
access_key = azurerm_storage_account.example.primary_access_key
access_mode = "ReadOnly"
}

关于azure - 如何使用 terraform 将共享卷安装到 Azure 容器应用程序实例上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77213582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com