bocan / mastodon-google-cloud

This rough bit of code will spin up a network and a Google Kubernetes Engine in Google Cloud to let you run Mastodon. It includes a bucket for media, some backup stuff, and a Google SQL (Postgres) database
https://mastodon.cloudcauldron.io
MIT License
6 stars 0 forks source link

Terraform "Invalid for_each argument" Error #2

Open jhademcconnell opened 1 year ago

jhademcconnell commented 1 year ago

Issue

When running terraform plan or terraform apply this error returns:

Plan: 27 to add, 0 to change, 0 to destroy.
╷
│ Error: Invalid for_each argument
│
│   on .terraform/modules/custom_role/modules/custom_role_iam/main.tf line 85, in resource "google_project_iam_member" "custom_role_member":
│   85:   for_each = var.target_level == "project" ? toset(var.members) : []
│     ├────────────────
│     │ var.members is list of string with 1 element
│     │ var.target_level is "project"
│
│ The "for_each" set includes values derived from resource attributes that cannot be determined
│ until apply, and so Terraform cannot determine the full set of keys that will identify the
│ instances of this resource.
│
│ When working with unknown values in for_each, it's better to use a map value where the keys are
│ defined statically in your configuration and where only the values contain apply-time results.
│
│ Alternatively, you could use the -target planning option to first apply only the resources that
│ the for_each value depends on, and then apply a second time to fully converge.

There are mentions online to append -target=resource to get around this but not sure what this means in the context of this project's Terraform deployment into GCP. I will continue to look but if you've ran into this error that'd help.

Steps to Reproduce

  1. Clone the project
  2. Changed variables
  3. Run terraform init
  4. Run terraform fmt then terraform validate
  5. Run terraform apply
jhademcconnell commented 1 year ago

This is thrown when you set enable_velero_backups = true in terraform.tfvars. If you set this to false, no errors are thrown when running terraform plan/apply.

bocan commented 1 year ago

Thanks @jhademcconnell. I'll have a look at this. Can you let me know what version of Terraform you're running it with? I run my own apply with it set to true without issue, but I wonder if I installed everything with it set to false, and then turned it on.

jhademcconnell commented 1 year ago

@bocan np, I ran into your project and wanted to play it around with it so I'm using a new GCP project through setup. Terraform version: Terraform v1.4.4.

I ran into two more issues but I can open a separate issue in case of future improvements. I was able to get through the Terraform install though, gonna try running a Mastodon instance on it next through the helm instructions. Still looking through docs for that part