I have been trying to create a script that allows the attachment of multiple disks into multiple instances using google_compute_attached_disk. What should I do in the resource “google_compute_attached_disk”?
resource "google_compute_disk" "encrypted_disk" {
count = "${var.resource_count}"
name = "${var.disk_name}${count.index}"
type = "${var.disk_type}"
zone = "${var.instance_zone}"
size = "${var.disk_size}"
image = "${var.image}"
labels = "${var.disk_labels}"
disk_encryption_key {
kms_key_self_link = "${var.encryption_key}"
}
}
resource "google_compute_attached_disk" "attached_encrypted_disk" {
disk = "${google_compute_disk.encrypted_disk.self_link}"
instance = "${google_compute_instance.compute_instance.self_link}"
}
resource "google_compute_instance" "compute_instance" {
count = "${var.resource_count}"
name = "${var.instance_name}${count.index}"
machine_type = "${var.instance_type}"
zone = "${var.instance_zone}"
tags = "${var.target_tags}"
boot_disk {
kms_key_self_link = "${var.encryption_key}"
auto_delete = "${var.disk_auto_delete}"
initialize_params {
size = "${var.image_size}"
type = "${var.disk_type}"
image = "${var.image}"
}
}
network_interface {
network = "${var.network}"
network_ip = "${var.private_ip}"
}
lifecycle {
ignore_changes = ["attached_disk"]
}
metadata = "${var.metadata}"
labels = "${var.instance_labels}"
scheduling {
preemptible = "${var.preemptible}"
automatic_restart = "${var.automatic_restart}"
}
service_account {
scopes = "${var.scopes}"
}
}