hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.28k stars 1.72k forks source link

create instance terraform gcp with shared vpc #11862

Open ghost opened 2 years ago

ghost commented 2 years ago

Affected Resource(s)

This my code:

// VM srv-dc01

resource "google_compute_instance" "vm_01" { name = "srv-dc01" machine_type = "n2d-standard-2" zone = "europe-west4-a" allow_stopping_for_update = true

boot_disk { initialize_params{ image = "windows-server-2022-dc-v20220513" size = "100" type = "pd-balanced" } device_name = "os-srv-dc01-disk-0" }

network_interface { subnetwork = "${data.google_compute_subnetwork.subnet.id}" network_ip = "10.10.3.5" }

}

data "google_compute_subnetwork" "subnet" { name = "subnet_shared_vpc" region = "europe-west4" }

Error terraform Apply

google_compute_instance.vm_01: Creating... ╷ │ Error: Error creating network interfaces: exactly one of network or subnetwork must be provided │ │ with google_compute_instance.vm_01, │ on srv-dc01.tf line 3, in resource "google_compute_instance" "vm_01": │ 3: resource "google_compute_instance" "vm_01" {

Any idea since I can't get it, thanks!

b/308755874

shuyama1 commented 2 years ago

Would you mind sharing the build log for this error please. Thanks!

Sylphe88 commented 2 years ago

Got the same issue. Looks like we need to specify the project that hosts the subnet in the network_interface block but I'm still unable to set up the instance in my service project, with the following block:

network_interface { subnetwork = data.google_compute_subnetwork.my_host_vpc_subnet.name subnetwork_project = data.google_project.my_host_project.name access_config { network_tier = "STANDARD" } }

The error is exactly the same as @ricardoeusse. A manual creation + terraform import on the resource + terraform apply shows no difference, so I guess the HCL instance description is correct.

ghost commented 2 years ago

ya lo resolvi!

Gracias!!

Un saludo. [image: Tecnología | Confianza inspiradora. Globalmente.] http://www.techedgegroup.com/ Ricardo Eusse Sanchez Consultor de Nube

Móvil 679080554 Ricardo Eusse Sánchez <Ricardo%20Eusse%20Sanchez> Spain - Madrid Martínez Villergas, 52. Edificio B – Planta 6 Madrid, 28027 Phone +34 91 556 0013 <+34+91+556+0013> techedgegroup.com http://www.techedgegroup.com/ Mensaje solo para el destinatario previsto. Si lo recibe por error, comuníquese con el remitente y lea www.techedgegroup.com/disclaimer

El sáb, 11 jun 2022 a las 1:54, Shuya Ma @.***>) escribió:

Would you mind sharing the build log for this error please. Thanks!

— Reply to this email directly, view it on GitHub https://github.com/hashicorp/terraform-provider-google/issues/11862#issuecomment-1152806034, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXUWGIO4H62FQVLITTC75HDVOPITDANCNFSM5YMULTPA . You are receiving this because you are subscribed to this thread.Message ID: @.*** com>

karolgorc commented 1 week ago

Couldn't recreate this error on any of the provided configs

Played around with providing data sources, variables, locals, and references to resources to somehow break this but couldn't.