Terraform unable to create Azure Storage Account Management Policy

The other day I was trying to set up Azure storage account lifecycle management policy via Terraform. Azure storage account lifecycle management policies allow you to transition your data to the appropriate access tiers or expire at the end of the data’s lifecycle. Unfortunately on attempt to apply Terraform template I got an error:

Error: expanding Storage Account Management Policy: (Management Policy Name "management-policy-name" / Storage Account Name "storage-account-name" / Resource Group "resource-group-name"): expanding the 0th rule: can't specify 'tier_to_cool_after_days_since_modification_greater_than' and 'tier_to_cool_after_days_since_last_access_time_greater_than' at the same time

The error was a bit confusing as it complains about tier_to_cool_after_days_since_modification_greater_than and tier_to_cool_after_days_since_last_access_time_greater_than being specified at the same time, whereas Terraform definition contained only one of those settings (tier_to_cool_after_days_since_modification_greater_than).

Basically this error occurred due to the fact that in the Terraform Azure RM provider this functionality was not fully implemented for versions prior to 3.0.0, earlier versions had only partial implementation (before that provider schema changes were in place, but corresponding changes for the expand/flatten logic were missing) which was causing this error (source). So to resolve such error (providing that you don’t try to specify two settings mentioned in error message at the same time in your template) you need to make sure that your Terraform Azure RM provider version is 3.0.0 or newer.

Leave a Reply

Your email address will not be published.