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_data_factory_trigger_schedule supports schedule and description #13243

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -53,6 +53,86 @@ func resourceDataFactoryTriggerSchedule() *pluginsdk.Resource {
ValidateFunc: validate.DataFactoryName(),
},

"description": {
stephybun marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"schedule": {
Type: pluginsdk.TypeList,
Optional: true,
MinItems: 1,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"days_of_month": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeInt,
ValidateFunc: validation.Any(
validation.IntBetween(1, 31),
validation.IntBetween(-31, -1),
),
},
},

"days_of_week": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 7,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.IsDayOfTheWeek(false),
},
},

"hours": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeInt,
ValidateFunc: validation.IntBetween(0, 24),
},
},

"minutes": {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeInt,
ValidateFunc: validation.IntBetween(0, 60),
},
},

"monthly_occurrence": {
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeList,
Optional: true,
MinItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"day": {
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.IsDayOfTheWeek(false),
},

"occurrence": {
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved
Type: pluginsdk.TypeInt,
Optional: true,
ValidateFunc: validation.Any(
validation.IntBetween(1, 5),
validation.IntBetween(-5, -1),
),
},
},
},
},
},
},
},

// This time can only be represented in UTC.
// An issue has been filed in the SDK for the timezone attribute that doesn't seem to work
// https://github.com/Azure/azure-sdk-for-go/issues/6244
Expand Down Expand Up @@ -148,6 +228,7 @@ func resourceDataFactoryTriggerScheduleCreateUpdate(d *pluginsdk.ResourceData, m
Recurrence: &datafactory.ScheduleTriggerRecurrence{
Frequency: datafactory.RecurrenceFrequency(d.Get("frequency").(string)),
Interval: utils.Int32(int32(d.Get("interval").(int))),
Schedule: expandDataFactorySchedule(d.Get("schedule").([]interface{})),
},
}

Expand Down Expand Up @@ -176,6 +257,7 @@ func resourceDataFactoryTriggerScheduleCreateUpdate(d *pluginsdk.ResourceData, m
Parameters: d.Get("pipeline_parameters").(map[string]interface{}),
},
},
Description: utils.String(d.Get("description").(string)),
}

if v, ok := d.GetOk("annotations"); ok {
Expand Down Expand Up @@ -246,6 +328,10 @@ func resourceDataFactoryTriggerScheduleRead(d *pluginsdk.ResourceData, meta inte
}
d.Set("frequency", recurrence.Frequency)
d.Set("interval", recurrence.Interval)

if schedule := recurrence.Schedule; schedule != nil {
d.Set("schedule", flattenDataFactorySchedule(schedule))
}
}

if pipelines := scheduleTriggerProps.Pipelines; pipelines != nil {
Expand All @@ -262,6 +348,8 @@ func resourceDataFactoryTriggerScheduleRead(d *pluginsdk.ResourceData, meta inte
if err := d.Set("annotations", annotations); err != nil {
return fmt.Errorf("setting `annotations`: %+v", err)
}

d.Set("description", scheduleTriggerProps.Description)
}

return nil
Expand All @@ -285,3 +373,65 @@ func resourceDataFactoryTriggerScheduleDelete(d *pluginsdk.ResourceData, meta in

return nil
}

func expandDataFactorySchedule(input []interface{}) *datafactory.RecurrenceSchedule {
if len(input) == 0 {
return nil
}
value := input[0].(map[string]interface{})
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved
weekDays := make([]datafactory.DaysOfWeek, 0)
for _, v := range value["days_of_week"].([]interface{}) {
weekDays = append(weekDays, datafactory.DaysOfWeek(v.(string)))
}
monthlyOccurrences := make([]datafactory.RecurrenceScheduleOccurrence, 0)
for _, v := range value["monthly_occurrence"].([]interface{}) {
value := v.(map[string]interface{})
monthlyOccurrences = append(monthlyOccurrences, datafactory.RecurrenceScheduleOccurrence{
Day: datafactory.DayOfWeek(value["day"].(string)),
Occurrence: utils.Int32(int32(value["occurrence"].(int))),
})
}
return &datafactory.RecurrenceSchedule{
Minutes: utils.ExpandInt32Slice(value["minutes"].([]interface{})),
Hours: utils.ExpandInt32Slice(value["hours"].([]interface{})),
WeekDays: &weekDays,
MonthDays: utils.ExpandInt32Slice(value["days_of_month"].([]interface{})),
MonthlyOccurrences: &monthlyOccurrences,
}
}

func flattenDataFactorySchedule(schedule *datafactory.RecurrenceSchedule) []interface{} {
if schedule == nil {
return []interface{}{}
}
value := make(map[string]interface{})
if schedule.Minutes != nil {
value["minutes"] = utils.FlattenInt32Slice(schedule.Minutes)
}
if schedule.Hours != nil {
value["hours"] = utils.FlattenInt32Slice(schedule.Hours)
}
if schedule.WeekDays != nil {
weekDays := make([]interface{}, 0)
for _, v := range *schedule.WeekDays {
weekDays = append(weekDays, string(v))
}
value["days_of_week"] = weekDays
}
if schedule.MonthDays != nil {
value["days_of_month"] = utils.FlattenInt32Slice(schedule.MonthDays)
}
if schedule.MonthlyOccurrences != nil {
monthlyOccurrences := make([]interface{}, 0)
for _, v := range *schedule.MonthlyOccurrences {
occurrence := make(map[string]interface{})
occurrence["day"] = string(v.Day)
if v.Occurrence != nil {
occurrence["occurrence"] = *v.Occurrence
}
monthlyOccurrences = append(monthlyOccurrences, occurrence)
}
value["monthly_occurrence"] = monthlyOccurrences
}
return []interface{}{value}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ func TestAccDataFactoryTriggerSchedule_complete(t *testing.T) {
})
}

