VladRassokhin / intellij-hcl

HCL language support for IntelliJ platform based IDEs
Apache License 2.0
244 stars 47 forks source link

Members of complex object outputs of modules are reported as unresolved if output referenzes object from array #293

Open albuch opened 4 years ago

albuch commented 4 years ago

Installation details

Terraform Configuration Files

Module output defined with a resource object in a module:

variable "enabled" {
  default = true
}
resource "aws_s3_bucket" {
  count = var.enabled ? 1 : 0
  ...
}
output "bucket" {
  value= var.enabled ? aws_s3_bucket.this_bucket[0] : null
}

and then referenced a member of the modules output object:

module "test" {}

local {
   test= module.test.bucket.bucket
}

Exception

Unresolved reference bucket

Expected Behavior

Members of complex outputs (e.g. ressources) from an array should not be reported as unresolved.

Actual Behavior

terraform apply properly works IDEA displays validation error "Unresolved reference ". This seems to have already been partially fixed with 0.7.2 (see #213) however it is still happening for this case with 0.7.7.

ImIOImI commented 4 years ago

This seems to be close to my issue as well (uploading the picture to show incorrect syntax highlighting). image

Result: image

VladRassokhin commented 4 years ago

Screenshots with sources 🤦 , is there a web service which converts them to text already? Moreover it's another issue

VladRassokhin commented 4 years ago

@albuch Seems it's unresolved due to ternary operator, works fine in case of

output "bucket" {
  value= aws_s3_bucket.this_bucket[0]
}
tmahncke-lhind commented 4 years ago

I am expierencing a similar issue in a setup having

output "disk" {
  value = var.allow_disk_source_change ? azurerm_managed_disk.disk_no_recreation[0] : azurerm_managed_disk.disk_force_recreation[0]
}

Where var.allow_disk_source_change is a bool. I am then using disk.id from the output which should always be defined. Terraform itself is not reporting anything but the plugin is reporting an error.

IDE Version: IntelliJ IDEA 2019.3.5 (Ultimate Edition) Build #IU-193.7288.26, built on May 6, 2020 intellij-hcl plugin version: 0.7.9 Terraform version: 0.12.25 provider.azurerm 2.10.0

If wanted I can create a separate Issue.

dartov commented 4 years ago

Looks like similar issue to mine:

resource "aws_eks_cluster" "main" {
  name = "test"
  role_arn = "role-abcd"
  vpc_config {
    subnet_ids = ["subnet-abcd"]
  }
}

output "oidc_provider_url" {
  value = aws_eks_cluster.main.identity[0].oidc[0].issuer
}

I'm getting Unresolved reference issuer while terraform apply and plan work fine. I can report a separate issue.

IDE Version: IntelliJ IDEA 2020.2 (Ultimate Edition) Build #IU-202.6397.94, built on July 27, 2020 intellij-hcl plugin version: 0.7.10 Terraform version: v0.13.1 provider aws 3.4.0

systematicguy commented 1 year ago

I have a slightly different use case when I employ a proxy local for the terraform_remote_state data:

data "terraform_remote_state" "backend_infra" {
  backend = "s3"
  config = {
    bucket = var.backend_bucket
    key    = var.backend_key
    region = "eu-central-1"
  }
}

locals {
  backend_outputs = data.terraform_remote_state.backend_infra.outputs
  deployment_stage = local.backend_outputs.deployment_stage
}

Wherever I use the proxy local (I do this for sake of brevity on multiple places) it gets highlighted with the same Unresolved reference error. image

IDE: 2022.2.3 (Build #PY-222.4345.23, built on October 10, 2022) HCL Plugin: 222.4345.14 Terraform version: 0.13.5

FWIW, this issue got me thinking: https://github.com/VladRassokhin/intellij-hcl/issues/108#issuecomment-329997796

At the same time 'unresolved reference' doesn't highlight that code as error since 'terraform_remote_state' specially marked to contain dynamic properties.

It would be ideal to be able to somehow mark locals to contain dynamic properties