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

azurerm_automation_schedule: skip set location if expiry_time exceed the upper limit as year 9999 #21886

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
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