Atom-beautify: Add .tf (terraform) support to beautify

Created on 6 Nov 2015  路  13Comments  路  Source: Glavin001/atom-beautify

.tf files are defined at https://www.terraform.io/docs/configuration/index.html
We're using terraform to manage AWS infrastructure and would like for Atom to keep the config files formatted beautifully.

add-beautifier add-language published

Most helpful comment

Added a PR yesterday. Crossing fingers that it will apporved. 馃

All 13 comments

TF is close enough to JavaScript that I can make this work, but I have some questions first:

  1. If there a way to identify code as being terraform code merely by looking at the code. I did not see anything like this in the documentation, but if it did exist it would be very helpful.
  2. None of the code statements were terminated with a semicolon. Does this language never use semicolons for statement termination, even implicitly or optionally?
  3. I noticed that blocks comments look identical to JS block comments, but the line comments start with # instead of and //. edit: I just noticed that TF also uses // for line comments

The safest course of action is to use a JavaScript parser for this, but only parse for TF code when passed an option explicitly declaring TF conventions. I just have to put up a prototype for you to play around with so that we can ensure that million things the JavaScript library is doing isn't consequential to TF.

Code samples:

lifecycle {
    [create_before_destroy = true|false]
    [prevent_destroy = true|false]
    [ignore_changes = [ATTRIBUTE NAME, ...]]
}
resource "digitalocean_droplet" "web" {
    name = "tf-web"
    size = "512mb"
    image = "centos-5-8-x32"
    region = "sfo1"
}
resource "dnsimple_record" "hello" {
    domain = "example.com"
    name = "test"
    value = "${digitalocean_droplet.web.ipv4_address}"
    type = "A"
}

resource "aws_elb" "frontend" {
    name = "frontend-load-balancer"
    listener {
        instance_port = 8000
        instance_protocol = "http"
        lb_port = 80
        lb_protocol = "http"
    }
    instances = ["${aws_instance.app.*.id}"]
}
resource "aws_instance" "app" {
    count = 5
    ami = "ami-043a5034"
    instance_type = "m1.small"
}

variable "ami" {
    description = "the AMI to use"
}

# is equal to:

variable = [{
    "ami": {
        "description": "the AMI to use",
    }
}]

+1

+1, does this have any momentum? Is there a branch somewhere?

@Knetic I proposed some questions in a comment above. I need some details answered before I can write the needed support.

Ah, missed those above. Quick note; Terraform uses the "Hashicorp Configuration Language" (hcl), which is shared across a few of their tools. It's got a repo here which seems to spec out most of the syntax.

From that page, I'm fair sure that the language never uses semicolons. As far as detecting that a file is HCL, I'm not sure how the beautifier works today, but when trying to beautify some HCL this morning it seemed to know that it was an HCL file:

Atom Beautify could not determine a supported beautifier to handle this file with grammar "HashiCorp Configuration Language" and extension "tf"

Not sure if that's because i have an HCL language syntax highlighter installed or not. But, if there's no support yet, the way that objects are defined seems like a safe way to tell. <type> "<template>" "<name>" {, all on one line, seems to be constant. But again, I haven't actually sat down to see how atom-beautify goes about that sort of thing.

Language detection in this tool uses this priority:

  1. Grammar setting. This can be set manually and it governs things like code colors and syntax helpers
  2. File extension

I will spend some time looking at HCL.

+1 on the utility of adding HCL language support. It would be amazing,

+1. terraform fmt command is added in v0.6.15.

Looks like all we need is someone to submit a Pull Request adding terraform-fmt beautifier to Atom-Beautify! Let me know if you have any questions.

Added a PR yesterday. Crossing fingers that it will apporved. 馃

I think every issue in the PR was fixed, which requires just an approval.

Published to v0.30.6

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CorentinAndre picture CorentinAndre  路  4Comments

opikhidayat picture opikhidayat  路  4Comments

jcollum picture jcollum  路  4Comments

physcocode picture physcocode  路  3Comments

jasonivers picture jasonivers  路  4Comments