Terraform failing with Invalid for_each argument / The given “for_each” argument value is unsuitable

Explanation This error is often caused by passing a list to for_each, but for_each only works with unordered data-types, i.e. with sets and maps. Solution The resolution depends on the situation. List of strings If the list is just a list of strings, the easiest fix is to add a toset()-call to transform the list … Read more

How to reference a resource created by a Terraform module

Since you’re using a module, you need to change the format of the reference slightly. Module Outputs use the form ${module.<module name>.<output name>}. It’s also important to note, you can only reference values outputted from a module. In your specific case, this would become ${module.vpc.vpc_id} based on the VPC Module’s Outputs.

Getting an Environment Variable in Terraform configuration?

I would try something more like this, which seems closer to the documentation. variable “UN” { type = string } variable “PW” { type = string } resource “google_container_cluster” “primary” { name = “marcellus-wallace” zone = “us-central1-a” initial_node_count = 3 master_auth { username = var.UN password = var.PW } node_config { oauth_scopes = [ “https://www.googleapis.com/auth/compute”, … Read more

Experimenting Locally with Terraform

Terraform supports a bunch of providers, but the vast majority of them are public cloud based. However, you could set up a local VMware vSphere cluster and use the vSphere provider to interact with that to get you going. There’s also a provider for OpenStack if you want to set up an OpenStack cluster. Alternatively … Read more