Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: for 1624 resource monitor timestamps are always considered to have changed #2214

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions pkg/resources/resource_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,13 @@ func UpdateResourceMonitor(d *schema.ResourceData, meta interface{}) error {
opts.Set.CreditQuota = sdk.Pointer(d.Get("credit_quota").(int))
}

if d.HasChange("frequency") {
if d.HasChange("frequency") || d.HasChange("start_timestamp") {
RichBarnes marked this conversation as resolved.
Show resolved Hide resolved
runSetStatement = true
frequency, err := sdk.FrequencyFromString(d.Get("frequency").(string))
if err != nil {
return err
}
opts.Set.Frequency = frequency
}

if d.HasChange("start_timestamp") {
runSetStatement = true
opts.Set.StartTimestamp = sdk.Pointer(d.Get("start_timestamp").(string))
}

Expand All @@ -355,10 +351,8 @@ func UpdateResourceMonitor(d *schema.ResourceData, meta interface{}) error {
}

// If ANY of the triggers changed, we collect all triggers and set them
if d.HasChange("suspend_trigger") ||
d.HasChange("suspend_triggers") ||
d.HasChange("suspend_immediate_trigger") ||
d.HasChange("suspend_immediate_triggers") ||
if d.HasChange("suspend_trigger") || d.HasChange("suspend_triggers") ||
d.HasChange("suspend_immediate_trigger") || d.HasChange("suspend_immediate_triggers") ||
d.HasChange("notify_triggers") {
runSetStatement = true
triggers := collectResourceMonitorTriggers(d)
Expand Down
48 changes: 48 additions & 0 deletions pkg/resources/resource_monitor_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,54 @@ func TestAcc_ResourceMonitor(t *testing.T) {
})
}

func TestAcc_ResourceMonitorUpdateNotifyUsers(t *testing.T) {
userEnv := os.Getenv("RESOURCE_MONITOR_NOTIFY_USERS_TEST")
if userEnv == "" {
t.Skip("Skipping ResourceMonitorUpdateNotifyUsers")
}
users := strings.Split(userEnv, ",")
name := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
config, err := resourceMonitorNotifyUsersConfig(name, users)
if err != nil {
t.Error(err)
}
checks := []resource.TestCheckFunc{
resource.TestCheckResourceAttr("snowflake_resource_monitor.test", "name", name),
resource.TestCheckResourceAttr("snowflake_resource_monitor.test", "set_for_account", "false"),
}
for _, s := range users {
checks = append(checks, resource.TestCheckTypeSetElemAttr("snowflake_resource_monitor.test", "notify_users.*", s))
}
empty := []string{}
emptyUsersConfig, err := resourceMonitorNotifyUsersConfig(name, empty)
if err != nil {
t.Error(err)
}
resource.ParallelTest(t, resource.TestCase{
Providers: acc.TestAccProviders(),
PreCheck: func() { acc.TestAccPreCheck(t) },
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: emptyUsersConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("snowflake_resource_monitor.test", "name", name),
resource.TestCheckResourceAttr("snowflake_resource_monitor.test", "set_for_account", "false"),
),
},
{
Config: config,
Check: resource.ComposeTestCheckFunc(checks...),
},
{
ResourceName: "snowflake_resource_monitor.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func resourceMonitorConfig(accName string) string {
return fmt.Sprintf(`
resource "snowflake_warehouse" "warehouse" {
Expand Down
9 changes: 8 additions & 1 deletion pkg/sdk/resource_monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"strconv"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -97,7 +98,13 @@ func (row *resourceMonitorRow) convert() (*ResourceMonitor, error) {
resourceMonitor.Frequency = *frequency
}
if row.StartTime.Valid {
resourceMonitor.StartTime = row.StartTime.String
const YYMMDDhhmm = "2006-01-02 15:04"
sfc-gh-asawicki marked this conversation as resolved.
Show resolved Hide resolved
t, err := time.Parse(time.RFC3339, row.StartTime.String)
if err != nil {
return nil, err
}
localTime := t.Local()
resourceMonitor.StartTime = localTime.Format(YYMMDDhhmm)
}
if row.EndTime.Valid {
RichBarnes marked this conversation as resolved.
Show resolved Hide resolved
resourceMonitor.EndTime = row.EndTime.String
Expand Down