Skip to content

7.x has issue parsing parenthesis in object keys #211

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

Closed
andrewthetechie opened this issue Apr 4, 2025 · 0 comments · Fixed by #218
Closed

7.x has issue parsing parenthesis in object keys #211

andrewthetechie opened this issue Apr 4, 2025 · 0 comments · Fixed by #218
Assignees
Labels
bug Something isn't working

Comments

@andrewthetechie
Copy link

Describe the bug

Expected one of: 
        * STRING_LIT
        * FOR_EACH
        * NL_OR_COMMENT
        * IF
        * NEGATIVE_DECIMAL
        * FOR
        * DECIMAL
        * IN
        * RBRACE
        * NAME

When parsing this hcl (some content stripped out/anonymized because this is work code)

module "mymodule" {
  source  = "./modules/mymoudle"

  roles = {
    (var.role_name) = {
      inline_policies = {
        (var.policy_name) = local.policy_statements
      }
    },
    (var.second_role_name) = {
      trust_policy = [local.events_trust_policy]
      inline_policies = {
        (local.policy_name_inline) = local.events_policy_statements
      }
    }
  }
  policies = {
    (var.policy_name) = {
      description = "Policy"
      statements  = local.events_policy_statements
    }
  }

}

this works on the 6.x releae

Software:

  • OS: [macOS / Windows / Linux] any
  • Python version (e.g. 3.9.21) - tested on 3.10 to 3.13
  • python-hcl2 version (e.g. 7.0.0) 7.0.0 and 7.0.1

Snippet of HCL2 code causing the unexpected behaviour:

module "mymodule" {
  source  = "./modules/mymoudle"

  roles = {
    (var.role_name) = {
      inline_policies = {
        (var.policy_name) = local.policy_statements
      }
    },
    (var.second_role_name) = {
      trust_policy = [local.events_trust_policy]
      inline_policies = {
        (local.policy_name_inline) = local.events_policy_statements
      }
    }
  }
  policies = {
    (var.policy_name) = {
      description = "Policy"
      statements  = local.events_policy_statements
    }
  }

}

Expected behavior

This HCL should parse. It does on 6.1.1

Exception traceback (if applicable):

Unexpected token Token('LPAR', '(') at line 178, column 5.
Expected one of: 
        * STRING_LIT
        * FOR_EACH
        * NL_OR_COMMENT
        * IF
        * NEGATIVE_DECIMAL
        * FOR
        * DECIMAL
        * IN
        * RBRACE
        * NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants