hcledit icon indicating copy to clipboard operation
hcledit copied to clipboard

Unable to get/set attributes more than 3 levels deep

Open syphernl opened this issue 3 years ago • 2 comments

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?

syphernl avatar Feb 15 '22 07:02 syphernl

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,

I guess it's a common concern for terraform folks and not only for you. Good luck 😇

minamijoyo avatar Feb 15 '22 13:02 minamijoyo

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 👍🏻

syphernl avatar Feb 15 '22 13:02 syphernl

Closed this as duplicate of #28.

minamijoyo avatar Jan 05 '23 02:01 minamijoyo