Add a nested block to a Terraform resource

Proprietary

Add a nested block (e.g. parameter { ... }) to a Terraform resource if no matching instance exists. When keyMatchers is provided, the recipe deduplicates by attribute keys so it works correctly with repeatable blocks like aws_db_parameter_group.parameter.

org.openrewrite.terraform.AddResourceNestedBlock

Required

A Terraform resource type, without the quotes.

Raw multiline HCL of the nested block to insert, including the block type header and any labels. The block type (and labels) used for sibling lookup are derived from this value.

Optional

A regular expression matched against the resource's local name (the second label). If omitted, all resources of resourceType are considered.

A list of attr=valueRegex entries. The resource is considered a match only if every entry matches an attribute on the resource (AND semantics). Useful to narrow scoping by family, engine, etc. Separate values with commas.

A list of attr=valueRegex entries identifying an existing nested block instance (e.g. name=local_infile for aws_db_parameter_group.parameter). If a sibling block of the same type matches every key, the nested block is considered already present and not inserted. Without keyMatchers, the recipe falls back to skipping insertion when any sibling block of the same type exists (suitable for single-instance blocks like lifecycle / timeouts). Separate values with commas.

Where to place the new block within the resource body: first or last. Defaults to last.

mod run . --recipe=org.openrewrite.terraform.AddResourceNestedBlock \ -P resourceType=aws_db_parameter_group \ -P block='parameter { name = "local_infile" value = "0" }'

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.