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

Add timezone logic app recurrence #8829

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ func resourceArmLogicAppTriggerRecurrence() *schema.Resource {
Optional: true,
ValidateFunc: validation.IsRFC3339Time,
},

"time_zone": {
Type: schema.TypeString,
Optional: true,
Lucretius marked this conversation as resolved.
Show resolved Hide resolved
Default: "UTC",
ValidateFunc: validateLogicAppTriggerRecurrenceTimeZone(),
},
},
}
}
Expand All @@ -80,6 +87,11 @@ func resourceArmLogicAppTriggerRecurrenceCreateUpdate(d *schema.ResourceData, me

if v, ok := d.GetOk("start_time"); ok {
trigger["recurrence"].(map[string]interface{})["startTime"] = v.(string)

// time_zone only allowed when start_time is specified
if v, ok := d.GetOk("time_zone"); ok {
trigger["recurrence"].(map[string]interface{})["timeZone"] = v.(string)
}
}

logicAppId := d.Get("logic_app_id").(string)
Expand Down Expand Up @@ -139,6 +151,10 @@ func resourceArmLogicAppTriggerRecurrenceRead(d *schema.ResourceData, meta inter
d.Set("start_time", startTime.(string))
}

if timeZone := recurrence["timeZone"]; timeZone != nil {
d.Set("time_zone", timeZone.(string))
}

return nil
}

Expand All @@ -159,3 +175,104 @@ func resourceArmLogicAppTriggerRecurrenceDelete(d *schema.ResourceData, meta int

return nil
}

func validateLogicAppTriggerRecurrenceTimeZone() schema.SchemaValidateFunc {
// from https://support.microsoft.com/en-us/help/973627/microsoft-time-zone-index-values
timeZones := []string{
"Dateline Standard Time",
"Samoa Standard Time",
"Hawaiian Standard Time",
"Alaskan Standard Time",
"Pacific Standard Time",
"Mountain Standard Time",
"Mexico Standard Time",
"U.S. Mountain Standard Time",
"Central Standard Time",
"Canada Central Standard Time",
"Mexico Standard Time",
"Central America Standard Time",
"Eastern Standard Time",
"U.S. Eastern Standard Time",
"S.A. Pacific Standard Time",
"Atlantic Standard Time",
"S.A. Western Standard Time",
"Pacific S.A. Standard Time",
"Newfoundland and Labrador Standard Time",
"E. South America Standard Time",
"S.A. Eastern Standard Time",
"Greenland Standard Time",
"Mid-Atlantic Standard Time",
"Azores Standard Time",
"Cape Verde Standard Time",
"GMT Standard Time",
"Greenwich Standard Time",
"Central Europe Standard Time",
"Central European Standard Time",
"Romance Standard Time",
"W. Europe Standard Time",
"W. Central Africa Standard Time",
"E. Europe Standard Time",
"Egypt Standard Time",
"FLE Standard Time",
"GTB Standard Time",
"Israel Standard Time",
"South Africa Standard Time",
"Russian Standard Time",
"Arab Standard Time",
"E. Africa Standard Time",
"Arabic Standard Time",
"Iran Standard Time",
"Arabian Standard Time",
"Caucasus Standard Time",
"Transitional Islamic State of Afghanistan Standard Time",
"Ekaterinburg Standard Time",
"West Asia Standard Time",
"India Standard Time",
"Nepal Standard Time",
"Central Asia Standard Time",
"Sri Lanka Standard Time",
"N. Central Asia Standard Time",
"Myanmar Standard Time",
"S.E. Asia Standard Time",
"North Asia Standard Time",
"China Standard Time",
"Singapore Standard Time",
"Taipei Standard Time",
"W. Australia Standard Time",
"North Asia East Standard Time",
"Korea Standard Time",
"Tokyo Standard Time",
"Yakutsk Standard Time",
"A.U.S. Central Standard Time",
"Cen. Australia Standard Time",
"A.U.S. Eastern Standard Time",
"E. Australia Standard Time",
"Tasmania Standard Time",
"Vladivostok Standard Time",
"West Pacific Standard Time",
"Central Pacific Standard Time",
"Fiji Islands Standard Time",
"New Zealand Standard Time",
"Tonga Standard Time",
"Azerbaijan Standard Time",
"Middle East Standard Time",
"Jordan Standard Time",
"Central Standard Time (Mexico)",
"Mountain Standard Time (Mexico)",
"Pacific Standard Time (Mexico)",
"Namibia Standard Time",
"Georgian Standard Time",
"Central Brazilian Standard Time",
"Montevideo Standard Time",
"Armenian Standard Time",
"Venezuela Standard Time",
"Argentina Standard Time",
"Morocco Standard Time",
"Pakistan Standard Time",
"Mauritius Standard Time",
"UTC",
"Paraguay Standard Time",
"Kamchatka Standard Time",
}
return validation.StringInSlice(timeZones, false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,37 @@ func TestAccAzureRMLogicAppTriggerRecurrence_startTime(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLogicAppTriggerExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "start_time", "2020-01-01T01:02:03Z"),
resource.TestCheckResourceAttr(data.ResourceName, "time_zone", "UTC"),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMLogicAppTriggerRecurrence_startTimeWithTimeZone(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMLogicAppTriggerRecurrence_startTimeWithTimeZone(data, "2020-01-01T01:02:03Z", "U.S. Eastern Standard Time"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLogicAppTriggerExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "start_time", "2020-01-01T01:02:03Z"),
resource.TestCheckResourceAttr(data.ResourceName, "time_zone", "U.S. Eastern Standard Time"),
),
},
data.ImportStep(),
Lucretius marked this conversation as resolved.
Show resolved Hide resolved
{
Config: testAccAzureRMLogicAppTriggerRecurrence_startTimeWithTimeZone(data, "2020-01-01T01:02:03Z", "Egypt Standard Time"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMLogicAppTriggerExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "start_time", "2020-01-01T01:02:03Z"),
resource.TestCheckResourceAttr(data.ResourceName, "time_zone", "Egypt Standard Time"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -259,6 +290,34 @@ resource "azurerm_logic_app_trigger_recurrence" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, startTime)
}

func testAccAzureRMLogicAppTriggerRecurrence_startTimeWithTimeZone(data acceptance.TestData, startTime string, timeZone string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_logic_app_workflow" "test" {
name = "acctestlaw-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_logic_app_trigger_recurrence" "test" {
name = "frequency-trigger"
logic_app_id = azurerm_logic_app_workflow.test.id
frequency = "Month"
interval = 1
start_time = "%s"
time_zone = "%s"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, startTime, timeZone)
}

func testAccAzureRMLogicAppTriggerRecurrence_requiresImport(data acceptance.TestData, frequency string, interval int) string {
template := testAccAzureRMLogicAppTriggerRecurrence_basic(data, frequency, interval)
return fmt.Sprintf(`
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/logic_app_trigger_recurrence.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ The following arguments are supported:

* `start_time` - (Optional) Specifies the start date and time for this trigger in RFC3339 format: `2000-01-02T03:04:05Z`.

* `time_zone` - (Optional) Specifies the time zone for this trigger. Supported time zone options are listed [here](https://support.microsoft.com/en-us/help/973627/microsoft-time-zone-index-values)

## Attributes Reference

The following attributes are exported:
Expand Down