A meta argument controls how Terraform processes a data or resource block rather than configuring the underlying infrastructure. Built into HCL, it gives Terraform instructions for planning, ordering creation, ignoring changes, or forcing replacement. section 2.7
Use meta arguments to shape infrastructure operations:
- Ignore selected value changes, such as AMI updates that would otherwise recreate an existing instance. section 2.7
- Create a replacement before destroying the old resource to reduce service downtime. section 2.7
- Provide universal block-level behavior independent of the underlying provider. section 2.7
EC2 image updates
An EC2 instance can use the latest AMI for new launches while ignoring later AMI changes on an existing instance, preventing automatic recreation. A replacement-before-destruction rule can then reduce downtime when replacement is required. section 2.7
Listing 2.16 terraform block style
resource "resource_type" "unique_resource_name" {
provider = aws.dns #1
string_parameter = "value" #2
integer_parameter = 134
boolean_parameter = true
object_arguments = { #3
key1 : "value" #4
key2 = "value" #5
key3 = "value"
}
subblock { #6
subargument = "value"
subargument2 = "another_value"
}
lifecycle { #7
ignore_changes = [object_arguments]
}
}
Place meta arguments at the top of a block, keep block-specific arguments and subblocks afterward, and put meta-argument subblocks last; terraform fmt applies formatting. section 2.2.6
