Skip to content
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## \[Unreleased\]

### Fixed

- Issue parsing dot-accessed attribute as an object key ([#209](https://github.com/amplify-education/python-hcl2/pull/209))

## \[7.0.0\] - 2025-03-27

### Added
Expand Down
5 changes: 3 additions & 2 deletions hcl2/hcl2.lark
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ PLUS : "+"
LPAR : "("
RPAR : ")"
COMMA : ","
DOT : "."

expr_term : LPAR new_line_or_comment? expression new_line_or_comment? RPAR
| float_lit
Expand Down Expand Up @@ -74,8 +75,8 @@ EQ : /[ \t]*=(?!=|>)/
tuple : "[" (new_line_or_comment* expression new_line_or_comment* ",")* (new_line_or_comment* expression)? new_line_or_comment* "]"
object : "{" new_line_or_comment? (new_line_or_comment* (object_elem | (object_elem COMMA)) new_line_or_comment*)* "}"
object_elem : object_elem_key ( EQ | ":") expression
object_elem_key : float_lit | int_lit | identifier | STRING_LIT

object_elem_key : float_lit | int_lit | identifier | STRING_LIT | object_elem_key_dot_accessor
object_elem_key_dot_accessor : identifier (DOT identifier)+

heredoc_template : /<<(?P<heredoc>[a-zA-Z][a-zA-Z0-9._-]+)\n?(?:.|\n)*?\n\s*(?P=heredoc)\n/
heredoc_template_trim : /<<-(?P<heredoc_trim>[a-zA-Z][a-zA-Z0-9._-]+)\n?(?:.|\n)*?\n\s*(?P=heredoc_trim)\n/
Expand Down
3 changes: 3 additions & 0 deletions hcl2/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def object_elem(self, args: List) -> Dict:
value = self.to_string_dollar(value)
return {key: value}

def object_elem_key_dot_accessor(self, args: List) -> str:
return "".join(args)

def object(self, args: List) -> Dict:
args = self.strip_new_line_tokens(args)
result: Dict[str, Any] = {}
Expand Down
6 changes: 5 additions & 1 deletion test/helpers/terraform-config-json/s3.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
"source": "s3_bucket_name",
"name": "audit",
"account": "${var.account}",
"region": "${var.region}"
"region": "${var.region}",
"providers": {
"aws.ue1": "${aws}",
"aws.uw2.attribute": "${aws.backup}"
}
}
}
]
Expand Down
5 changes: 5 additions & 0 deletions test/helpers/terraform-config/s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ module "bucket_name" {
name = "audit"
account = var.account
region = var.region

providers = {
aws.ue1 = aws
aws.uw2.attribute = aws.backup
}
}