Skip to content

Commit

Permalink
Support special escape sequences in Terraform (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
tancnle authored Sep 18, 2024
1 parent 98febba commit 67f3244
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/rouge/lexers/terraform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def self.builtins

state :strings do
rule %r/\\./, Str::Escape
rule %r/(\$[\$]+|%[%]+)(\{)/, Str
rule %r/\$\{/ do
token Keyword
token Punctuation
push :interpolation
end
end
Expand All @@ -66,7 +67,7 @@ def self.builtins

state :interpolation do
rule %r/\}/ do
token Keyword
token Punctuation
pop!
end

Expand Down
15 changes: 15 additions & 0 deletions spec/visual/samples/terraform
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,18 @@ resource "aws_subnet" "main" {
resource "aws_cloudfront_distribution" "s3_distribution" {
aliases = ["www.${replace(var.domain_name, "/\\.$/", "")}"]
}

# Directives in string templates
locals {
policy = <<EOT
%{ for ip in aws_instance.example[*].private_ip }
server ${ip}
%{ endfor }
EOT
}

# Special escape sequences that do not use backslashes
locals {
demo_dollars_1 = "$${local.demo}"
demo_dollars_2 = "%%{for i in items}"
}

0 comments on commit 67f3244

Please sign in to comment.