diff --git a/.changelog/9561.txt b/.changelog/9561.txt new file mode 100644 index 00000000000..07f5370f900 --- /dev/null +++ b/.changelog/9561.txt @@ -0,0 +1,3 @@ +```release-note:bug +logging: value change of `unique_writer_identity` on `google_logging_project_sink` does not trigger diff on dependent's usages of `writer_identity` +``` diff --git a/google/services/logging/resource_logging_project_sink.go b/google/services/logging/resource_logging_project_sink.go index 7d29ba2c3de..f61bcb1422f 100644 --- a/google/services/logging/resource_logging_project_sink.go +++ b/google/services/logging/resource_logging_project_sink.go @@ -96,10 +96,19 @@ func resourceLoggingProjectSinkAcquireOrCreate(d *schema.ResourceData, meta inte return resourceLoggingProjectSinkUpdate(d, meta) } -// if bigquery_options is set unique_writer_identity must be true +// 1) if bigquery_options is set unique_writer_identity must be true +// 2) taint the value of writer_identity when unique_writer_identity is updating from false -> true func resourceLoggingProjectSinkCustomizeDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error { // separate func to allow unit testing - return resourceLoggingProjectSinkCustomizeDiffFunc(d) + err := resourceLoggingProjectSinkCustomizeDiffFunc(d) + if err != nil { + return err + } + err = resourceLoggingProjectSinkUniqueWriterIdentityCustomizeDiffFunc(d) + if err != nil { + return err + } + return nil } func resourceLoggingProjectSinkCustomizeDiffFunc(diff tpgresource.TerraformResourceDiff) error { @@ -117,6 +126,20 @@ func resourceLoggingProjectSinkCustomizeDiffFunc(diff tpgresource.TerraformResou return nil } +func resourceLoggingProjectSinkUniqueWriterIdentityCustomizeDiffFunc(diff *schema.ResourceDiff) error { + if !diff.HasChange("unique_writer_identity") { + return nil + } + // taint the value of writer_identity when unique_writer_identity is updating from false -> true + if diff.Get("unique_writer_identity").(bool) { + err := diff.SetNewComputed("writer_identity") + if err != nil { + return fmt.Errorf("Error re-setting writer_identity: %s", err) + } + } + return nil +} + func resourceLoggingProjectSinkRead(d *schema.ResourceData, meta interface{}) error { config := meta.(*transport_tpg.Config) userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)