openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.13k stars 320 forks source link

HCL base recipes and utilities #2043

Open jkschneider opened 2 years ago

jkschneider commented 2 years ago

cc / @nmck257 JsonPathMatcher will be a more fully featured form of getBlockPath().

jkschneider commented 2 years ago

JsonPathMatcher introduced with df8d8dece8fe40253bc80c75821a836f082321d5

rmadamanchi commented 2 years ago

@jkschneider thoughts on JsonPathMatcher support for querying on labels? (didn't think it does currently)

I'm thinking something like $.provider[aws] to match the first block below - or $.resource[foo.bar] to match third block below.

provider "aws" {

}

provider "gcp" {

}

resource "foo" "bar" {

}

Edit - proper jsonpath syntax is probably something like $.provider[?(@.labels = 'aws'] or $.resource[?(@.labels = 'foo.bar'] - labels being a special property to query on