terraform-linters / tflint

A Pluggable Terraform Linter
Mozilla Public License 2.0
4.86k stars 353 forks source link

Error: Circular reference found #1565

Closed sagar2610 closed 1 year ago

sagar2610 commented 1 year ago

Introduction

After installing the new version, 0.42.0, I start getting circular dependency errors in my local variables.

locals.tf


locals {
  resource_prefix            = "${var.project}-${var.usecase}"
  resource_prefix_underscore = "${var.project}_${var.usecase}"
}

test.tf


locals {
  pilot_ecrs = [
    "${local.resource_prefix}-main",
    "${local.resource_prefix}-tests"
  ]
}

module "prereq" {
  source               = "../../test"
  tags                 = local.default_tags
  resource_prefix      = local.pilot_resource_prefix
  kms_key_arns         = local.kmskey_arns
  ecr_repos            = local.pilot_ecrs
}
./infrastructure/project
Failed to prepare rule checking; failed to eval an expression in prerequisites.tf:27; prerequisites.tf:13,8-29: circular reference found; local.ecrs -> local.resource_prefix -> local.resource_prefix:

Error: circular reference found

  on prerequisites.tf line 13, in locals:
  13:     "${local.resource_prefix}-tests"

local.ecrs -> local.resource_prefix -> local.resource_prefix

-->

Expected Behavior

Actual behavior

Step to Reproduce

Additional Context

miguelangelmorenochacon commented 1 year ago

Same problem here, I've reproduced it with

locals {
  sample_value = "whatever"

  sample_map = merge({
    sample-key = {
      another-sample-key = local.sample_value
    }
    sample-key-2 = {
      another-sample-key = local.sample_value
    }
  })
}

resource "null_resource" "sample" {
  for_each = local.sample_map
}
Failed to check ruleset; Failed to check `google_project_iam_member_invalid_member` rule: tflint-fix.tf:9,28-46: circular reference found; local.sample_map -> local.sample_value -> local.sample_value
wata727 commented 1 year ago

Thank you for reporting this issue. I'm working on a fix for this bug.

wata727 commented 1 year ago

v0.42.1 has been released. https://github.com/terraform-linters/tflint/releases/tag/v0.42.1