diff --git a/internal/services/automation/automation_schedule_resource.go b/internal/services/automation/automation_schedule_resource.go index e91a83971f30..906d3c432e79 100644 --- a/internal/services/automation/automation_schedule_resource.go +++ b/internal/services/automation/automation_schedule_resource.go @@ -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 }, @@ -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, }, @@ -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 @@ -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) diff --git a/internal/services/automation/automation_schedule_resource_test.go b/internal/services/automation/automation_schedule_resource_test.go index 4bd3d91698ad..8040780e30cd 100644 --- a/internal/services/automation/automation_schedule_resource_test.go +++ b/internal/services/automation/automation_schedule_resource_test.go @@ -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{} @@ -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