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

Feature/sub block support #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sebasmannem
Copy link

This would allow for get'ing and set'ing attributes in blocks which reside in attribute values.
If a hcl file called test/example.hcl would contain a body like:

module "sg" {
  source        = "git.git@gitsg"
  ingress_rules = {
    https = {
      service = "psql-db"
      network = "seb_test"
    }
  }
}
module "sa" {
  source        = "git.git@gitsa"
  ingress_rules = {
    https = {
      service = "psql-db"
      network = "seb_test"
    }
  }
}

then this changes would allow for:

  • hcledit -f test/example2.hcl attribute get module.sg.ingress_rules=https=network which would return seb_test
  • bin/hcledit -f test/example2.hcl attribute set module.sg.ingress_rules=https=network '"mnm_test"' which would return;
module "sg" {
  source        = "git.git@gitsg"
  ingress_rules = {
    https = {
      service = "psql-db"
      network = "mnm_test"
    }
  }
}
module "sa" {
  source        = "git.git@gitsa"
  ingress_rules = {
    https = {
      service = "psql-db"
      network = "seb_test"
    }
  }
}

@sebasmannem
Copy link
Author

Fixes: #67

@minamijoyo
Copy link
Owner

Hi @sebasmannem, Thank you for working on this!

What you call a subblock is technically an attribute value of the object type. It's already being tracked in #28. Unfortunately, upstream's hclwrite package we depend on currently does not provide the ability to edit this.

To be honest, adding this feature without proper support in the upstream is challenging as there are many complex possibilities to consider, such as nested objects. So I’m afraid I cannot accept this patch as it is.

@sebasmannem
Copy link
Author

sebasmannem commented Mar 3, 2023

To be honest, adding this feature without proper support in the upstream is challenging as there are many complex possibilities to consider, such as nested objects. So I’m afraid I cannot accept this patch as it is.

Yeah I see what you mean.
Is there anything I can do to enable proper support? Just let me know and I will see what I can do...

@minamijoyo
Copy link
Owner

In fact, the hcledit is a CLI layer to provide the hclwrite functionalities in shell scripts; it is not possible to implement advanced features that are not in hclwrite.

A good place to start would be to open an issue in the upstream hashicorp/hcl repository and ask the hcl maintainer how to edit a value of object type using the hclwrite package. As you know, the current functionality is insufficient; then discuss what API extensions to the hclwrite would be acceptable and how to implement them.

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.

2 participants