Skip to content

fix(race): KMS module can create resources too early #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

petemounce
Copy link

@petemounce petemounce commented Mar 28, 2025

With TF_PARALLELISM=80 when applying the tech-foundations bootstrap (ref), it's possible to get an error.

This can occur because the data.google_storage_project_service_account does not exist yet (it is provisioned by the google_project_service in the project-factory module - https://github.com/terraform-google-modules/terraform-google-project-factory/blob/main/modules/project_services/main.tf#L31-L37)


│ Error: Error applying IAM policy for KMS CryptoKey "projects/prj-b-seed-7128/locations/us-central1/keyRings/prj-keyring/cryptoKeys/prj-key": Error setting IAM policy for KMS CryptoKey "projects/prj-b-seed-7128/locations/us-central1/keyRings/prj-keyring/cryptoKeys/prj-key": googleapi: Error 400: Service account service-224653906387@gs-project-accounts.iam.gserviceaccount.com does not exist., badRequest

│   with module.seed_bootstrap.module.kms[0].google_kms_crypto_key_iam_binding.encrypters[0],
│   on .terraform/modules/seed_bootstrap.kms/main.tf line 89, in resource "google_kms_crypto_key_iam_binding" "encrypters":
│   89: resource "google_kms_crypto_key_iam_binding" "encrypters" {

With `TF_PARALLELISM=80` when applying the bootstrap, it's possible to get an error.

This can occur because the `data.google_storage_project_service_account` does not exist yet (it is provisioned by the `google_project_service` in the project-factory module - https://github.com/terraform-google-modules/terraform-google-project-factory/blob/main/modules/project_services/main.tf#L31-L37)

```console
╷
│ Error: Error applying IAM policy for KMS CryptoKey "projects/prj-b-seed-7128/locations/us-central1/keyRings/prj-keyring/cryptoKeys/prj-key": Error setting IAM policy for KMS CryptoKey "projects/prj-b-seed-7128/locations/us-central1/keyRings/prj-keyring/cryptoKeys/prj-key": googleapi: Error 400: Service account service-224653906387@gs-project-accounts.iam.gserviceaccount.com does not exist., badRequest
│
│   with module.seed_bootstrap.module.kms[0].google_kms_crypto_key_iam_binding.encrypters[0],
│   on .terraform/modules/seed_bootstrap.kms/main.tf line 89, in resource "google_kms_crypto_key_iam_binding" "encrypters":
│   89: resource "google_kms_crypto_key_iam_binding" "encrypters" {
│
╵
```
@petemounce petemounce requested a review from a team as a code owner March 28, 2025 16:40
@petemounce
Copy link
Author

(Re-running terraform apply allows the resource to be created successfully)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant