Hi Team,
I am using module to create additional disk but getting below error and u can see my code below any assistance please?
error : │ Error: Invalid for_each argument
│
│ on .terraform/modules/xxx/module/main.tf line 27, in resource “google_compute_disk” “additional_disks”:
│: for_each = { for disk in var.additional_disks : disk.name => disk }
│ ├────────────────
│ │ var.additional_disks is list of object with 1 element
Code :
resource “random_string” “add_disk_suffix” {
length = 4
number = true
min_numeric = 2
upper = false
special = false
}
module “gce” {
source = “xyz”
version = “1.0.3”
name = var.instance_name
project = var.gcp[var.environment].project_id
zone = var.zone
subnetwork_project = var.gcp[var.environment].network_project
subnetwork = var.gcp[var.environment].subnetwork
machine_type = var.machine_type
tags = “{split(",", var.tags)}"
source_image = var.source_image
source_image_project = var.source_image_project
service_account_email = var.gcp[var.environment].service_account
metadata = {
env = var.environment,
creator = var.vm_owner
}
metadata_startup_script = "{file(”./…/scripts/bootstrap.sh")}"
additional_disks = [{
name = “additional-disk-${random_string.add_disk_suffix.result}”,
type = “pd-ssd”,
size = var.additional_disk_size,
description = “”,
labels = {},
mode = “READ_WRITE”,
device_name = “”,
disk_encryption_key_raw = “”,
kms_key_self_link = “”,
snapshot = “”,
provisioned_iops = 0,
resource_policies =
}]
}
locals {
disk_name = “${var.instance_name}”
}
variable “additional_disks” {
description = “Additional persistent disks to attach to the instance.”
type = list(object({
name = string
size = number
type = string
provisioned_iops = number
description = string
labels = map(string)
device_name = string
mode = string
kms_key_self_link = string
disk_encryption_key_raw = string
snapshot = string
resource_policies = list(string)
provisioned_iops = number
}))
default =
}
Thanks
Mahen