hcledit
hcledit copied to clipboard
Unable to get/set attributes more than 3 levels deep
Take for example this version.tf:
terraform {
required_version = ">= 1.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0"
}
}
}
I can retrieve the aws provider just fine:
❯ cat versions.tf | hcledit attribute get terraform.required_providers.aws
{
source = "hashicorp/aws"
version = ">= 3.0"
}
But I cannot retrieve the version attribute of it:
❯ cat versions.tf | hcledit attribute get terraform.required_providers.aws.version
Setting this attribute doesn't work either:
❯ cat versions.tf | hcledit attribute set terraform.required_providers.aws.version "< 4.0"
terraform {
required_version = ">= 1.0.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.0"
}
}
}
Am I doing something wrong or can't hcledit go this deep?
Hi @syphernl, Thank you for reporting this.
In the HCL specification, foo {} is a block and foo = {} is an attribute with an object type. Note that = means the attribute syntax. With that in mind, a hypothetical address notation could be terraform.required_providers.aws["version"]
However, the address index reference notation has not been implemented yet due to technical limitations of the hclwrite package in the upstream hcl library we depends on.
By the way, you looks interested in the recent breaking changes in the terraform-provider-aws v4, if your concern is only for Terraform provider constraints,
- Use hashicorp/terraform-config-inspect for get
- Use minamijoyo/tfupdate for set, which is written by me 😉
I guess it's a common concern for terraform folks and not only for you. Good luck 😇
We are indeed currently "affected" by the breaking changes of aws provider v4, so ~30 repo's needed to be pinned to a version prior to that.
I came across your tfupdate tool and it did the trick perfectly 👍🏻
Closed this as duplicate of #28.