Reputation: 1128
I'm attempting to use Terraform to create a number of resources in Azure. It appears to be working until I get to the creation of a backup storage container.
Here's my Terraform code:
Resource Group
resource "azurerm_resource_group" "resource-group" {
name = "${var.resource_prefix}-${var.environment}-rg-${var.project_name_web}"
location = var.location
tags = {
environment = var.environment
}
}
Storage Account
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
}
}
Storage Container
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
}
Vault
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
}
}
Vault Container
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
}
It looks to be failing on the last of these with the following error:
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" {
It seems to indicate that something is missing but I've checked that the resource group, vault, and storage accounts are present in Azure. I've also checked the identifiers used in this block and, as far as I can tell, they look to be correct.
What am I doing wrong?
Upvotes: 0
Views: 222
Reputation: 2401
Create Azure storage container using terraform
As per the error description which mentioned as Item not found Azure Recovery Services Vault is unable to find the storage account container.
This may be delay to availablity of the resource before you actually use. Here in this case azurerm_backup_container_storage_account
resource tries to reference the storage account before it is fully registered in Azure Recovery Services.
You can use depends_on where the terraform make sure the use of the target resouce occurs only after the resource completely created and ready to use.
Configuration:
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]
}
Deployement:
Refer:
https://learn.microsoft.com/en-us/azure/backup/backup-azure-recovery-services-vault-overview
Upvotes: 1