Skip to content

Commit

Permalink
Add force delete for notifiaction channel (#6474) (#4638)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Aug 29, 2022
1 parent ab8cb27 commit d3c4e81
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/6474.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
monitoring: added `force_delete` field to `google_monitoring_notification_channel` resource
```
13 changes: 12 additions & 1 deletion google-beta/resource_monitoring_notification_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ The [CHANNEL_ID] is automatically assigned by the server on creation.`,
Computed: true,
Description: `Indicates whether this channel has been verified or not. On a ListNotificationChannels or GetNotificationChannel operation, this field is expected to be populated.If the value is UNVERIFIED, then it indicates that the channel is non-functioning (it both requires verification and lacks verification); otherwise, it is assumed that the channel works.If the channel is neither VERIFIED nor UNVERIFIED, it implies that the channel is of a type that does not require verification or that this specific channel has been exempted from verification because it was created prior to verification being required for channels of this type.This field cannot be modified using a standard UpdateNotificationChannel operation. To change the value of this field, you must call VerifyNotificationChannel.`,
},
"force_delete": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"project": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -312,6 +317,12 @@ func resourceMonitoringNotificationChannelRead(d *schema.ResourceData, meta inte
return nil
}

// Explicitly set virtual fields to default values if unset
if _, ok := d.GetOkExists("force_delete"); !ok {
if err := d.Set("force_delete", false); err != nil {
return fmt.Errorf("Error setting force_delete: %s", err)
}
}
if err := d.Set("project", project); err != nil {
return fmt.Errorf("Error reading NotificationChannel: %s", err)
}
Expand Down Expand Up @@ -454,7 +465,7 @@ func resourceMonitoringNotificationChannelDelete(d *schema.ResourceData, meta in
mutexKV.Lock(lockName)
defer mutexKV.Unlock(lockName)

url, err := replaceVars(d, config, "{{MonitoringBasePath}}v3/{{name}}")
url, err := replaceVars(d, config, "{{MonitoringBasePath}}v3/{{name}}?force={{force_delete}}")
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ resource "google_monitoring_notification_channel" "basic" {
labels = {
email_address = "fake_email@blahblah.com"
}
force_delete = false
}
`, context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func testSweepMonitoringNotificationChannel(region string) error {
continue
}

deleteTemplate := "https://monitoring.googleapis.com/v3/{{name}}"
deleteTemplate := "https://monitoring.googleapis.com/v3/{{name}}?force={{force_delete}}"
deleteUrl, err := replaceVars(d, config, deleteTemplate)
if err != nil {
log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err)
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/monitoring_notification_channel.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ resource "google_monitoring_notification_channel" "basic" {
labels = {
email_address = "fake_email@blahblah.com"
}
force_delete = false
}
```
## Example Usage - Notification Channel Sensitive
Expand Down Expand Up @@ -133,6 +134,12 @@ The following arguments are supported:
* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

* `force_delete` - (Optional) If true, the notification channel will be deleted regardless
of its use in alert policies (the policies will be updated
to remove the channel). If false, channels that are still
referenced by an existing alerting policy will fail to be
deleted in a delete operation.


<a name="nested_sensitive_labels"></a>The `sensitive_labels` block supports:

Expand Down

0 comments on commit d3c4e81

Please sign in to comment.