Skip to content

Commit

Permalink
Allow deleting google_logging_*_bucket_config (#5949) (#11538)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Apr 19, 2022
1 parent 791b9ef commit cb7c8df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/5949.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
logging: made `google_logging_*_bucket_config` deletable
```
22 changes: 19 additions & 3 deletions google/resource_logging_bucket_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,25 @@ func resourceLoggingBucketConfigUpdate(d *schema.ResourceData, meta interface{})
}

func resourceLoggingBucketConfigDelete(d *schema.ResourceData, meta interface{}) error {
name := d.Get("bucket_id")
for _, restrictedName := range []string{"_Required", "_Default"} {
if name == restrictedName {
log.Printf("[WARN] Default logging bucket configs cannot be deleted. Removing logging bucket config from state: %#v", d.Id())
return nil
}
}

log.Printf("[WARN] Logging bucket configs cannot be deleted. Removing logging bucket config from state: %#v", d.Id())
d.SetId("")

config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return err
}
url, err := replaceVars(d, config, fmt.Sprintf("{{LoggingBasePath}}%s", d.Id()))
if err != nil {
return err
}
if _, err := sendRequestWithTimeout(config, "DELETE", "", url, userAgent, nil, d.Timeout(schema.TimeoutUpdate)); err != nil {
return fmt.Errorf("Error deleting Logging Bucket Config %q: %s", d.Id(), err)
}
return nil
}

0 comments on commit cb7c8df

Please sign in to comment.