Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@andrewthetechie

Description

@andrewthetechie

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

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions