Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator ... does not work with variables #24033

Closed
MarkKharitonov opened this issue Feb 5, 2020 · 4 comments
Closed

Operator ... does not work with variables #24033

MarkKharitonov opened this issue Feb 5, 2020 · 4 comments
Labels
bug config v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@MarkKharitonov
Copy link

Terraform Version

C:\temp\terraform\cfg [master]> C:\Users\mkharitonov\.terraform\terraform.exe version
Terraform v0.12.20
C:\temp\terraform\cfg [master]>

Terraform Configuration Files

variable "codes" {
    default = ["abc"]
}

locals {
    codes = ["abc"]
    _y1 = [
        for code in var.codes: {
            for num in [1]: "${code}-${num}" => {
                code = code
                num = num
            }
        }
    ]
    x = merge(local._y1...)

    _y2 = flatten([for m in local._y1: [for k,v in m: { 
        key = k
        value = v
    }]])
#    x = zipmap(local._y2.*.key, local._y2.*.value)
}
output "x" {
    value = local.x
}

Expected Behavior

Should output this:

x = {
  "abc-1" = {
    "code" = "abc"
    "num" = 1
  }
}

Actual Behavior

Error: Invalid expanding argument value

  on main.tf line 15, in locals:
  15:     x = merge(local._y1...)

The expanding argument (indicated by ...) must be of a tuple, list, or set
type.

Steps to Reproduce

  1. terraform init
  2. terraform apply

Additional Context

If we replace var.codes with local.codes then it works.

To make it work with var.codes there is a workaround - comment out the first assignment to x and uncomment the second one which uses zipmap

References

https://stackoverflow.com/questions/60067168/terraform-is-unable-to-apply-the-operator

-->

@bholzer
Copy link

bholzer commented Feb 6, 2020

I am encountering the same issue, but with a local

locals {
  # Define databases, and their roles with privileges
  databases = {
    for db in var.databases:
      db => {
        "${db}" = ["ALL"]
        "${db}_read" = ["CONNECT", "SELECT", "TEMP", "EXECUTE", "USAGE"] #readonly
      }
  }
}

resource "aws_secretsmanager_secret" "db_credentials" {
  for_each = keys(merge(values(local.databases)...))

  name = "RDSRole-${each.value}-${random_id.secret_id.hex}"
  rotation_lambda_arn = aws_lambda_function.rds_secret_rotator_lambda.arn

  rotation_rules {
    automatically_after_days = 30
  }
}

This code results in the same error:

In modules/database/main.tf line 206, in resource "aws_secretsmanager_secret" "db_credentials":
 206:   for_each = keys(merge(values(local.databases)...))

The expanding argument (indicated by ...) must be of a tuple, list, or set
type.

@UvaK
Copy link

UvaK commented Feb 8, 2020

This appears to be a duplicate of #22404 and it has a workaround for this issue.

@hashibot hashibot added the v0.12 Issues (primarily bugs) reported against v0.12 releases label Feb 13, 2020
@hashibot
Copy link
Contributor

Hello! 🤖

This issue seems to be covering the same problem or request as #22404, so we're going to close it just to consolidate the discussion over there. Thanks!

@ghost
Copy link

ghost commented Apr 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug config v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

No branches or pull requests

5 participants