terraform-provider-google icon indicating copy to clipboard operation
terraform-provider-google copied to clipboard

create instance terraform gcp with shared vpc

Open ricardoeusse opened this issue 2 years ago • 3 comments

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!

ricardoeusse avatar Jun 10 '22 06:06 ricardoeusse

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

shuyama1 avatar Jun 10 '22 23:06 shuyama1

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.

Sylphe88 avatar Aug 10 '22 08:08 Sylphe88

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>

ghost avatar Aug 10 '22 08:08 ghost