_This issue was originally opened by @jegadeshhike as hashicorp/terraform#16248. It was migrated here as a result of the provider split. The original body of the issue is below._
Terraform v0.10.6
I want to 2 google_compute_instance with 3 disk (1 boot disk and 2 attached_disk). can someone help ?
resource "google_compute_disk" "test-disk" {
name = "test${count.index+1}-test"
type = "pd-standard"
size = 2
zone = "asia-southeast1-a"
count = 2
}
resource "google_compute_instance" "test" {
name = "test${count.index+1}"
machine_type = "n1-standard-1"
zone = "asia-southeast1-a"
can_ip_forward = true
count = 2
disk {
type = "pd-standard"
size = 100
image = "centos-cloud/centos-7-v20150710"
}
disk {
disk = "${element(google_compute_disk.test-disk.*.name, count.index)}"
auto_delete = false
}
# ... network config and provisioners ...
}
Output:
Terraform will perform the following actions:
google_compute_disk.test-disk[0]
id:
disk_encryption_key_sha256:
name: "test1-test"
self_link:
size: "2"
type: "pd-standard"
users.#:
zone: "asia-southeast1-a"
google_compute_disk.test-disk[1]
id:
disk_encryption_key_sha256:
name: "test2-test"
self_link:
size: "2"
type: "pd-standard"
users.#:
zone: "asia-southeast1-a"
google_compute_instance.test[0]
id:
can_ip_forward: "true"
create_timeout: "4"
disk.#: "2"
disk.0.auto_delete: "true"
disk.0.disk_encryption_key_sha256:
disk.0.image: "centos-cloud/centos-7-v20150710"
disk.0.size: "100"
disk.0.type: "pd-standard"
disk.1.auto_delete: "false"
disk.1.disk: "test1-test"
disk.1.disk_encryption_key_sha256:
label_fingerprint:
machine_type: "n1-standard-1"
metadata_fingerprint:
name: "test1"
scheduling.#:
self_link:
tags_fingerprint:
zone: "asia-southeast1-a"
google_compute_instance.test[1]
id:
can_ip_forward: "true"
create_timeout: "4"
disk.#: "2"
disk.0.auto_delete: "true"
disk.0.disk_encryption_key_sha256:
disk.0.image: "centos-cloud/centos-7-v20150710"
disk.0.size: "100"
disk.0.type: "pd-standard"
disk.1.auto_delete: "false"
disk.1.disk: "test2-test"
disk.1.disk_encryption_key_sha256:
label_fingerprint:
machine_type: "n1-standard-1"
metadata_fingerprint:
name: "test2"
scheduling.#:
self_link:
tags_fingerprint:
zone: "asia-southeast1-a"
Hey @jegadeshhike, we recently upgraded the Google provider in Terraform so we don't use the disk field on instances anymore. I can try to help you out with your current version if you don't want to upgrade yet, but I'm not totally clear what the issue is right now (can you edit your issue to include code formatting for everything that is input / output?)
@danawillow - I have upgraded to I need to create a node with one boot_disk and two attached_disk.
But only one attached_disk getting attached to node.
Input:
resource "google_compute_disk" "test-disk" {
name = "test${count.index+1}-test"
type = "pd-standard"
size = 2
zone = "asia-southeast1-a"
count = 2
}
boot_disk {
initialize_params {
image = "centos-cloud/centos-7-v20150710"
type = "pd-ssd"
size = 20 }
}
attached_disk {
source = "${element(google_compute_disk.test-disk.*.name, count.index)}"
}
Actual output :
boot_disk.#: "1"
attached_disk.#: "1" <-- One disk only getting attached
Expected output :
boot_disk.#: "1"
attached_disk.#: "2" <-- It should be 2
Ah I see what's going on. Your count is referring to the number of instances, so you're going to end up with 2 instances, each with an attached disk from your list. Unfortunately HCL doesn't support count on objects within a resource, so you'll have to specify each attached disk separately. I'm going to close this issue but let me know if I'm misunderstanding!
@danawillow may I ask why you close this issue? Did you find a way to attach multiple disk (number of disk should be dynamic) to one single instance on GCP? Thanks for your feedback
Hey @DeWaRs, I closed the issue because it doesn't relate to the Google provider at all- the feature request is to be able to support counts inside a block, which isn't currently a part of Terraform. If that becomes something that Terraform supports as a whole, then the Google provider will get it automatically. I think https://github.com/hashicorp/terraform/issues/7034 is the right issue to be following.
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!
Most helpful comment
Hey @DeWaRs, I closed the issue because it doesn't relate to the Google provider at all- the feature request is to be able to support counts inside a block, which isn't currently a part of Terraform. If that becomes something that Terraform supports as a whole, then the Google provider will get it automatically. I think https://github.com/hashicorp/terraform/issues/7034 is the right issue to be following.