python-hcl2
python-hcl2 copied to clipboard
Unexpected token for ~
With latest version 4.3.3:
File "/home/piotrzal/SRC/DEVOPS/modules-manager/docs_venv/lib/python3.8/site-packages/lark/lexer.py", line 598, in next_token
raise UnexpectedCharacters(lex_state.text, line_ctr.char_pos, line_ctr.line, line_ctr.column,
lark.exceptions.UnexpectedCharacters: No terminal matches '~' in the current parser context, at line 65 col 34
%{for role in var.ADMIN_ROLES_ARN~}
^
Expected one of:
* /[a-zA-Z_][a-zA-Z0-9_-]*/
* "=="
* QMARK
* /#.*\n/
* COMMA
* LPAR
* MORETHAN
* "<="
* "[*]"
* LESSTHAN
* RBRACE
* ">="
* RPAR
* STRING_LIT
* PLUS
* LBRACE
* RSQB
* /\/\/.*\n/
* "..."
* "!="
* LSQB
* COLON
* SLASH
* PERCENT
* MINUS
* /\n/
* "||"
* "&&"
* EQUAL
* STAR
* DOT
* "=>"
* ".*"
Previous tokens: Token('__ANON_3', '_ARN')
Example terraform code:
name = <<EOT
%{for role in var.ADMIN_ROLES_ARN~}
- rolearn: ${role}
username: ${join("-", slice(split("/", role), 1, length(split("/", role))))}
groups:
- system:masters
%{endfor}
EOT
The tilde ~ at the end of for might not be necessary unless it is part of a specific syntax or requirement. Typically, for loops in Heredocs do not use it. Ensure proper spacing and alignment for readability and consistency. Ensure that the closing EOT matches the opening <<EOT without any additional spaces or characters. Here's a corrected and properly formatted version of your Heredoc syntax:
name = <<EOT
%{for role in var.ADMIN_ROLES_ARN}
- rolearn: ${role}
username: ${join("-", slice(split("/", role), 1, length(split("/", role))))}
groups:
- system:masters
%{endfor}
EOT