Terraform 无法创建 Azure 存储容器

问题描述 投票:0回答:1

我正在尝试使用 Terraform 在 Azure 中创建许多资源。在我创建备份存储容器之前,它似乎一直有效。

这是我的 Terraform 代码:

资源组

resource "azurerm_resource_group" "resource-group" {
  name     = "${var.resource_prefix}-${var.environment}-rg-${var.project_name_web}"
  location = var.location

  tags = {
    environment = var.environment
  }
}

存储账户

resource "azurerm_storage_account" "storage-account" {
  name                     = "${var.resource_prefix}${var.environment}storage${var.project_name_web}"
  resource_group_name      = azurerm_resource_group.resource-group.name
  location                 = var.location
  account_tier             = var.storage_account_tier
  account_replication_type = "LRS"
  account_kind             = var.storage_account_kind
  access_tier              = var.storage_access_tier

  tags = {
    environment = var.environment
  }
}

储存容器

resource "azurerm_storage_container" "storage-account-container-media" {
  name                  = var.storage_container_media_name
  storage_account_name  = azurerm_storage_account.storage-account.name
  container_access_type = var.storage_container_media_access_type
}

金库

resource "azurerm_recovery_services_vault" "vault" {
  name                = "${var.resource_prefix}-${var.environment}-vault-${var.project_name_web}"
  location            = var.location
  resource_group_name = azurerm_resource_group.resource-group.name
  sku                 = "Standard"

  tags = {
    environment = var.environment
  }
}

保险柜容器

resource "azurerm_backup_container_storage_account" "vault-container" {
  resource_group_name = azurerm_resource_group.resource-group.name
  recovery_vault_name = azurerm_recovery_services_vault.vault.name
  storage_account_id  = azurerm_storage_account.storage-account.id
}

最后一个似乎失败并出现以下错误:

Error: Recovery Service Protection Container operation status failed with status "Failed" (Vault "group-dev-vault-web" Resource Group "group-dev-rg-web" Operation ID "09239f11-eab5-407d-afeb-796d64b6a46f"): Item not found
with azurerm_backup_container_storage_account.vault-container
on infra-staging-web.tf line 97, in resource "azurerm_backup_container_storage_account" "vault-container":
resource "azurerm_backup_container_storage_account" "vault-container" {

这似乎表明缺少某些内容,但我已检查 Azure 中是否存在资源组、保管库和存储帐户。我还检查了此块中使用的标识符,据我所知,它们看起来是正确的。

我做错了什么?

azure terraform azure-blob-storage azure-resource-group
1个回答
0
投票

使用 terraform 创建 Azure 存储容器

根据错误描述,提到“找不到项目”Azure 恢复服务保管库无法找到存储帐户容器。

这可能会延迟您实际使用资源之前的可用性。在本例中,

azurerm_backup_container_storage_account
资源在 Azure 恢复服务中完全注册之前尝试引用存储帐户。

您可以使用 depends_on,其中 terraform 确保仅在资源完全创建并准备使用之后才使用目标资源。

配置:

resource "azurerm_storage_container" "storage-account-container-media" {
  name                  = var.storage_container_media_name
  storage_account_name  = azurerm_storage_account.storage-account.name
  container_access_type = var.storage_container_media_access_type
}

resource "azurerm_recovery_services_vault" "vault" {
  name                = "${var.resource_prefix}-${var.environment}-vault-${var.project_name_web}"
  location            = var.location
  resource_group_name = azurerm_resource_group.resource-group.name
  sku                 = "Standard"
}


resource "azurerm_backup_container_storage_account" "vault-container" {
  resource_group_name = azurerm_resource_group.resource-group.name
  recovery_vault_name = azurerm_recovery_services_vault.vault.name
  storage_account_id  = azurerm_storage_account.storage-account.id
  
  depends_on = [azurerm_storage_account.storage-account]
}

部署:

enter image description here

enter image description here

参考:

https://learn.microsoft.com/en-us/azure/backup/backup-azure-recovery-services-vault-overview

© www.soinside.com 2019 - 2024. All rights reserved.