I'm sure this is a quick one..
I'm trying to run through a resource creation with count, and name the resource accordingly. Here I have two problems.. one that I'm unsure if can be fixed, so I am guessing I'll have to use the following work around.
This is my instance creation, one for a disk, and another for a compute instance:
resource "google_compute_disk" "us-am-build" {
count = "${var.us_am_count}"
name = "am${count.index}-disk"
type = "pd-standard"
size = "200"
zone = "us-east1-b"
}
resource "google_compute_instance" "us-am-build" {
count = "${var.us_am_count}"
project = "${var.gcp_project}"
name = "am${count.index}"
machine_type = "n1-standard-1"
zone = "us-east1-b"
allow_stopping_for_update = "true"
tags = "${var.am_instance_tags}"
service_account {
email = "${var.service_account}"
scopes = [ "cloud-platform" ]
}
boot_disk {
initialize_params {
image = "${var.compute_image}"
}
}
attached_disk {
source = "${google_compute_disk.us-am-build.self_link}"
device_name = "${google_compute_disk.us-am-build.name}-1"
}
network_interface {
subnetwork = "${var.us-east-1-subnet}"
subnetwork_project = "${var.gcp_project}"
access_config = {}
}
metadata {
certname = "am0-us.forgerock.com"
shutdown-script = "${file("${path.module}/scripts/node_termination_publish.sh")}"
startup-script = "${file("${path.module}/scripts/startup.sh")}"
}
}
The first issue is that I wanted to loop through a count of 4, 2 of which would be in us-east and the other 2 would be in eu-west. I couldn't think of a way to be able to loop through and have them in different regions.
The other problem is with the above demonstration, and the name of the instances between the disk and the compute instance.
count = "${var.us_am_count}"
Let's say the above is set to 2 (for US).
name = "am${count.index}-disk"
Would the name of the first disk be am0-disk?
The error I'm getting it:
* module.am-deploy.google_compute_instance.us-am-build[1]: Resource 'google_compute_disk.us-am-build' not found for variable 'google_compute_disk.us-am-build.self_link'
* module.am-deploy.google_compute_instance.us-am-build[0]: Resource 'google_compute_disk.us-am-build' not found for variable 'google_compute_disk.us-am-build.self_link'