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 formatting comments block comments using # #11209

Closed
nateww opened this issue Jan 14, 2017 · 7 comments · Fixed by #11396
Closed

terraform fmt formatting comments block comments using # #11209

nateww opened this issue Jan 14, 2017 · 7 comments · Fixed by #11396
Assignees

Comments

@nateww
Copy link

nateww commented Jan 14, 2017

Using terraform 0.8.4, terraform formats comment block using # signs by placing newlines between every line. IMO, it shoudn't even be adding a newline after a comment starting with a #, let alone a newline between every line.

Original (pre-fmt)

variable "environment" {
  default = {}

  # default {
  #    "region" = "us-west-2"
  #    "sg"     = "playground"
  #    "env"    = "prod"
  #  }
}

Post-fmt

variable "environment" {
  default = {}

  # default {

  #    "region" = "us-west-2"

  #    "sg"     = "playground"

  #    "env"    = "prod"

  #  }
}

The format of adding a newline after a comment block seem arbitrary.

@mmontreuil
Copy link

I am seeing the same thing with terraform 0.8.2. Seems to be happen inside variable blocks.

Original:

# Above Foo 1
# Above Foo 2
variable "foo" {
  # In Foo 1
  # In Foo 2

  default = ""
}

Post-fmt:

# Above Foo comment 1
# Above Foo comment 2
variable "foo" {
  # In Foo Line 1

  # In Foo Line 2

  default = ""
}

@rkulagowski
Copy link
Contributor

terraform v0.8.2, Ubuntu 14.04

I'm seeing a variation; it's eating the first comment.

Pre-fmt:

  vpc_security_group_ids = ["sg-aaaaaaaa", # SG_USE1_DEV_REM_ACC_V01
    "sg-bbbbbbbb",                             # SG_USE1_DEV_REL_MGMT_V01
    "sg-cccccccc",                             # SG_USE1_DEV_INF_MGMT_V01
    "${aws_security_group.docs-us-east-1.id}",
  ]

Post-fmt:

  vpc_security_group_ids = ["sg-aaaaaaaa",
    "sg-bbbbbbbb",                             # SG_USE1_DEV_REL_MGMT_V01
    "sg-cccccccc",                             # SG_USE1_DEV_INF_MGMT_V01
    "${aws_security_group.docs-us-east-1.id}",
  ]

@rkulagowski
Copy link
Contributor

Interesting; it doesn't eat the comment if the first sg-id is on its own line instead of against the opening left bracket.

Pre-fmt:

  vpc_security_group_ids = [
"sg-aaaaaaaa",                             # SG_USE1_DEV_REM_ACC_V01
    "sg-bbbbbbbb",                             # SG_USE1_DEV_REL_MGMT_V01
    "sg-cccccccc",                             # SG_USE1_DEV_INF_MGMT_V01
    "${aws_security_group.docs-us-east-1.id}",
  ]

Post-fmt:

  vpc_security_group_ids = [
    "sg-aaaaaaaa",                             # SG_USE1_DEV_REM_ACC_V01
    "sg-bbbbbbbb",                             # SG_USE1_DEV_REL_MGMT_V01
    "sg-cccccccc",                             # SG_USE1_DEV_INF_MGMT_V01
    "${aws_security_group.docs-us-east-1.id}",
  ]

mitchellh added a commit to hashicorp/hcl that referenced this issue Jan 25, 2017
hashicorp/terraform#11209

See the TF issue above for an example, and test cases for a fix. This
didn't affect any other formatting tests.
@mitchellh
Copy link
Contributor

Fixed! Will be in 0.8.5. @rkulagowski I'm taking a look at that, too.

@nateww
Copy link
Author

nateww commented Jan 25, 2017

Thanks, looking forward to 0.8.5

@dead10ck
Copy link

dead10ck commented Jan 25, 2019

There still appear to be issues with this. v0.11.11 turns

    cidr_blocks = [
      "${var.cidr_blocks}",
      "x.x.x.x/32" # GitHub
    ]

into

    cidr_blocks = [
      "${var.cidr_blocks}",
      "x.x.x.x/32",
    ] # GitHub

and

  # No credentials explicitly set here because they come from either the
  # environment or the global credentials file.

into

  # No credentials explicitly set here because they come from either the  # environment or the global credentials file.

@ghost
Copy link

ghost commented Mar 30, 2020

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 Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants