.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.
TF is close enough to JavaScript that I can make this work, but I have some questions first:
# //. edit: I just noticed that TF also uses // for line commentsThe 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:
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
Most helpful comment
Added a PR yesterday. Crossing fingers that it will apporved. 馃