diff --git a/.changelog/5949.txt b/.changelog/5949.txt new file mode 100644 index 00000000000..bd930810443 --- /dev/null +++ b/.changelog/5949.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +logging: made `google_logging_*_bucket_config` deletable +``` diff --git a/google/resource_logging_bucket_config.go b/google/resource_logging_bucket_config.go index 01dec3590e8..02de26da4f3 100644 --- a/google/resource_logging_bucket_config.go +++ b/google/resource_logging_bucket_config.go @@ -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 }