Including dynamic blocks or a for_each
resource with ignore_changes
leads to: A static list expression is required.
As for the solution, make sure whatever list of attributes you are passing to ignore_changes
to be static.
Prerequisites
- Terraform
Solution
Taking the following code block into consideration:
resource "aws_instance" "this" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
dynamic "ebs_block_device" {
for_each = var.ebs_volumes
content {
device_name = ebs_block_device.value.device_name
volume_type = ebs_block_device.value.volume_type
volume_size = ebs_block_device.value.volume_size
}
}
lifecycle {
ignore_changes = [ebs_block_device]
}
}
The fix:
lifecycle {
ignore_changes = [ebs_block_device.*.device_name, ebs_block_device.*.volume_type, ebs_block_device.*.volume_size]
}
Note: The wildcard (*
) in ebs_block_device.*.device_name
and the rest, creates a list of all values of the specified attribute for all instances of the dynamic block.
Conclusion
Related: Resolve: “The block type lifecycle is reserved for use by Terraform in a future version”.
In case nothing works, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.