hashicorp / terraform-config-inspect

A helper library for shallow inspection of Terraform configurations
Mozilla Public License 2.0
383 stars 76 forks source link

Error: Invalid expression #27

Closed nunofernandes closed 5 years ago

nunofernandes commented 5 years ago

Hi,

I'm getting the following error when running terraform-config-inspect:

...
## Problems

## Error: Invalid expression

(at `main.tf` line 164)

Expected the start of an expression, but found an invalid expression token.

The line in question is:

resource "aws_instance" "squid" {
  count         = length(var.availability_zones)
  ami           = var.ami_id != "" ? var.ami_id : data.aws_ami.amzn2.id
  instance_type = var.instance_type
  key_name      = var.aws_key_name
  user_data     = data.template_cloudinit_config.squid.rendered
  monitoring    = true
  ebs_optimized = true

  dynamic "network_interface" {
    iterator = interface
>>>    for_each = length(var.network_interface_ids) > 0 ? list(element(var.network_interface_ids, count.index)) : list(element(aws_network_interface.squid[*].id, count.index))                                                                                                                                                

    content {
      device_index         = 0
      network_interface_id = interface.value
    }
  }
...

The above code works fine in terraform plan and terraform apply.

teamterraform commented 5 years ago

Hi @nunofernandes!

There have been a few bugs fixed in the underlying language parser over the last few months, so perhaps the parser dependency of this library is too old to have some fix for that, while Terraform CLI has been upgraded.

In your dev environment, could you try selecting the latest version of hashicorp/hcl2 in your project's go.mod and see if the problem goes away?

go get github.com/hashicorp/hcl2@master

If that fixes it, then we could make it permanent by updating the go.mod in this repository to refer to a newer version.

nunofernandes commented 5 years ago

Yeap.. that fixes it!

$ cd $GOPATH/src/github.com/hashicorp/hcl2 && git pull && GO111MODULE=on go get github.com/hashicorp/terraform-config-inspect

$ cd <MODULEDIR/squid> && terraform-config-inspect
...
* `data.aws_vpc.selected` from `aws`
* `data.template_cloudinit_config.squid` from `template`
* `data.template_file.awscli` from `template`
* `data.template_file.clamav` from `template`
* `data.template_file.ecs_cloud_config` from `template`
* `data.template_file.icinga` from `template`

## Child Modules
* `ecr` from `../terraform-aws-ecr`
* `service` from `../terraform-aws-ecs-service`