Skip to content

Add highlighting for Plan output #68

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions Terraform Plan.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
# https://github.com/hashicorp/terraform/blob/337bf8e11b75dff87509455cabee60b023dd586e/internal/command/jsonformat/plan.go#L201
file_extensions:
- tfplan
- tf.plan
scope: source.diff.terraform

contexts:

main:
- include: comments
- include: diffs
- include: summary

comments:
- match: '#'
scope: punctuation.definition.comment.terraform
push:
- meta_scope: comment.line.number-sign.terraform
- include: pop-eol

diffs:
- match: ^\+/-
scope: punctuation.definition.changed.diff
push: line-created-then-destroyed
- match: ^-/\+
scope: punctuation.definition.changed.diff
push: line-destroyed-then-created
- match: ^!
scope: punctuation.definition.changed.diff
push: line-changed
- match: ^\+
scope: punctuation.definition.inserted.diff
push: line-inserted
- match: ^-
scope: punctuation.definition.deleted.diff
push: line-deleted

annotations:
- match: ->
scope: keyword.operator.assignment.terraform
- match: \(known after apply\)$
scope: comment.block.terraform
- match: \bnull$
scope: constant.language.null.terraform

line-deleted:
- meta_scope: markup.deleted.diff
- include: pop-eol
- include: annotations

line-inserted:
- meta_scope: markup.inserted.diff
- include: pop-eol
- include: annotations

line-changed:
- meta_scope: markup.changed.updated-in-place.diff
- include: pop-eol
- include: annotations

line-created-then-destroyed:
- meta_scope: markup.changed.created-then-destroyed.diff
- include: pop-eol
- include: annotations

line-destroyed-then-created:
- meta_scope: markup.changed.destroyed-then-created.diff
- include: pop-eol
- include: annotations

line-ignored:
- meta_scope: comment.line.diff
- include: pop-eol
- include: annotations

summary:
- match: ^(?=Plan:[ ]\d)
push:
- meta_scope: meta.block.summary.terraform
- include: pop-eol
- match: ','
scope: punctuation.separator.sequence.terraform
- match: \.
scope: punctuation.terminator.terraform
- match: (\d+) to add
scope: markup.inserted.terraform
captures:
1: meta.number.integer.decimal.terraform constant.numeric.value.terraform
- match: (\d+) to change
scope: markup.changed.terraform
captures:
1: meta.number.integer.decimal.terraform constant.numeric.value.terraform
- match: (\d+) to destroy
scope: markup.deleted.terraform
captures:
1: meta.number.integer.decimal.terraform constant.numeric.value.terraform

pop-eol:
- match: \n|$
pop: 1
104 changes: 104 additions & 0 deletions syntax_test_terraform_plan.tfplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# SYNTAX TEST "Terraform Plan.sublime-syntax"

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:

+ create
! update-in-place
- destroy
-/+ destroy and then create replacement

Terraform will perform the following actions:

# aws_route53_record_cname_autodiscover_example_com must be replaced
-/+ resource "aws_route53_record" "cname_autodiscover_example_com" {
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.changed.destroyed-then-created.diff
#^^ punctuation.definition.changed.diff
+ allow_overwrite = (known after apply)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.inserted.diff
# ^^^^^^^^^^^^^^^^^^^ comment.block.terraform
! fqdn = "autodiscover.example.com" -> (known after apply)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.changed.updated-in-place.diff
# ^^ keyword.operator.assignment.terraform
# ^^^^^^^^^^^^^^^^^^^ comment.block.terraform
! id = "ABCDEABCDEABCDEA_autodiscover_CNAME" -> (known after apply)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.changed.updated-in-place.diff
# ^^ keyword.operator.assignment.terraform
# ^^^^^^^^^^^^^^^^^^^ comment.block.terraform
! name = "autodiscover.example.com" -> (known after apply)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.changed.updated-in-place.diff
# ^^ keyword.operator.assignment.terraform
# ^^^^^^^^^^^^^^^^^^^ comment.block.terraform
# (4 unchanged attributes hidden)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - markup
}
# ^^^^ - markup

# aws_route53_record_cname_lyncdiscover_example_com will be destroyed
- resource "aws_route53_record" "cname_lyncdiscover_example_com_old" {
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.deleted.diff
- fqdn = "lyncdiscover.example.com" -> null
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.deleted.diff
# ^^ keyword.operator.assignment.terraform
# ^^^^ constant.language.null.terraform
- id = "ABCDEABCDEABCDEA_lyncdiscover_CNAME" -> null
- name = "lyncdiscover" -> null
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.deleted.diff
# ^^ keyword.operator.assignment.terraform
# ^^^^ constant.language.null.terraform
- records = [
- "webdir.online.lync.com.",
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.deleted.diff
] -> null
- ttl = 7200 -> null
- type = "CNAME" -> null
- zone_id = "ABCDEABCDEABCDEA" -> null
}

# aws_route53_record_cname_lyncdiscover_example_com will be created
+ resource "aws_route53_record" "cname_lyncdiscover_example_com_new" {
+ fqdn = (known after apply)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.inserted.diff
# ^^^^^^^^^^^^^^^^^^^ comment.block.terraform
+ id = (known after apply)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.inserted.diff
# ^^^^^^^^^^^^^^^^^^^ comment.block.terraform
+ name = (known after apply)
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.inserted.diff
# ^^^^^^^^^^^^^^^^^^^ comment.block.terraform
+ records = [
+ "webdir.online.lync.com.",
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.inserted.diff
]
+ ttl = 7200
+ type = "CNAME"
+ zone_id = "ABCDEABCDEABCDEA"
}

# aws_route53_record_zone_example_com will be updated in-place
! resource "aws_route53_record" "cname_autodiscover_example_com" {
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.changed.updated-in-place.diff
! comment = "Records for the example.com domain" -> "Records for the example.com domains"
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.changed.updated-in-place.diff
# ^^ keyword.operator.assignment.terraform
id = "ABCDEABCDEABCDEA"
name = "example.com"
tags = {
"Provisioner" = "Terraform"
"System" = "example"
"Workspace" = "production"
}
# (3 unchanged attributes hidden)
}

Plan: 2 to add, 1 to change, 2 to destroy.
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.summary.terraform
# ^^^^^^^^ markup.inserted.terraform
# ^ meta.number.integer.decimal.terraform constant.numeric.value.terraform
# ^ punctuation.separator.sequence.terraform
# ^^^^^^^^^^^ markup.changed.terraform
# ^ meta.number.integer.decimal.terraform constant.numeric.value.terraform
# ^ punctuation.separator.sequence.terraform
# ^^^^^^^^^^^^ markup.deleted.terraform
# ^ meta.number.integer.decimal.terraform constant.numeric.value.terraform
# ^ punctuation.terminator.terraform