liveBook · Manning

Meta argument

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A meta argument is a built-in Terraform argument that controls how Terraform processes a block rather than configuring the underlying infrastructure.

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

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains universal behavior, EC2 consequences, placement, and planning-time constraints without enumerating individual meta arguments.
Examples
Uses EC2 instances, changing AMIs, replacement ordering, lifecycle blocks, and aligned Terraform block formatting.
What it assumes
Assumes familiarity with Terraform blocks and provider-specific arguments while distinguishing those fields from universal processing instructions.
What you can do after
Operate/configure Terraform blocks to ignore selected changes, control replacement order, and follow standard meta-argument placement.
How it connects
Connects resource blocks, data sources, modules, providers, plans, dependencies, and infrastructure replacement behavior.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.