Skip to content

Commit f866faa

Browse files
Add force delete for notifiaction channel (#6474) (#12414)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent ddc5480 commit f866faa

5 files changed

+24
-2
lines changed

.changelog/6474.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
monitoring: added `force_delete` field to `google_monitoring_notification_channel` resource
3+
```

google/resource_monitoring_notification_channel.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ The [CHANNEL_ID] is automatically assigned by the server on creation.`,
145145
Computed: true,
146146
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.`,
147147
},
148+
"force_delete": {
149+
Type: schema.TypeBool,
150+
Optional: true,
151+
Default: false,
152+
},
148153
"project": {
149154
Type: schema.TypeString,
150155
Optional: true,
@@ -312,6 +317,12 @@ func resourceMonitoringNotificationChannelRead(d *schema.ResourceData, meta inte
312317
return nil
313318
}
314319

320+
// Explicitly set virtual fields to default values if unset
321+
if _, ok := d.GetOkExists("force_delete"); !ok {
322+
if err := d.Set("force_delete", false); err != nil {
323+
return fmt.Errorf("Error setting force_delete: %s", err)
324+
}
325+
}
315326
if err := d.Set("project", project); err != nil {
316327
return fmt.Errorf("Error reading NotificationChannel: %s", err)
317328
}
@@ -454,7 +465,7 @@ func resourceMonitoringNotificationChannelDelete(d *schema.ResourceData, meta in
454465
mutexKV.Lock(lockName)
455466
defer mutexKV.Unlock(lockName)
456467

457-
url, err := replaceVars(d, config, "{{MonitoringBasePath}}v3/{{name}}")
468+
url, err := replaceVars(d, config, "{{MonitoringBasePath}}v3/{{name}}?force={{force_delete}}")
458469
if err != nil {
459470
return err
460471
}

google/resource_monitoring_notification_channel_generated_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ resource "google_monitoring_notification_channel" "basic" {
5656
labels = {
5757
email_address = "[email protected]"
5858
}
59+
force_delete = false
5960
}
6061
`, context)
6162
}

google/resource_monitoring_notification_channel_sweeper_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func testSweepMonitoringNotificationChannel(region string) error {
9999
continue
100100
}
101101

102-
deleteTemplate := "https://monitoring.googleapis.com/v3/{{name}}"
102+
deleteTemplate := "https://monitoring.googleapis.com/v3/{{name}}?force={{force_delete}}"
103103
deleteUrl, err := replaceVars(d, config, deleteTemplate)
104104
if err != nil {
105105
log.Printf("[INFO][SWEEPER_LOG] error preparing delete url: %s", err)

website/docs/r/monitoring_notification_channel.html.markdown

+7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ resource "google_monitoring_notification_channel" "basic" {
6464
labels = {
6565
email_address = "[email protected]"
6666
}
67+
force_delete = false
6768
}
6869
```
6970
## Example Usage - Notification Channel Sensitive
@@ -133,6 +134,12 @@ The following arguments are supported:
133134
* `project` - (Optional) The ID of the project in which the resource belongs.
134135
If it is not provided, the provider project is used.
135136

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

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

0 commit comments

Comments
 (0)