Skip to content

Commit

Permalink
Allow setting notification channel enabled to false (#3874)
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 and danawillow committed Jun 18, 2019
1 parent 17ff8af commit 596496a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Config struct {
AccessContextManagerBasePath string
CloudSchedulerBasePath string
FirestoreBasePath string
MonitoringBasePath string
RedisBasePath string
TpuBasePath string

Expand Down
3 changes: 3 additions & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func Provider() terraform.ResourceProvider {
FilestoreCustomEndpointEntryKey: FilestoreCustomEndpointEntry,
FirestoreCustomEndpointEntryKey: FirestoreCustomEndpointEntry,
KmsCustomEndpointEntryKey: KmsCustomEndpointEntry,
MonitoringCustomEndpointEntryKey: MonitoringCustomEndpointEntry,
PubsubCustomEndpointEntryKey: PubsubCustomEndpointEntry,
RedisCustomEndpointEntryKey: RedisCustomEndpointEntry,
ResourceManagerCustomEndpointEntryKey: ResourceManagerCustomEndpointEntry,
Expand Down Expand Up @@ -357,6 +358,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config.DnsBasePath = d.Get(DnsCustomEndpointEntryKey).(string)
config.FilestoreBasePath = d.Get(FilestoreCustomEndpointEntryKey).(string)
config.KmsBasePath = d.Get(KmsCustomEndpointEntryKey).(string)
config.MonitoringBasePath = d.Get(MonitoringCustomEndpointEntryKey).(string)
config.PubsubBasePath = d.Get(PubsubCustomEndpointEntryKey).(string)
config.RedisBasePath = d.Get(RedisCustomEndpointEntryKey).(string)
config.ResourceManagerBasePath = d.Get(ResourceManagerCustomEndpointEntryKey).(string)
Expand Down Expand Up @@ -409,6 +411,7 @@ func ConfigureBasePaths(c *Config) {
c.FilestoreBasePath = FilestoreDefaultBasePath
c.FirestoreBasePath = FirestoreDefaultBasePath
c.KmsBasePath = KmsDefaultBasePath
c.MonitoringBasePath = MonitoringDefaultBasePath
c.PubsubBasePath = PubsubDefaultBasePath
c.RedisBasePath = RedisDefaultBasePath
c.ResourceManagerBasePath = ResourceManagerDefaultBasePath
Expand Down
4 changes: 2 additions & 2 deletions google/resource_monitoring_notification_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func resourceMonitoringNotificationChannelCreate(d *schema.ResourceData, meta in
enabledProp, err := expandMonitoringNotificationChannelEnabled(d.Get("enabled"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enabled"); !isEmptyValue(reflect.ValueOf(enabledProp)) && (ok || !reflect.DeepEqual(v, enabledProp)) {
} else if v, ok := d.GetOkExists("enabled"); ok || !reflect.DeepEqual(v, enabledProp) {
obj["enabled"] = enabledProp
}

Expand Down Expand Up @@ -251,7 +251,7 @@ func resourceMonitoringNotificationChannelUpdate(d *schema.ResourceData, meta in
enabledProp, err := expandMonitoringNotificationChannelEnabled(d.Get("enabled"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("enabled"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enabledProp)) {
} else if v, ok := d.GetOkExists("enabled"); ok || !reflect.DeepEqual(v, enabledProp) {
obj["enabled"] = enabledProp
}

Expand Down
9 changes: 5 additions & 4 deletions google/resource_monitoring_notification_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func TestAccMonitoringNotificationChannel_update(t *testing.T) {
CheckDestroy: testAccCheckMonitoringNotificationChannelDestroy,
Steps: []resource.TestStep{
{
Config: testAccMonitoringNotificationChannel_update("email", `email_address = "fake_email@blahblah.com"`),
Config: testAccMonitoringNotificationChannel_update("email", `email_address = "fake_email@blahblah.com"`, "true"),
},
{
ResourceName: "google_monitoring_notification_channel.update",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccMonitoringNotificationChannel_update("sms", `number = "+15555379009"`),
Config: testAccMonitoringNotificationChannel_update("sms", `number = "+15555379009"`, "false"),
},
{
ResourceName: "google_monitoring_notification_channel.update",
Expand All @@ -56,15 +56,16 @@ func TestAccMonitoringNotificationChannel_update(t *testing.T) {
})
}

func testAccMonitoringNotificationChannel_update(channel, labels string) string {
func testAccMonitoringNotificationChannel_update(channel, labels, enabled string) string {
return fmt.Sprintf(`
resource "google_monitoring_notification_channel" "update" {
display_name = "IntTest Notification Channel"
type = "%s"
labels = {
%s
}
enabled = "%s"
}
`, channel, labels,
`, channel, labels, enabled,
)
}

0 comments on commit 596496a

Please sign in to comment.