garbetjie/terraform-google-cloud-run

How can i pass more than one env ?

Closed this issue · 5 comments

I tried this example:

env = [{ key = "DB_HOST",value = var.database_dns_name },
{ key = "DB_PASS", value = var.schema_pass }]

But i got this error:
Cannot use a tuple value in for_each. An iterable collection is required.

@naynivek Could you confirm the module version & terraform version you're using? I remember receiving an error similar to this on one of the older versions. I'm currently using this module in production, and I'm not receiving this error.

Is there any way you're able to provide a sample usage of the module that replicates this issue (with sensitive values redacted/removed of course)? It would really help in trying to track down the issue.

Hi, thanks for the answer!
My terraform is in v0.15.4
Your module is in v2.0.0

This is module config, it's working because i'm passing only one var in env, when i try more than one, i get the error.

module "cloud-run" {
  source = "garbetjie/cloud-run/google"
  version = "~> 2"

  name     = var.service_name
  image    = var.image
  location = var.location
  allow_public_access = true
  env = [{ key = "DB_HOST",value = var.database_dns_name}]

  vpc_access = { connector = var.vpc , egress = "private-ranges-only" }
  max_instances = 2
  min_instances = 0
  port = 80

}

Hi, i have an update!
The error only occurs when i use the var.schema_pass variable, when i put any word between "" as simple string, the terraform plan runs correctly.
I think the sensitive information is causing the problem, but when using the official provider this kind of problem doesn't occur.

The error

│ │ local.env has a sensitive value

│ Cannot use a tuple value in for_each. An iterable collection is required.

module "cloud-run" {
  source = "garbetjie/cloud-run/google"
  version = "~> 2"

  name     = var.service_name
  image    = var.image
  location = var.location
  allow_public_access = true
  env = [{ key = "DB_HOST",value = var.database_dns_name },
         { key = "DB_PASS",value = var.schema_pass },
         { key = "DB_USER",value = var.schema_user },
         { key = "DB_NAME",value = var.schema },
         { key = "WP_ENV",value = var.env },
         { key = "SSL_ENABLE",value = "true" },
         { key = "TABLE_PREFIX",value = "pgmkr" },
         { key = "WP_CONTENT_DIR_NAME",value = "box" },
         { key = "LAST_VERSION",value = var.sha }
         ]

  vpc_access = { connector = var.vpc , egress = "private-ranges-only" }
  max_instances = 2
  min_instances = 0
  port = 80

Hmmm... Wrapping the var.schema_pass value in a nonsensitive() function call should help.

I'm not sure whether the issue could be caused by the fact that the env values are also displayed in the output, and Terraform is perhaps complaining about that? Could you try use git@github.com:garbetjie/terraform-google-cloud-run?ref=test-sensitive-env as the source for the module? I've added the sensitive = true attribute to the env output in that branch. That might help fix it. If it does, I'll update the docs to reflect this issue.

If it doesn't help, the nonsensitive() function call might help, and I'll try take another look when I have a moment.

Yes, the nonsesitive() function worked for me!
Thanks a lot!

output "username" {
  description = "username"
  value       = google_sql_user.user.name
}

output "password" {
  description = "password"
  value       = nonsensitive(google_sql_user.user.password)
}

output "schema_name" {
  description = "schema name"
  value       = google_sql_database.schema.name
}