Improve Terraform (.tf) / HCL (.hcl) syntax highlighting (#3392)

* Add Terraform grammar, and change .tf and .hcl files from using Ruby to Terraform sublime syntax

* Expand Terraform sample to demonstrate more language features

* Revert terraform sample change

* Add terraform sample - Dokku AWS deploy

* Updated to latest Terraform

* Update terraform string interpolation

* Update terraform to latest
This commit is contained in:
Alex Louden
2017-02-20 18:09:59 +08:00
committed by Colin Seymour
parent f7fe1fee66
commit b66fcb2529
7 changed files with 169 additions and 2 deletions

3
.gitmodules vendored
View File

@@ -818,3 +818,6 @@
[submodule "vendor/grammars/language-regexp"]
path = vendor/grammars/language-regexp
url = https://github.com/Alhadis/language-regexp
[submodule "vendor/grammars/Terraform.tmLanguage"]
path = vendor/grammars/Terraform.tmLanguage
url = https://github.com/alexlouden/Terraform.tmLanguage

View File

@@ -130,6 +130,8 @@ vendor/grammars/TLA:
- source.tla
vendor/grammars/TXL:
- source.txl
vendor/grammars/Terraform.tmLanguage:
- source.terraform
vendor/grammars/Textmate-Gosu-Bundle:
- source.gosu.2
vendor/grammars/UrWeb-Language-Definition:

View File

@@ -1588,7 +1588,7 @@ HCL:
ace_mode: ruby
codemirror_mode: ruby
codemirror_mime_type: text/x-ruby
tm_scope: source.ruby
tm_scope: source.terraform
language_id: 144
HLSL:
type: programming

135
samples/HCL/main.tf Normal file
View File

@@ -0,0 +1,135 @@
resource "aws_security_group" "elb_sec_group" {
description = "Allow traffic from the internet to ELB port 80"
vpc_id = "${var.vpc_id}"
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["${split(",", var.allowed_cidr_blocks)}"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "dokku_allow_ssh_from_internal" {
description = "Allow git access over ssh from the private subnet"
vpc_id = "${var.vpc_id}"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["${var.private_subnet_cidr}"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "allow_from_elb_to_instance" {
description = "Allow traffic from the ELB to the private instance"
vpc_id = "${var.vpc_id}"
ingress {
security_groups = ["${aws_security_group.elb_sec_group.id}"]
from_port = 80
to_port = 80
protocol = "tcp"
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "dokku" {
ami = "ami-47a23a30"
instance_type = "${var.instance_type}"
associate_public_ip_address = false
key_name = "${var.key_name}"
subnet_id = "${var.private_subnet_id}"
vpc_security_group_ids = [
"${var.bastion_sec_group_id}",
"${aws_security_group.allow_from_elb_to_instance.id}",
"${aws_security_group.dokku_allow_ssh_from_internal.id}"
]
tags {
Name = "${var.name}"
}
connection {
user = "ubuntu"
private_key = "${var.private_key}"
bastion_host = "${var.bastion_host}"
bastion_port = "${var.bastion_port}"
bastion_user = "${var.bastion_user}"
bastion_private_key = "${var.bastion_private_key}"
}
provisioner "file" {
source = "${path.module}/../scripts/install-dokku.sh"
destination = "/home/ubuntu/install-dokku.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /home/ubuntu/install-dokku.sh",
"HOSTNAME=${var.hostname} /home/ubuntu/install-dokku.sh"
]
}
}
resource "aws_elb" "elb_dokku" {
name = "elb-dokku-${var.name}"
subnets = ["${var.public_subnet_id}"]
security_groups = ["${aws_security_group.elb_sec_group.id}"]
listener {
instance_port = 80
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "HTTP:80/"
interval = 30
}
instances = ["${aws_instance.dokku.id}"]
cross_zone_load_balancing = false
idle_timeout = 400
tags {
Name = "elb-dokku-${var.name}"
}
}
resource "aws_route53_record" "dokku-deploy" {
zone_id = "${var.zone_id}"
name = "deploy.${var.hostname}"
type = "A"
ttl = "300"
records = ["${aws_instance.dokku.private_ip}"]
}
resource "aws_route53_record" "dokku-wildcard" {
zone_id = "${var.zone_id}"
name = "*.${var.hostname}"
type = "CNAME"
ttl = "300"
records = ["${aws_elb.elb_dokku.dns_name}"]
}

2
vendor/README.md vendored
View File

@@ -142,7 +142,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **Harbour:** [hernad/atom-language-harbour](https://github.com/hernad/atom-language-harbour)
- **Haskell:** [atom-haskell/language-haskell](https://github.com/atom-haskell/language-haskell)
- **Haxe:** [clemos/haxe-sublime-bundle](https://github.com/clemos/haxe-sublime-bundle)
- **HCL:** [aroben/ruby.tmbundle](https://github.com/aroben/ruby.tmbundle)
- **HCL:** [alexlouden/Terraform.tmLanguage](https://github.com/alexlouden/Terraform.tmLanguage)
- **HTML:** [textmate/html.tmbundle](https://github.com/textmate/html.tmbundle)
- **HTML+Django:** [textmate/python-django.tmbundle](https://github.com/textmate/python-django.tmbundle)
- **HTML+ECR:** [atom-crystal/language-crystal](https://github.com/atom-crystal/language-crystal)

View File

@@ -0,0 +1,26 @@
---
type: grammar
name: Terraform.tmLanguage
license: mit
---
MIT License
Copyright (c) 2016 Alex Louden
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.