Cloud composer - Data sources with GCP

Hello, I hope you are all OK :slight_smile:
I have some issue with terraform and GCP.

The goal is to create a Cloud Composer instance on project A and to retrieve the network resources (network & subnetwork) from project B.

I used a data-sources.tf file, but it doesn’t seem to be working. My data-sources.tf file specifies the network resources from project B, but in my composer.tf file, I indicate that it should create the Cloud Composer instance in project A.

In my tf-plan-review, I have:

network = “projects/project A/global/networks/network project B”
subnetwork = “projects/project A/regions/europe-xxx/subnetworks/subnetwork project B”

Logically, based on this, it looks for the information in project A and not in project B.

Do you have any ideas? :slightly_smiling_face:

Hi @kad25,

Are you using a single GCP provider block? Such as:

provider "google" {
  project = "{{YOUR GCP PROJECT}}"
  region  = "us-central1"
  zone    = "us-central1-c"
}

If this is the case then that provider will only access the resources in the project referenced as documented the google provider block references a single project.

To access resources in a separate project you will need to use multiple provider configurations.

I would suggest you set up a second provider with an alias for use with the data sources from the other project. Leaving the default provider (without alias) to be the one referencing the project where you are deploying. And then update the data resources that are getting information from the other project:

data "aws_some_resource" "some_name" {
  provider = aws.alias_name

  # ...
}

Hope that helps

Happy Terraforming