Terraform: 1.0.3
When trying to create google_cloud_disk and google_cloud_instance depending on the disks, snippet from the configuration:
resource "google_compute_disk" "tst-disk1" {
name = "tst-disk1"
image = "debian-cloud/debian-10-buster-v20210217"
zone = "us-central1-a"
type = "pd-balanced"
physical_block_size_bytes = 4096
}
resource "google_compute_instance" "tst-instance1" {
name = "tst-instance1"
machine_type = "e2-micro"
zone = "us-central1-a"
boot_disk {
device_name = "tst-disk1"
initialize_params {
size = "10"
image = "https://www.googleapis.com/compute/v1/projects/projectname/zones/us-central1-a/disks/tst-disk1"
}
}
}
However, when I do ‘terraform apply’, the instance isn’t created:
Error: Error resolving image name 'https://www.googleapis.com/compute/v1/projects/projectname/zones/us-central1-a/disks/tst-disk1': Could not find image or family https://www.googleapis.com/compute/v1/projects/projectname/zones/us-central1-a/disks/tst-disk1
│
│ with google_compute_instance.tst-instance1,
│ on instances.tf line 91, in resource "google_compute_instance" "tst-instance1":
│ 91: resource "google_compute_instance" "tst-instance1"
But when I do gcloud compute disks list --format=yaml
, the “absent” disk is listed, its selfLink matches the problem one exactly.
How can I make Terraform detect the disk? Using “depends_on” inside instance definition doesn’t help.