terraform-google-modules/terraform-google-bootstrap

Error 400: Unknown project id - Due to Dependency Issue

dmcgowandmc opened this issue · 5 comments

Hi All,

Facing a weird error which I think is more related to terraform core code itself, but wanted to call it out hear in case anyone else faces the issue, and a workaround could be added to fix the issue in this module

Basically, when I run the module, I get the following error

module.bootstrap_standard.module.seed_project.module.project-factory.random_id.random_project_id_suffix: Refreshing state... [id=xqU]
╷
│ Error: Error when reading or editing GCS service account not found: googleapi: Error 400: Unknown project id: 'dcs-seed-c6a5', invalid
│ 
│   with module.bootstrap_standard.data.google_storage_project_service_account.gcs_account,
│   on .terraform/modules/bootstrap_standard/main.tf line 83, in data "google_storage_project_service_account" "gcs_account":
│   83: data "google_storage_project_service_account" "gcs_account" {

This snippet of code is the culprit

/***********************************************
  GCS Bucket - Terraform State
 ***********************************************/
data "google_storage_project_service_account" "gcs_account" {
  project = module.seed_project.project_id
}

There actually isn't anything wrong with the code, but for some reason, terraform is executing this data resource before all the resources in the project factory module have had a chance to execute. So we have a valid project ID, but no project has yet been created, hence the error

I added the following dependency

/***********************************************
  GCS Bucket - Terraform State
 ***********************************************/
data "google_storage_project_service_account" "gcs_account" {
  project = module.seed_project.project_id

  depends_on = [
    module.seed_project.project_id
  ]
}

And this forced the data resource to wait until ALL resources in the project factory module complete, fixing the issue

Regards,
Doug.

This does seem like a core issue since your data source should have had an implicit dependency anyways.

Closing since I don't think there's anything for us to do here.

Hello Morgante,

Apologies for rehashing this one again. I reached out to the core terraform team and they explained that this is expected behaviour.

hashicorp/terraform#29555

It does sound odd to me, but if this is the way terraform is expected to behave, do you think we could add this dependency in to resolve the issue?

I can push a change up if that's easier

Regards,
Doug.

Hi Morgante,

I had the same issue and the solution of Doug helped me out ... is there a plan to fix it ?

I'm fine with adding this dependency, though I'm somewhat confused on why it's not working automatically without it.

Hey Morgante,

Yeah I agree it's odd behaviour, I would have expected dependencies for data to be managed just like any conventional resource. In terms of path of least resistance, I think making the change here is the way to go, and maybe we can ask the core terraform team again to clarify if this is indeed expected behaviour.

Regards,
Doug.