func TestAccDataFactoryTriggerSchedule_schedule(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_data_factory_trigger_schedule", "test")
r := TriggerScheduleResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.schedule(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (t TriggerScheduleResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := azure.ParseAzureResourceID(state.ID)
if err != nil {
Expand Down Expand Up @@ -143,7 +158,7 @@ resource "azurerm_data_factory_trigger_schedule" "test" {
data_factory_name = azurerm_data_factory.test.name
resource_group_name = azurerm_resource_group.test.name
pipeline_name = azurerm_data_factory_pipeline.test.name
description = "test"
pipeline_parameters = azurerm_data_factory_pipeline.test.parameters
annotations = ["test5"]
frequency = "Day"
Expand All @@ -152,3 +167,52 @@ resource "azurerm_data_factory_trigger_schedule" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, endTime)
}

func (TriggerScheduleResource) schedule(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-df-%d"
location = "%s"
}
resource "azurerm_data_factory" "test" {
name = "acctestdf%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_data_factory_pipeline" "test" {
name = "acctest%d"
resource_group_name = azurerm_resource_group.test.name
data_factory_name = azurerm_data_factory.test.name
parameters = {
test = "testparameter"
}
}
resource "azurerm_data_factory_trigger_schedule" "test" {
name = "acctestdf%d"
data_factory_name = azurerm_data_factory.test.name
resource_group_name = azurerm_resource_group.test.name
pipeline_name = azurerm_data_factory_pipeline.test.name
annotations = ["test1", "test2", "test3"]
schedule {
days_of_month = [1, 2, 3]
days_of_week = ["Monday", "Tuesday"]
hours = [0, 12, 24]
minutes = [0, 30, 60]
monthly_occurrence {
day = "Monday"
occurrence = 1
}
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
28 changes: 27 additions & 1 deletion website/docs/r/data_factory_trigger_schedule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,44 @@ The following arguments are supported:

* `pipeline_name` - (Required) The Data Factory Pipeline name that the trigger will act on.

* `description` - (Optional) The Schedule Trigger's description.

* `schedule` - (Optional) The recurrence schedule for the trigger. A trigger with a specified frequency value alters its recurrence based on a recurrence schedule. The schedule property contains modifications for the recurrence that are based on minutes, hours, weekdays, month days, and week number. A `schedule` block as documented below.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

* `start_time` - (Optional) The time the Schedule Trigger will start. This defaults to the current time. The time will be represented in UTC.

* `end_time` - (Optional) The time the Schedule Trigger should end. The time will be represented in UTC.

* `interval` - (Optional) The interval for how often the trigger occurs. This defaults to 1.

* `frequency` - (Optional) The trigger freqency. Valid values include `Minute`, `Hour`, `Day`, `Week`, `Month`. Defaults to `Minute`.
* `frequency` - (Optional) The trigger frequency. Valid values include `Minute`, `Hour`, `Day`, `Week`, `Month`. Defaults to `Minute`.

* `pipeline_parameters` - (Optional) The pipeline parameters that the trigger will act upon.

* `annotations` - (Optional) List of tags that can be used for describing the Data Factory Schedule Trigger.

---

`schedule` supports the following:
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

* `days_of_month` - (Optional) Day of the month on which the trigger runs. The value can be specified with a monthly frequency only.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

* `days_of_week` - (Optional) Days of the week the trigger runs. The value can be specified only with a weekly frequency.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

* `hours` - (Optional) Hours of the day at which the trigger runs.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

* `minutes` - (Optional) Minutes of the hour at which the trigger runs.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

* `monthly_occurrence` - (Optional) Days of the month on which the trigger runs. The value can be specified with a monthly frequency only. A `monthly_occurrence` block as documented below.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

---

`monthly_occurrence` supports the following:
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

* `day` - (Required) The day of the week on which the trigger runs. For example, a `monthly_occurrence` property with a day value of `Sunday` means every Sunday of the month.

* `occurrence` - (Optional) The occurrence of the specified day during the month. For example, a `monthly_occurrence` property with day and occurrence values of `Sunday, -1` means the last Sunday of the month.
ms-henglu marked this conversation as resolved.
Show resolved Hide resolved

## Attributes Reference

The following attributes are exported:
Expand Down