Skip to content

Commit c9d3343

Browse files
Alerting Mute Timing: Mute all the time (#1300)
* Alerting Mute Timing: Mute all the time Closes #649 Currently, it panics because the block is nil * Linting
1 parent 1b9da40 commit c9d3343

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

docs/resources/mute_timing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ resource "grafana_mute_timing" "my_mute_timing" {
4646

4747
### Optional
4848

49-
- `intervals` (Block List) The time intervals at which to mute notifications. (see [below for nested schema](#nestedblock--intervals))
49+
- `intervals` (Block List) The time intervals at which to mute notifications. Use an empty block to mute all the time. (see [below for nested schema](#nestedblock--intervals))
5050
- `org_id` (String) The Organization ID. If not set, the Org ID defined in the provider block will be used.
5151

5252
### Read-Only

internal/resources/grafana/resource_alerting_mute_timing.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ This resource requires Grafana 9.1.0 or later.
4949
// Therefore TF will see delete+create instead of modify, which breaks the diff-suppression.
5050
Type: schema.TypeList,
5151
Optional: true,
52-
Description: "The time intervals at which to mute notifications.",
52+
Description: "The time intervals at which to mute notifications. Use an empty block to mute all the time.",
5353
Elem: &schema.Resource{
5454
SchemaVersion: 0,
5555
Schema: map[string]*schema.Schema{
@@ -248,7 +248,11 @@ func unpackIntervals(raw []interface{}) []*models.TimeInterval {
248248
result := make([]*models.TimeInterval, len(raw))
249249
for i, r := range raw {
250250
interval := models.TimeInterval{}
251-
block := r.(map[string]interface{})
251+
252+
block := map[string]interface{}{}
253+
if r != nil {
254+
block = r.(map[string]interface{})
255+
}
252256

253257
if vals, ok := block["times"]; ok && vals != nil {
254258
vals := vals.([]interface{})

internal/resources/grafana/resource_alerting_mute_timing_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package grafana_test
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/grafana/grafana-openapi-client-go/models"
@@ -69,3 +70,34 @@ func TestAccMuteTiming_basic(t *testing.T) {
6970
},
7071
})
7172
}
73+
74+
func TestAccMuteTiming_AllTime(t *testing.T) {
75+
testutils.CheckOSSTestsEnabled(t, ">9.0.0")
76+
77+
var mt models.MuteTimeInterval
78+
name := "My Mute Timing"
79+
80+
resource.ParallelTest(t, resource.TestCase{
81+
ProviderFactories: testutils.ProviderFactories,
82+
CheckDestroy: alertingMuteTimingCheckExists.destroyed(&mt, nil),
83+
Steps: []resource.TestStep{
84+
{
85+
Config: fmt.Sprintf(`
86+
resource "grafana_mute_timing" "my_mute_timing" {
87+
name = "%s"
88+
intervals {}
89+
}`, name),
90+
Check: resource.ComposeTestCheckFunc(
91+
alertingMuteTimingCheckExists.exists("grafana_mute_timing.my_mute_timing", &mt),
92+
resource.TestCheckResourceAttr("grafana_mute_timing.my_mute_timing", "name", name),
93+
resource.TestCheckResourceAttr("grafana_mute_timing.my_mute_timing", "intervals.0.times.#", "0"),
94+
resource.TestCheckResourceAttr("grafana_mute_timing.my_mute_timing", "intervals.0.weekdays.#", "0"),
95+
resource.TestCheckResourceAttr("grafana_mute_timing.my_mute_timing", "intervals.0.days_of_month.#", "0"),
96+
resource.TestCheckResourceAttr("grafana_mute_timing.my_mute_timing", "intervals.0.months.#", "0"),
97+
resource.TestCheckResourceAttr("grafana_mute_timing.my_mute_timing", "intervals.0.years.#", "0"),
98+
resource.TestCheckNoResourceAttr("grafana_mute_timing.my_mute_timing", "intervals.0.location"),
99+
),
100+
},
101+
},
102+
})
103+
}

0 commit comments

Comments
 (0)