Skip to content

Commit

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

* update error handling

---------

Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
edwardmedia and Edward Sun authored Dec 11, 2023
1 parent 42bac03 commit 135dfa3
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,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 {
Expand All @@ -115,6 +124,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)
Expand Down

0 comments on commit 135dfa3

Please sign in to comment.