← All recipes
Moderne licensed

Change a single attribute inside a Terraform resource's nested block

Recipe IDorg.openrewrite.terraform.ChangeResourceNestedBlockAttributeArtifactorg.openrewrite.recipe:rewrite-terraform

Change the value of an attribute inside a specific instance of a nested block on a Terraform resource (e.g. set value = "0" on the parameter { name = "local_infile" } block of an aws_db_parameter_group). Use keyMatchers to identify a single instance among repeatable blocks.

Single recipeProprietary

Add to your build

Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.

~/.gradle/gradle.properties

codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN

build.gradle.kts

plugins {
    id("org.openrewrite.rewrite") version("latest.release")
}

rewrite {
    activeRecipe("org.openrewrite.terraform.ChangeResourceNestedBlockAttribute")
}

repositories {
    mavenCentral()
    maven {
        url = uri("https://artifacts.codegenomeproject.org/maven")
        credentials {
            username = providers.gradleProperty("codeGenomeUsername").get()
            password = providers.gradleProperty("codeGenomeToken").get()
        }
    }
}

dependencies {
    rewrite("org.openrewrite.recipe:rewrite-terraform:3.15.0")
}

Then run

./gradlew rewriteRun

This recipe has required options, which a build sets in a rewrite.yml recipe that you activate instead.

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.terraform.ChangeResourceNestedBlockAttribute --recipe-option "resourceType=aws_db_parameter_group" --recipe-option "blockType=parameter" --recipe-option "attributeName=value" --recipe-option "newValue=0"

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-terraform:RELEASE

Options

NameTypeDescription
resourceTyperequiredStringA Terraform resource type, without the quotes.
e.g. aws_db_parameter_group
resourceNamePatternStringA regular expression matched against the resource's local name (the second label). If omitted, all resources of resourceType are considered.
e.g. rds_.*
resourceAttrMatchersListA list of attr=valueRegex entries. The resource is considered a match only if every entry matches an attribute on the resource (AND semantics).
e.g. family=mysql.*|mariadb.*
blockTyperequiredStringThe type of nested block to update (e.g. parameter, tag, setting).
e.g. parameter
keyMatchersListA list of attr=valueRegex entries identifying the specific nested block instance to update. If omitted, every block of the given blockType is updated.
e.g. name=local_infile
attributeNamerequiredStringThe attribute inside the nested block whose value should change.
e.g. value
newValuerequiredStringThe new value to set. For quoted string attributes, provide the value without quotes.
e.g. 0

Data tables

Structured output this recipe can produce.

  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats