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

Add .tf (terraform) support to beautify #645

Closed
TheLinuxNinja opened this issue Nov 6, 2015 · 13 comments
Closed

Add .tf (terraform) support to beautify #645

TheLinuxNinja opened this issue Nov 6, 2015 · 13 comments

Comments

@TheLinuxNinja
Copy link

.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.

@prettydiff
Copy link
Collaborator

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.

@prettydiff
Copy link
Collaborator

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",
    }
}]

@vkatushenok
Copy link

+1

@Knetic
Copy link

Knetic commented Feb 8, 2016

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

@prettydiff
Copy link
Collaborator

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

@Knetic
Copy link

Knetic commented Feb 8, 2016

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.

@prettydiff
Copy link
Collaborator

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.

@ProbablyRusty
Copy link

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

@itiut
Copy link

itiut commented Sep 22, 2016

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

@Glavin001
Copy link
Owner

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.

@derBroBro derBroBro mentioned this issue Oct 9, 2017
6 tasks
@derBroBro
Copy link
Contributor

Added a PR yesterday. Crossing fingers that it will apporved. 🤞

@derBroBro
Copy link
Contributor

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

@Glavin001 Glavin001 added this to the v0.35.6 milestone Oct 30, 2017
@Glavin001 Glavin001 self-assigned this Oct 30, 2017
@Glavin001
Copy link
Owner

Published to v0.30.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants