Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform GCP VPC peering

I am trying to configure a VPC peering between my project network and another project using GCP, however I can't because I don't have permissions to list networks on the other project.

resource "google_compute_network" "my-network" {
  name                    = "foobar"
  auto_create_subnetworks = "false"
}

resource "google_compute_network_peering" "my-network" {
  name         = "peering1"
  network      = "${google_compute_network.my-network.self_link}"
  peer_network = "${data.google_compute_network.another-network.self_link}"
}

data "google_compute_network" "another-network" {
  name    = "another"
  project = "another-project"
}

The error:

Error 403: Required 'compute.networks.get' permission for 'projects/another-project/global/networks/another', forbidden

Since terraform doesn't have access to another-project I would like to know if there is any other way to do this with terraform.

Thank you in advance! :)

like image 514
Flávio Ferreira Avatar asked Dec 29 '25 04:12

Flávio Ferreira


1 Answers

If you know the name of the peer network just add the location:

peer_network = "projects/PEER_PROJECT/global/networks/PEER_NETWORK"

like image 139
Steve Avatar answered Jan 01 '26 03:01

Steve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!