hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.31k stars 1.73k forks source link

google_bigquery_dataset_access unable to handle service account emails with mixed/upper cases #19547

Open kamal-1 opened 1 week ago

kamal-1 commented 1 week ago

Community Note

Terraform Version & Provider Version(s)

Terraform v1.9.6 on darwin_arm64

Affected Resource(s)

google_bigquery_dataset_access

Terraform Configuration

resource "google_bigquery_dataset_access" "bigquery_dataset_access" {
  for_each      = var.access_requests
  project       = each.value.project_id
  dataset_id    = each.value.dataset_id
  role          = each.value.role
  user_by_email = each.value.user_by_email
}

Debug Output

https://gist.github.com/kamal-1/49cd54c47b1733296b918c08f71d0bb7

Expected Behavior

Terraform apply should succeed after the access is granted to the service account.

Actual Behavior

Terraform apply completes with an error. Note that the access is granted but it fails while validation for service accounts having upper case or mixed case email addresses.

ā”‚ Error: Provider produced inconsistent result after apply ā”‚ ā”‚ When applying changes to google_bigquery_dataset_access.bigquery_dataset_access["project-READER-ENTERPRISE-REPORTS-@project.iam.gserviceaccount.com"], provider ā”‚ "provider[\"registry.terraform.io/hashicorp/google\"]" produced an unexpected new value: Root object was present, but now absent. ā”‚ ā”‚ This is a bug in the provider, which should be reported in the provider's own issue tracker.

2024-09-19T21:44:24.224-0700 [DEBUG] provider.terraform-provider-google_v6.3.0_x5: 2024/09/19 21:44:24 [DEBUG] Skipping item with role= "OWNER", looking for "READER") 2024-09-19T21:44:24.224-0700 [DEBUG] provider.terraform-provider-google_v6.3.0_x5: 2024/09/19 21:44:24 [DEBUG] Skipping item with userByEmail= , looking for "enterprise-reports@project.iam.gserviceaccount.com") 2024-09-19T21:44:24.224-0700 [DEBUG] provider.terraform-provider-google_v6.3.0_x5: 2024/09/19 21:44:24 [DEBUG] Skipping item with userByEmail= "ENTERPRISE-REPORTS@project.iam.gserviceaccount.com", looking for "enterprise-reports@project.iam.gserviceaccount.com")

Steps to reproduce

  1. Create a service account with upper case email address
  2. Use google_bigquery_dataset_access to assign a BigQuery role to the upper case service account email.
  3. Run terraform apply. Fails with error Error: Provider produced inconsistent result after apply

Important Factoids

References

There have been similar issues in the past. We were hoping that 17994 being the latest one, would have fixed the issue but even the latest version 6.3.0 has the issue.

https://github.com/hashicorp/terraform-provider-google/issues/17994 https://github.com/hashicorp/terraform-provider-google/issues/11985

b/369584826

kamal-1 commented 4 days ago

I recently discovered that it is not possible to create service accounts with all caps/mixed case via Google Cloud Console. However, it is possible to do that via gcloud CLI.

gcloud iam service-accounts create TEST-SERVICE-ACCOUNT --description "Creating service account with all caps" --display-name TEST-SERVICE-ACCOUNT

Output: Created service account [TEST-SERVICE-ACCOUNT]

ggtisc commented 2 days ago

According to terraform registry isn't possible to create a google_service_account with uppercase email address.

Apparently it is possible to create it through CLI but I don't have permission to confirm this.

kamal-1 commented 2 days ago

According to terraform registry isn't possible to create a google_service_account with uppercase email address.

Apparently it is possible to create it through CLI but I don't have permission to confirm this.

My comment here confirms this understanding. CLI allows the service accounts to be created with upper case.

https://github.com/hashicorp/terraform-provider-google/issues/19547#issuecomment-2368876451