mfcastellani / hcl-checker

Ruby Gem to parse and validate HCL files
MIT License
17 stars 8 forks source link

Add support for Resources and Modules as Values #12

Open mfcastellani opened 3 years ago

mfcastellani commented 3 years ago

Building on this capability, Terraform 0.12 now permits using entire resources as object values within configuration, including returning them as outputs and passing them as input variables:

Configuration for Terraform 0.12

output "vpc" {
  value = aws_vpc.example
}

The type of this output value is an object type derived from the schema of the aws_vpc resource type. The calling module can then access attributes of this result in the same way as the returning module would use aws_vpc.example, such as module.example.vpc.cidr_block.

This capability also works for modules themselves, with an expression like module.vpc evaluating to an object value with attributes corresponding to the modules's named outputs.

https://www.hashicorp.com/blog/terraform-0-12-rich-value-types

thiagoarrais commented 3 years ago

This parses in main branch. What is the expected behaviour here? Should the parser output differentiate between references and strings? How?

  it 'parses resource reference as value' do
    hcl_string = 'output "foo" {' \
                 'value = bar_resource.baz' \
                 '}'
    expect(HCL::Checker.parse hcl_string).to eq({
      "output" => {
        "foo" => {
          "value" => "bar_resource.baz", 
        }
      }
    })
  end
mfcastellani commented 3 years ago

Parser should be able to parse data with or without quotes. Currently this break the parser:

variable "networks" {
  type = map(object({
    network_number    = number
    availability_zone = string
    tags              = map(string)
  }))
}

But since 0.12 this is a valid code and should be parsed correctly