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

Conversation

wuxu92
Copy link
Contributor

@wuxu92 wuxu92 commented May 23, 2023

also update DiffSuppressFunc start_time and expiry_time. or it will cause diff because the API will remove the second part in response value for these two field. like below

Terraform will perform the following actions:

# azurerm_automation_schedule.test will be updated in-place
  ~ resource "azurerm_automation_schedule" "test" {
    id  = "/subscriptions/85b3dbca-5974-4067-9669-67a141095a76/resourceGroups/acctestRG-230505111254079233/providers/Microsoft.Automation/automationAccounts/acctestAA-230515134829705044/schedules/acctestAS-230515134829705044"           
    name  = "acctestAS-230515134829705044"
 ~ start_time = "2024-04-15T18:01:00+02:00" -> "2024-04-15T18:01:15+02:00"
      # (9 unchanged attributes hidden)
 }                                                                                                                                                                                                                                   Plan: 0 to add, 1 to change, 0 to destroy.                                                                          

fixes: #21854

also suppress diff ignore second for start_time and expiry_time
Copy link
Member

@catriona-m catriona-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this @wuxu92. While this may resolve the error in the linked issue, a different approach here may be more useful. Perhaps we could avoid setting expiry_time as a timestamp in the Read in first place if it hasn't been specified?

Comment on lines 266 to 269
// fixes: https://github.com/hashicorp/terraform-provider-azurerm/issues/21854. that year 9999 may return by API
if t.In(loc).Year() <= 9999 {
t = t.In(loc)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason we can't always send and return UTC here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I think it can always send a UTC time here. but I am not sure if it will cause changes to current users if we change to UTC here.

the timezone logic introduced in this PR if @catriona-m has any context about this logic and can we change the loc to UTC safely?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we have a user-specified value here, we would still need it to be in the timezone they have specified too I think, so we do need to check if it's the default value from the api or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tombuildsstuff Is this PR acceptable to resolve the issue, or do you prefer @catriona-m's suggestion to avoid setting expiry_time as a timestamp in the Read in first place if it hasn't been specified? both options seem viable to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually we don't need to do either approach, we can instead set the raw string value rather than parsing and then setting the date time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should work too. I'll update it that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR updated and added a new acc test for it:

--- PASS: TestAccAutomationSchedule_oneTime_basic (158.45s)
--- PASS: TestAccAutomationSchedule_expiryTimeOfEuropeTimeZone (195.06s)
--- PASS: TestAccAutomationSchedule_requiresImport (166.47s)
--- PASS: TestAccAutomationSchedule_oneTime_complete (95.21s)
--- PASS: TestAccAutomationSchedule_oneTime_update (126.64s)
--- PASS: TestAccAutomationSchedule_hourly (91.86s)
--- PASS: TestAccAutomationSchedule_daily (94.86s)
--- PASS: TestAccAutomationSchedule_weekly (94.92s)
--- PASS: TestAccAutomationSchedule_monthly (154.84s)
--- PASS: TestAccAutomationSchedule_weekly_advanced (94.75s)
--- PASS: TestAccAutomationSchedule_monthly_advanced_by_day (92.64s)
--- PASS: TestAccAutomationSchedule_monthly_advanced_by_week_day (93.93s)

@wuxu92
Copy link
Contributor Author

wuxu92 commented May 29, 2023

@catriona-m the API will reponse expiry_time as 9999-12-31 23:59:59 if it's not specified in request. do you mean we should not set expiry_time in the Read if it's not specify in the terraform cofiguration?

@stephybun stephybun added the bug label Jun 26, 2023
Copy link
Member

@stephybun stephybun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wuxu92 LGTM 🌮

@stephybun stephybun merged commit f9c83f9 into hashicorp:main Jun 26, 2023
13 checks passed
@github-actions github-actions bot added this to the v3.63.0 milestone Jun 26, 2023
stephybun added a commit that referenced this pull request Jun 26, 2023
@wuxu92 wuxu92 deleted the schedule/tz branch June 27, 2023 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

azure_automation_schedule fails on successive applies for timezones with positive UTC offset
4 participants