minamijoyo / tfupdate

Update version constraints in your Terraform configurations
MIT License
556 stars 23 forks source link

Support configuration_aliases argument #40

Closed takumin closed 3 years ago

takumin commented 3 years ago

Starting with Terraform 0.15, configuration_aliases is available.

See also 1: https://www.terraform.io/upgrade-guides/0-15.html#alternative-provider-configurations-within-modules See also 2: https://www.terraform.io/docs/language/modules/develop/providers.html#provider-aliases-within-modules

For example, the following declaration.

terraform {
  required_providers {
    aws = {
      version = "2.65.0"
      source  = "hashicorp/aws"

      configuration_aliases = [
        aws.primary,
        aws.secondary,
      ]
    }
  }
}

Are you planning to support this syntax?

minamijoyo commented 3 years ago

@takumin Thank you for reporting this!

I confirmed that if we have the configuration_aliases key in the required_providers block, the tfupdate fails to parse and silently ignores the block.

I found the root cause of this problem is a dirty hack in the tfupdate implementation due to limitations of the hcl library. We expect a literal expression here: https://github.com/minamijoyo/tfupdate/blob/v0.4.3/tfupdate/hclwrite.go#L48-L71

If my understanding is correct, the configuration_aliases contains provider references, that is, variables in hcl and it requires a EvalContext to parse.

I think it should be fixed, but it may be quite difficult under the current technical constraints. I'm not sure how to fix it for now 🤔

minamijoyo commented 3 years ago

I found the terraform-config-inspect seems to parse the required_providers block without an EvalContext using hcl.ExprMap. It's worth investigating. https://github.com/hashicorp/terraform-config-inspect/pull/59

minamijoyo commented 3 years ago

@takumin Fixed in v0.5.1 🚀