hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.53k stars 4.6k forks source link

azurerm_automation_schedule altering start time based on timezone #17641

Open maistro-mw opened 2 years ago

maistro-mw commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.2

AzureRM Provider Version

3.13.0

Affected Resource(s)/Data Source(s)

azurerm_automation_schedule

Terraform Configuration Files

terraform {

  required_version = ">=1.2"

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.3"
    }
    local = {
      source = "hashicorp/local"
    }
  }

  backend "azurerm" {
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_automation_schedule" "schedule" {
  name                    = "PowerBI-Embedded-Suspend"
  resource_group_name     = "Resource-Group"
  automation_account_name = "Automation-Account"
  frequency               = Week
  interval                = 1
  start_time              = "${substr(timeadd(timestamp(), "24h"), 0, 10)}T22:00:00Z"
  timezone                = "Europe/London"
  week_days               = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
  description             = "Pause the PowerBI Embedded instance"
}

Debug Output/Panic Output

No debug logs

Expected Behaviour

The schedule is entered as T22:00Z with timezone Europe/London, so I expect the schedule to be created for 10pm in the UK timezone (which currently is summer time so UTC+1). The expected behaviour (which would occur is manually creating in Azure) would be for the schedule to run at 10pm - observing the summer time changes - so it is always at 10pm.

Actual Behaviour

The schedule is created as 11pm in the UK timezone. The apply operation is adding the +1 but keeping the timezone setting. This means the schedule will run at 11pm in the summer time but if I were to run the apply again out of summer time it would reset to 10pm.

Steps to Reproduce

No response

Important Factoids

No response

References

No response

wuxu92 commented 2 years ago

Hi, @maistro-mw thanks for your feedback. i believe the schedule resource's start_time property doesn't auto adjust the timezone part by the timezone property of the resource. so you should use

start_time              = "${substr(timeadd(timestamp(), "24h"), 0, 10)}T22:00:00+01:00"

for London summer time.

as for summertime, there is a gap between Terraform and the azure portal, terraform does not auto transfer the timezone so you have to change the summer time zone manually. I think it should be fixed by Terraform team, and I'll report it to the team.

maistro-mw commented 2 years ago

Hi @wuxu92 thanks for your reply. I tried using +01:00 instead of Z but that still put the wrong time in unless I left the timezone property blank (thus defaulting to UTC). This removed the Timezone setting in the Azure resource which meant it would not cope with the summer time changes. It would be good if this could be addressed by the Terraform team - prior to that I will manually adjust my definition to result in the correct time being deployed.

wuxu92 commented 2 years ago

prior

i have tried with this config

start_time              = "${substr(timeadd(timestamp(), "24h"), 0, 10)}T21:00:00+01:00" 
timezone                = "Europe/London"     

and the resource start_time looks fine

image

maistro-mw commented 2 years ago

OK, thanks. I will try again - I was not getting the same result

maistro-mw commented 2 years ago

@wuxu92 Thanks - that appears to get the correct time in now. Will see what happens when summer time ends as I guess I will need to change to +00:00 in my terraform config

DMunkov commented 1 year ago

I think the best option here would be to completely ignore time-offset in favour of timezone if specified.

simaotwx commented 1 year ago

There is a solution for this on SO: https://stackoverflow.com/questions/61762648/terraform-azurerm-schedule-start-time-always-resets-on-new-deploys

MichalSino commented 10 months ago

Hi @wuxu92,

I have the same problem. I'm trying to set schedule in local time (fixed) start_time = "2023-11-23T18:20:31Z" timezone = "Europe/Warsaw"

and in portal I have: image

When I do it in portal I'm entering local time, so I think the is some calculation of start_time and timezone.

Can it be fixed?

wuxu92 commented 10 months ago

Hi @MichalSino , This is because the provider will process the start_time to location of time_zone, as "2023-11-23T18:20:31Z" will be processed as 2023-11-23T19:20:31+01:00. So if you want set it in local time, you can use

start_time     = "2023-11-23T18:20:31+01:00"
timezone       = "Europe/Warsaw"
MichalSino commented 10 months ago

Ok, I understand.

But that's why I ask to possibility of changing it, because I need to remember if there is summer time or winter time. If it were not be calculated and writed the same as I entered, it would be better. Do you know it is done in api side or in provider side?

akmalharith commented 9 months ago

I don't really understand why accept tz database timezone input but actually require a tz-aware RFC3339 input in start_time..

vstoykov commented 2 months ago

I don't really understand why accept tz database timezone input but actually require a tz-aware RFC3339 input in start_time..

This is also confusing me. What is the point of the timezone then???

mpjtaylor commented 1 month ago

Agreed, if you do it in the portal the time is set correctly with the timezone, but via terraform you get a totally different time when using timezone and start_time.