From b66fcb252908fc489a700793291e216705b55664 Mon Sep 17 00:00:00 2001 From: Alex Louden Date: Mon, 20 Feb 2017 18:09:59 +0800 Subject: [PATCH] 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 --- .gitmodules | 3 + grammars.yml | 2 + lib/linguist/languages.yml | 2 +- samples/HCL/main.tf | 135 ++++++++++++++++++ vendor/README.md | 2 +- vendor/grammars/Terraform.tmLanguage | 1 + .../licenses/grammar/Terraform.tmLanguage.txt | 26 ++++ 7 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 samples/HCL/main.tf create mode 160000 vendor/grammars/Terraform.tmLanguage create mode 100644 vendor/licenses/grammar/Terraform.tmLanguage.txt diff --git a/.gitmodules b/.gitmodules index 14461012..720575db 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 \ No newline at end of file diff --git a/grammars.yml b/grammars.yml index 217eefad..74165002 100755 --- a/grammars.yml +++ b/grammars.yml @@ -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: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index a86c8a31..b61ec121 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -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 diff --git a/samples/HCL/main.tf b/samples/HCL/main.tf new file mode 100644 index 00000000..66db9807 --- /dev/null +++ b/samples/HCL/main.tf @@ -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}"] +} \ No newline at end of file diff --git a/vendor/README.md b/vendor/README.md index 359a9b14..6df56540 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -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) diff --git a/vendor/grammars/Terraform.tmLanguage b/vendor/grammars/Terraform.tmLanguage new file mode 160000 index 00000000..93b11ff8 --- /dev/null +++ b/vendor/grammars/Terraform.tmLanguage @@ -0,0 +1 @@ +Subproject commit 93b11ff8abc164b0f61113bed1300c5d68f0c399 diff --git a/vendor/licenses/grammar/Terraform.tmLanguage.txt b/vendor/licenses/grammar/Terraform.tmLanguage.txt new file mode 100644 index 00000000..ec7baf8b --- /dev/null +++ b/vendor/licenses/grammar/Terraform.tmLanguage.txt @@ -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. \ No newline at end of file