Use Terraform to manage ssh-keys in GCE I use Terrafrom and manage access to VMs in GCE by changing VM metadata.

Before I put it to string, but it not good, so I try to put them to variable and use it. But I faced problem. This is my code:

variable "ssh_keys" {
  type = "list"
  default = [
    {
      user = "atolkachev",
      key = "ssh-rsa my_key atolkachev"
    },
  ]
}

resource "google_compute_instance" "instance" {
  zone = "${var.region}-${var.zone}"
  project = "${var.project_name}"
  metadata = {
    ssh-keys = join("\n", [for user, key in var.ssh_keys : "${user}:${key}"])
  }


When I execute it, I get error:

Error: Invalid template interpolation value

  on main.tf line 24, in resource "google_compute_instance" "instance":
  24:     ssh-keys = join("\n", [for user, key in var.ssh_keys : "${user}:${key}"])


I tried to find solution, but failed.
There was used wrong type for variable, should be:

variable "ssh_keys" {
  type = "map"
  default = {
    "atolkachev" = "ssh-rsa my_key atolkachev"
  }
}