Skip to content

Commit

Permalink
azurerm_automation_schedule: skip set location if expiry_time excee…
Browse files Browse the repository at this point in the history
…d the upper limit as year 9999 (#21886)

* skip set location if expiry_time exceed the upper limit as year 9999
also suppress diff ignore second for start_time and expiry_time

* use raw string for schedule expiry time, and add a new acc test

* golangci import sort
  • Loading branch information
wuxu92 authored Jun 26, 2023
1 parent 5206eec commit f9c83f9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
14 changes: 4 additions & 10 deletions internal/services/automation/automation_schedule_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func resourceAutomationSchedule() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
DiffSuppressFunc: suppress.RFC3339Time,
DiffSuppressFunc: suppress.RFC3339MinuteTime,
ValidateFunc: validation.IsRFC3339Time,
// defaults to now + 7 minutes in create function if not set
},
Expand All @@ -95,7 +95,7 @@ func resourceAutomationSchedule() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true, // same as start time when OneTime, ridiculous value when recurring: "9999-12-31T15:59:00-08:00"
DiffSuppressFunc: suppress.CaseDifference,
DiffSuppressFunc: suppress.RFC3339MinuteTime,
ValidateFunc: validation.IsRFC3339Time,
},

Expand Down Expand Up @@ -262,8 +262,7 @@ func resourceAutomationScheduleCreateUpdate(d *pluginsdk.ResourceData, meta inte
}

if v, ok := d.GetOk("expiry_time"); ok {
t, _ := time.Parse(time.RFC3339, v.(string)) // should be validated by the schema
parameters.Properties.SetExpiryTimeAsTime(t.In(loc))
parameters.Properties.ExpiryTime = pointer.To(v.(string))
}

// only pay attention to interval if frequency is not OneTime, and default it to 1 if not set
Expand Down Expand Up @@ -324,12 +323,7 @@ func resourceAutomationScheduleRead(d *pluginsdk.ResourceData, meta interface{})
return err
}
d.Set("start_time", startTime.Format(time.RFC3339))

expiryTime, err := props.GetExpiryTimeAsTime()
if err != nil {
return err
}
d.Set("expiry_time", expiryTime.Format(time.RFC3339))
d.Set("expiry_time", pointer.From(props.ExpiryTime))

if v := props.Interval; v != nil {
d.Set("interval", v)
Expand Down
41 changes: 41 additions & 0 deletions internal/services/automation/automation_schedule_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@ func TestAccAutomationSchedule_oneTime_basic(t *testing.T) {
})
}

// test for: https://github.com/hashicorp/terraform-provider-azurerm/issues/21854
func TestAccAutomationSchedule_expiryTimeOfEuropeTimeZone(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test")
r := AutomationScheduleResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.expiryTimeOfEuropeTimeZone(data, "foo"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.expiryTimeOfEuropeTimeZone(data, "bar"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccAutomationSchedule_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test")
r := AutomationScheduleResource{}
Expand Down Expand Up @@ -245,6 +268,24 @@ resource "azurerm_automation_schedule" "test" {
`, AutomationScheduleResource{}.template(data), data.RandomInteger)
}

func (a AutomationScheduleResource) expiryTimeOfEuropeTimeZone(data acceptance.TestData, desc string) string {
return fmt.Sprintf(`
%s
resource "azurerm_automation_schedule" "test" {
name = "acctestAS-%d"
resource_group_name = azurerm_resource_group.test.name
automation_account_name = azurerm_automation_account.test.name
frequency = "Week"
interval = 1
timezone = "Europe/Amsterdam"
start_time = "2026-04-15T18:01:15+02:00"
description = "%s"
week_days = ["Monday"]
}
`, a.template(data), data.RandomInteger, desc)
}

func (AutomationScheduleResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down

0 comments on commit f9c83f9

Please sign in to comment.