Skip to content

Transform back does add interpolation literals to locals and variables inside a map #252

@francogjm

Description

@francogjm

Describe the bug

When transforming HCL code that includes a templatefile with a map inside, if the values of the map are locals or variables, e.g. local.name or var.name, the transform adds the interpolation literals to the values, so, they end up like "${local.name}" or "${var.name}" and that is a deprecated format. This according to: https://github.com/hashicorp/terraform/releases/tag/v0.12.14

Software:

  • OS: macOS
  • Python version 3.10.16
  • python-hcl2 version (e.g. 7.3.1)

Snippet of HCL2 code causing the unexpected behaviour:

module "my-module" {
  source            = "my-source"
  account_id        = local.account_id
  region            = local.region
  service_name      = local.service_name
  policy            = templatefile("./iam_policy.json.tpl", { "name" : local.service_name, "environment" : var.environment, "account_id" : local.account_id, "region" : local.region })
  tags              = local.tags
}

is transformed into:

module "my-module" {
  source            = "my-source"
  account_id        = local.account_id
  region            = local.region
  service_name      = local.service_name
  policy            = templatefile("./iam_policy.json.tpl", { "name" : "${local.service_name}", "environment" : "${var.environment}", "account_id" : "${local.account_id}", "region" : "${local.region}" })
  tags              = local.tags
}

Expected behavior

Expected result is to keep the policy = templatefile(... without the interpolation literals:

policy            = templatefile("./iam_policy.json.tpl", { "name" : local.service_name, "environment" : var.environment, "account_id" : local.account_id, "region" : local.region })

Metadata

Metadata

Labels

bugSomething isn't workingfixed-in-8.0this issue has been fixed in `transformer-overhaul` feature branch, to be released as v8.0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions