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

terraform fmt add spaces after % #22356

Closed
d-helios opened this issue Aug 6, 2019 · 3 comments · Fixed by hashicorp/hcl2#125 or #22428
Closed

terraform fmt add spaces after % #22356

d-helios opened this issue Aug 6, 2019 · 3 comments · Fixed by hashicorp/hcl2#125 or #22428

Comments

@d-helios
Copy link

d-helios commented Aug 6, 2019

terraform fmt command insert space (" ") character in inline template

Terraform Version

Terraform v0.12.6

Terraform Configuration Files

variable "IN" {
  default = [[
    "a",
    "b",
    ],
    ["c",
      "d"
  ]]
}

locals {
  OUT = join(";", [for i in var.IN : "start_${index(var.IN, i)},${join(",", i)},next_%{if index(var.IN, i) + 1 != length(var.IN)}${index(var.IN, i) + 1}%{else}END%{endif}"])

}

output "default" {
  value = local.OUT
}

Expected Behavior

terraform fmt doesn't insert any additional character in inline templates (string)

Actual Behavior

~/t/awef > cp main.tf /tmp/
~/t/awef > terraform fmt
main.tf
~/t/awef > diff /tmp/main.tf main.tf
12c12
<   OUT = join(";", [for i in var.IN : "start_${index(var.IN, i)},${join(",", i)},next_%{if index(var.IN, i) + 1 != length(var.IN)}${index(var.IN, i) + 1}%{else}END%{endif}"])
---
>   OUT = join(";", [for i in var.IN : "start_${index(var.IN, i)},${join(",", i)},next_%{if index(var.IN, i) + 1 != length(var.IN)}${index(var.IN, i) + 1} %{else}END%{endif}"])

Steps to Reproduce

Please list the full steps required to reproduce the issue, for example:

  1. terraform init
  2. cp main.tf /tmp/main.tf
  3. terraform fmt
  4. diff /tmp/main.tf main.tf
    --
@wata727
Copy link
Contributor

wata727 commented Aug 9, 2019

I got a minimal reproduction code like the following:

variable "foo" {
  default = "foo"
}

foo = "%{if true}${var.foo}%{endif}"

And I created the PR to HCL repository hashicorp/hcl2#125
Maybe it fixes the issue.

@apparentlymart
Copy link
Contributor

(Reopening because the change in the HCL repository can't fix this until it's vendored into this repository.)

@ghost
Copy link

ghost commented Sep 13, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants