Skip to content

Commit

Permalink
taint writer_identity (hashicorp#9561) (hashicorp#16776)
Browse files Browse the repository at this point in the history
* taint writer_identity

* update error handling

---------


[upstream:135dfa3e51199e0bb43be5e9e782c2edfd4f88fd]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Dec 11, 2023
1 parent 38d4ab2 commit b6532c0
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/9561.txt
Original file line number Diff line number Diff line change
@@ -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`
```
27 changes: 25 additions & 2 deletions google/services/logging/resource_logging_project_sink.go
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b6532c0

Please sign in to comment.