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.29k stars 1.72k forks source link

unexpected diff on google provider update from 4.65.0 to > 5.0.0 #18081

Open NemanjaMilenkovic opened 4 months ago

NemanjaMilenkovic commented 4 months ago

Community Note

Terraform Version & Provider Version(s)

cdktf 0.17.2 on

Affected Resource(s)

Terraform Configuration


  readonly editors = this.appBridgeSa.editorPrincipals.map(
    (principal) =>
      new google.bigqueryDatasetIamMember.BigqueryDatasetIamMember(
        this,
        `editor-${principal.type}-${principal.id}`,
        {
          datasetId: this.dataset.datasetId,
          role: 'roles/bigquery.dataEditor',
          member: principal,
        },
      ),
  );

Debug Output

(not relevant data redacted with "...")


 # google_bigquery_dataset_iam_member.org--editor-serviceAccount-dataform-sa_DF61663B must be replaced
-/+ resource "google_bigquery_dataset_iam_member" "org---editor-serviceAccount-dataform-sa_DF61663B" {
      + etag       = (known after apply)
      ~ id         = "projects/.../datasets/.../roles/bigquery.dataEditor/serviceAccount:service-...@gcp-sa-dataform.iam.gserviceaccount.com" -> (known after apply)
      ~ member     = "serviceAccount:service-...@gcp-sa-dataform.iam.gserviceaccount.com" # forces replacement -> (known after apply) # forces replacement
      ~ project    = "..." -> (known after apply)
        # (2 unchanged attributes hidden)

  # google_bigquery_connection_iam_member.org--dataform must be replaced
-/+ resource "google_bigquery_connection_iam_member" "org--serviceAccount-dataform" {
      ~ connection_id = "projects/.../locations/asia-northeast1/connections/custom_project_id" -> "custom_project_id"
      ~ etag          = "...=" -> (known after apply)
      ~ id            = "projects/.../locations/asia-northeast1/connections/custom_project_id/roles/bigquery.connectionUser/serviceAccount:service-...@gcp-sa-dataform.iam.gserviceaccount.com" -> (known after apply)
      ~ member        = "serviceAccount:service-...@gcp-sa-dataform.iam.gserviceaccount.com" # forces replacement -> (known after apply) # forces replacement
      ~ project       = "..." -> (known after apply)
        # (2 unchanged attributes hidden)
    }

Expected Behavior

no change

Actual Behavior

unexpeced diff on connection_id and force change on member

Steps to reproduce

  1. create google_bigquery_dataset_iam_member resource
  2. use google provider version < 5.0.0
  3. update google provider version to >=5.0.0
  4. terraform apply

Important Factoids

No response

References

No response

ggtisc commented 3 months ago

Hi @NemanjaMilenkovic!

I'm reviewing this scenario, but I saw that you have a lot of different versions:

Could you please be clear on which terraform version and Google provider version are you using? And if you are using a particular terraform code for the resources google_bigquery_connection_iam_member and google_bigquery_dataset_iam_member because you are only sharing a map without more context

NemanjaMilenkovic commented 3 months ago

Hi @ggtisc!

This would be an example of cdktf used that would cause it: (any google_bigquery_dataset_iam_member resource would should produce same result, there )

readonly connectionExample = new google.bigqueryConnectionIamMember.BigqueryConnectionIamMember(
  this,
  `connection-exampleId-exampleType-examplePrincipalId`,
  {
    connectionId: `projects/exampleProject/locations/exampleLocation/connections/exampleConnectionId`,
    role: 'roles/bigquery.connectionUser',
    member: `serviceAccount:${principal.email}`,
    location: 'exampleLocation',
  }
);

Terraform HCL equivalent would be something like:

resource "google_bigquery_dataset_iam_member" "user" {
  dataset_id = 'projects/exampleProject/locations/exampleLocation/connections/exampleConnectionId'
  role       =  'roles/bigquery.connectionUser'
  member     = 'serviceAccount:${principal.email}'
}

I see the cause being Terraform Data Source, used for google_bigquery_dataset_iam_member.member - this can be avoided with a workaround of using local values (indirectly referencing the managed resource values ​​through a local value). More info about data source dependencies: https://developer.hashicorp.com/terraform/language/data-sources#data-resource-dependencies

Main question here is - why is this happening on Google provider update from major version 4 to Google provider update to major version 5.

ggtisc commented 3 months ago

I tried to replicate this issue following your specifications, but the result was No changes. Your infrastructure matches your configuration.

The 1st thing I noticed is that you are using variables in your code like:

I suggest you check your code configuration related to your variables 1 by 1 to see if any are changing its value at compilation, run or execution time.

Finally the code used to replicate this scenario is here.