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

scheduler_job_collection: Renamed max_retry_interval to max_recurrence_interval to better match azure #1218

Merged
merged 3 commits into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 16 additions & 10 deletions azurerm/resource_arm_scheduler_job_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,17 @@ func resourceArmSchedulerJobCollection() *schema.Resource {
}, true),
},

//this is MaxRecurrance.Interval, property is named this as the documentation in the api states:
// Gets or sets the interval between retries.
// API documentation states the MaxRecurrance.Interval "Gets or sets the interval between retries."
// however it does appear it is the max interval allowed for recurrences
"max_retry_interval": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Deprecated: "Renamed to `max_recurrence_interval` to match azure",
ValidateFunc: validation.IntAtLeast(1), //changes depending on the frequency, unknown maximums
},

"max_recurrence_interval": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntAtLeast(1), //changes depending on the frequency, unknown maximums
Expand Down Expand Up @@ -148,7 +156,7 @@ func resourceArmSchedulerJobCollectionCreateUpdate(d *schema.ResourceData, meta

d.SetId(*collection.ID)

return resourceArmSchedulerJobCollectionPopulate(d, resourceGroup, &collection)
return resourceArmSchedulerJobCollectionRead(d, meta)
}

func resourceArmSchedulerJobCollectionRead(d *schema.ResourceData, meta interface{}) error {
Expand All @@ -175,11 +183,6 @@ func resourceArmSchedulerJobCollectionRead(d *schema.ResourceData, meta interfac
return fmt.Errorf("Error making Read request on Scheduler Job Collection %q (Resource Group %q): %+v", name, resourceGroup, err)
}

return resourceArmSchedulerJobCollectionPopulate(d, resourceGroup, &collection)
}

func resourceArmSchedulerJobCollectionPopulate(d *schema.ResourceData, resourceGroup string, collection *scheduler.JobCollectionDefinition) error {

//standard properties
d.Set("name", collection.Name)
d.Set("resource_group_name", resourceGroup)
Expand Down Expand Up @@ -248,7 +251,9 @@ func expandAzureArmSchedulerJobCollectionQuota(d *schema.ResourceData) *schedule
if v, ok := quotaBlock["max_recurrence_frequency"].(string); ok {
quota.MaxRecurrence.Frequency = scheduler.RecurrenceFrequency(v)
}
if v, ok := quotaBlock["max_retry_interval"].(int); ok {
if v, ok := quotaBlock["max_recurrence_interval"].(int); ok && v > 0 {
quota.MaxRecurrence.Interval = utils.Int32(int32(v))
} else if v, ok := quotaBlock["max_retry_interval"].(int); ok && v > 0 { //todo remove once max_retry_interval is removed
quota.MaxRecurrence.Interval = utils.Int32(int32(v))
}

Expand All @@ -271,7 +276,8 @@ func flattenAzureArmSchedulerJobCollectionQuota(quota *scheduler.JobCollectionQu
}
if recurrence := quota.MaxRecurrence; recurrence != nil {
if v := recurrence.Interval; v != nil {
quotaBlock["max_retry_interval"] = *v
quotaBlock["max_recurrence_interval"] = *v
quotaBlock["max_retry_interval"] = *v //todo remove once max_retry_interval is retired
}

quotaBlock["max_recurrence_frequency"] = string(recurrence.Frequency)
Expand Down
23 changes: 15 additions & 8 deletions azurerm/resource_arm_scheduler_job_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,47 @@ import (
func TestAccAzureRMSchedulerJobCollection_basic(t *testing.T) {
ri := acctest.RandInt()
resourceName := "azurerm_scheduler_job_collection.test"
config := testAccAzureRMSchedulerJobCollection_basic(ri, testLocation(), "")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSchedulerJobCollectionDestroy,
Steps: []resource.TestStep{
{
Config: config,
Config: testAccAzureRMSchedulerJobCollection_basic(ri, testLocation(), ""),
Check: checkAccAzureRMSchedulerJobCollection_basic(resourceName),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMSchedulerJobCollection_complete(t *testing.T) {
ri := acctest.RandInt()
resourceName := "azurerm_scheduler_job_collection.test"
preConfig := testAccAzureRMSchedulerJobCollection_basic(ri, testLocation(), "")
config := testAccAzureRMSchedulerJobCollection_complete(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMSchedulerJobCollectionDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Config: testAccAzureRMSchedulerJobCollection_basic(ri, testLocation(), ""),
Check: checkAccAzureRMSchedulerJobCollection_basic(resourceName),
},
{
Config: config,
Config: testAccAzureRMSchedulerJobCollection_complete(ri, testLocation()),
Check: checkAccAzureRMSchedulerJobCollection_complete(resourceName),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -133,7 +140,7 @@ func testAccAzureRMSchedulerJobCollection_complete(rInt int, location string) st
state = "disabled"
quota {
max_recurrence_frequency = "Hour"
max_retry_interval = 10
max_recurrence_interval = 10
max_job_count = 10
}
`)
Expand All @@ -159,7 +166,7 @@ func checkAccAzureRMSchedulerJobCollection_complete(resourceName string) resourc
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "state", string(scheduler.Disabled)),
resource.TestCheckResourceAttr(resourceName, "quota.0.max_job_count", "10"),
resource.TestCheckResourceAttr(resourceName, "quota.0.max_retry_interval", "10"),
resource.TestCheckResourceAttr(resourceName, "quota.0.max_recurrence_interval", "10"),
resource.TestCheckResourceAttr(resourceName, "quota.0.max_recurrence_frequency", "hour"),
)
}
4 changes: 2 additions & 2 deletions examples/scheduler-jobs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ resource "azurerm_scheduler_job_collection" "jobs" {
state = "enabled"

quota {
max_job_count = 5
max_retry_interval = 24
max_job_count = 5
max_recurrence_interval = 24
max_recurrence_frequency = "hour"
}
}
4 changes: 2 additions & 2 deletions website/docs/r/scheduler_job_collection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ resource "azurerm_scheduler_job_collection" "jobs" {

quota {
max_job_count = 5
max_retry_interval = 24
max_recurrence_interval = 24
max_recurrence_frequency = "hour"
}
}
Expand Down Expand Up @@ -58,7 +58,7 @@ The `quota` block supports:

* `max_recurrence_frequency` - (Required) The maximum frequency of recurrence. Possible values include: `Minute`, `Hour`, `Day`, `Week`, `Month`

* `max_retry_interval` - (Optional) The maximum interval between retries.
* `max_recurrence_interval` - (Optional) The maximum interval between recurrence.

## Attributes Reference

Expand Down