Vscode-terraform: `tags = {` breaks syntax highlighting

Created on 21 Aug 2020  ·  17Comments  ·  Source: hashicorp/vscode-terraform

Not sure if this belongs here or at hashicorp/terraform-ls, but the following block appears to break any subsequent stanzas:

resource "aws_instance" "test" {
  tags = {
    A = "thisisfine"
    B = "this is not fine"
    C = "neither.is.this"
  }
}

resource "aws_instance" "test2" {
    tags = {}
}

Expected result:

Proper syntax highlighting with "this is not fine" and "niether.is.this" being highlighted as strings and the next block being highlighted normally.

Actual Result:

example tf — phishtank-infra 2020-08-20 17-01-03

Removing only B = or C = lines still gives a broken block, each of those lines appears to break the parser. Removing both lines and never having anything but [a-z0-9] in the tag value appears to be the only "fix".

bug syntax

Most helpful comment

Smells like a regression from #462 (meant to fix #442 which is distressingly similar to this issue)

Line 452 in terraform.tmGrammar.json to be precise. If one would revert this line back to 2.1.1 everything works fine!

All 17 comments

Adding some examples i've run into:

resource "example" "test" {
  test = [{
    key = "valu-e"
  }]
}

resource "example" "test" {
  test = [{
    key = "value"
  }]
}

Screen Shot 2020-08-20 at 6 38 13 PM

resource "example" "test" {
  test = [{
    domain = "example.com"
  }]
}

resource "example" "test" {
  test = [{
    key = "value"
  }]
  key = "value"
}

Screen Shot 2020-08-20 at 6 40 08 PM

What seems to break the highlighting is xxx = {
I have the same issue with for example:
config = {
path = ""
}

If I write
config {
}
it works.

tags {
}
works as well. But of course is not correct.

I have the same issue on my end

Screenshot 2020-08-21 at 16 14 11

Just reverted to 2.1.1 because of this issue.
This is what I get:
bad-syntax

We are also experiencing this issue
image

Some issue here when using vars:
image

Same issue is observed on our end but using packer HCL2 where the syntax layout is broken due to the tag block.

example:

  tags = {
    Environment = "ECS Cluster"
    Team = "Platform"
    Approved = "no"
    Base_AMI_Name = "{{ .SourceAMIName }}"
    Base_AMI_ID = "{{ .SourceAMITags.TagName }}"
  }

Reverting back to version 2.1.1 fixes the issue and the layout is restored.

Thanks,

Smells like a regression from #462 (meant to fix #442 which is distressingly similar to this issue)

Also encountered this issue in 2.2.0 running in WSL; fixed by reverting to 2.1.1

Yes, I had the same problem. I just had to roll back to 2.1.1 to resolve this.

The problem can be drilled down to the equal sign in front of the curly bracket:
Left "azurerm ={", Right only "azurerm {"

Smells like a regression from #462 (meant to fix #442 which is distressingly similar to this issue)

Line 452 in terraform.tmGrammar.json to be precise. If one would revert this line back to 2.1.1 everything works fine!

Ugh. v2.2.0 really wasn't well road tested.

As per above I've had to rollback to v2.1.1 as the latest release is completely unusable.

data "terraform_remote_state" "a_terraform_remote_state" {
  backend = "remote"

  config = {
    organization = "org_name"

    workspaces = {
      name = "how-sweet-are-workspace"
    }
  }
}

is but one example of things that broke syntax highlighting.

@jufemaiz thanks for the tip, for anyone else that needs to downgrade the v2.1.1 package is available via

curl -o /path/to/vsix/hashicorp.terraform.2.1.1.vsix https://hashicorp.gallery.vsassets.io/_apis/public/gallery/publisher/hashicorp/extension/terraform/2.1.1/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage

Then just uninstall the v2.2.0 version, restart, install the new package, restart VSCode again and works a charm.

@ryderdain There is an easier method:
image

Just chose the version you wanna have.

We are currently working on a fix for this, but for now the best option is to downgrade. We hope to have a hotfix out as soon as we resolve the issue.

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 context necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

QuinnStevens picture QuinnStevens  ·  6Comments

bnm22 picture bnm22  ·  6Comments

okgolove picture okgolove  ·  4Comments

chrisgallivan picture chrisgallivan  ·  4Comments

brodster2 picture brodster2  ·  5Comments