CodexBloom - Programming Q&A Platform

Terraform scenarios to create Azure Blob Storage with lifecycle rules due to unexpected errors

👀 Views: 2 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-06
terraform azure blob-storage HCL

I'm upgrading from an older version and I'm trying to set up an Azure Blob Storage account using Terraform, but I'm running into an unexpected scenario when I attempt to configure lifecycle rules... The storage account is being created successfully, but the lifecycle management block keeps throwing errors. Here's my Terraform configuration for the storage account and the lifecycle rules: ```hcl provider "azurerm" { features {} } resource "azurerm_storage_account" "example" { name = "mystorageaccount123" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location account_tier = "Standard" account_replication_type = "LRS" lifecycle { prevent_destroy = true } } resource "azurerm_storage_blob" "example_blob" { name = "myblob.txt" storage_account_name = azurerm_storage_account.example.name container_name = azurerm_storage_container.example.name type = "Block" source = "path/to/my/blob/myblob.txt" } resource "azurerm_storage_container" "example" { name = "mycontainer" storage_account_name = azurerm_storage_account.example.name } resource "azurerm_storage_management_policy" "example_policy" { storage_account_id = azurerm_storage_account.example.id rule { name = "my_lifecycle_rule" filters { blob_types = ["blockBlob"] } actions { base_blob { delete { days_since_modification_greater_than = 30 } } } } } ``` When I apply this configuration, I get the following behavior: ``` behavior: azurerm_storage_management_policy.example_policy: expected rule to be a valid block, got "" ``` I've tried removing the lifecycle block from the storage account configuration, which didn't solve the scenario. I also ensured that the storage account is created before the management policy. I believe I'm following the correct format for defining the storage management policy, but it seems like there's something off with how I'm structuring the resource. Has anyone experienced similar issues or have insights on how to properly configure lifecycle rules for Azure Blob Storage using Terraform? I'm using Terraform version 1.1.6 and the azurerm provider version 2.82.0. I'm working on a application that needs to handle this. Hoping someone can shed some light on this. I'd be grateful for any help.