Closed elatovg closed 3 years ago
tried both suggestions from https://github.com/terraform-google-modules/terraform-google-project-factory/issues/538#issuecomment-761111833, but they didn't help out.
The problem you're encountering is that the service project is dependent on your host project ID, which is a computed attribute.
Cases like this are what this submodule are for, please try switching to that: https://github.com/elatovg/cft-bug-repro/pull/1
After switching to that submodule, I definitely get further... thanks for the help. But my terraform apply
fails with the following error:
Error: googleapi: Error 400: Invalid resource usage: ''projects/cft-env-shared-base-5ddb' is not a shared VPC host project.'., invalidResourceUsage
on .terraform/modules/svc_project.svc_project/modules/core_project_factory/main.tf line 103, in resource "google_compute_shared_vpc_service_project" "shared_vpc_attachment":
103: resource "google_compute_shared_vpc_service_project" "shared_vpc_attachment" {
Doing another terraform apply
right after the failure, succeeds. And same thing happens during a terraform destroy
, initially it fails with the following error:
Error: Error disabling Shared VPC Host "cft-env-shared-base-5ddb": googleapi: Error 400: Cannot disable project as a shared VPC host because it has active service projects., badRequest
But then running another terraform destroy
right after the failure succeeds as well.
You need to be careful with your sequencing: https://github.com/elatovg/cft-bug-repro/pull/2
It's really important that you build your dependency tree properly in Terraform. In this case, you were not making the service project dependent on the shared VPC actually being created.
Please try this example to understand the outputs which must be fed into the service project: https://github.com/terraform-google-modules/terraform-google-project-factory/blob/master/examples/shared_vpc/main.tf
Creating a host project with a shared VPC and then creating a service project attaching to the shared VPC produces errors. I created a sample git repository for reproducing the issue. Here is a simple way to reproduce the issue:
And then you will see the following error:
Please let me know if I am using the module in an incorrect way.