Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for getting nested block #22

Merged
merged 1 commit into from
Mar 2, 2021
Merged

Conversation

minamijoyo
Copy link
Owner

@minamijoyo minamijoyo commented Mar 2, 2021

Partial fix for #21

The hcledit block get command now returns not only the top-level block, but also the nested block.

The previous implementation of the block get command didn't support a nested block. However, it's natural to expect returning the nested block as the same as the attribute in the nested block.

$ cat tmp/attr.hcl
resource "foo" "bar" {
  attr1 = "val1"
  nested {
    attr2 = "val2"
  }
}

$ cat tmp/attr.hcl | go run main.go block get resource.foo.bar.nested
nested {
  attr2 = "val2"
}

$ cat tmp/attr.hcl | go run main.go block get resource.foo.bar
resource "foo" "bar" {
  attr1 = "val1"
  nested {
    attr2 = "val2"
  }
}

Partial fix for #21

The previous implementation of the block get command didn't support a
nested block. However, it's natural to expect returning the nested
block as the same as the attribute in the nested block.

I'll reuse the findLongestMatchingBlocks to implement it as a compromise
for now, but it doesn't support the wildcard match. There is a bit
inconsistency here. To fix it, we will need to merge implementations of
findBlocks and findLongestMatchingBlocks.
@minamijoyo minamijoyo merged commit 5fe3af6 into master Mar 2, 2021
@minamijoyo minamijoyo deleted the get-nested-block branch March 2, 2021 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant