Skip to content

Commit

Permalink
r/monitor_autoscale_setting: porting the changes over from #2806
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Jan 31, 2019
1 parent ac23da1 commit 85593b5
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 6 deletions.
6 changes: 3 additions & 3 deletions azurerm/resource_arm_monitor_autoscale_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ func resourceArmMonitorAutoScaleSetting() *schema.Resource {
"minimum": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(1, 40),
ValidateFunc: validation.IntBetween(0, 1000),
},
"maximum": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(1, 40),
ValidateFunc: validation.IntBetween(0, 1000),
},
"default": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntBetween(1, 40),
ValidateFunc: validation.IntBetween(0, 1000),
},
},
},
Expand Down
93 changes: 93 additions & 0 deletions azurerm/resource_arm_monitor_autoscale_setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,54 @@ func TestAccAzureRMMonitorAutoScaleSetting_multipleProfiles(t *testing.T) {
})
}

func TestAccAzureRMMonitorAutoScaleSetting_update(t *testing.T) {
resourceName := "azurerm_monitor_autoscale_setting.test"
ri := tf.AccRandTimeInt()
rs := acctest.RandString(6)
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMMonitorAutoScaleSettingDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMMonitorAutoScaleSetting_capacity(ri, rs, location, 1, 3, 2),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMMonitorAutoScaleSettingExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "profile.#", "1"),
resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.minimum", "1"),
resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.maximum", "2"),
resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.default", "4"),
),
},
{
Config: testAccAzureRMMonitorAutoScaleSetting_capacity(ri, rs, location, 2, 4, 3),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMMonitorAutoScaleSettingExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "profile.#", "1"),
resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.minimum", "2"),
resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.maximum", "4"),
resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.default", "3"),
),
},
{
Config: testAccAzureRMMonitorAutoScaleSetting_capacity(ri, rs, location, 2, 45, 3),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMMonitorAutoScaleSettingExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "profile.#", "1"),
resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.minimum", "2"),
resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.maximum", "45"),
resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.default", "3"),
),
},
},
})
}

func TestAccAzureRMMonitorAutoScaleSetting_multipleRules(t *testing.T) {
resourceName := "azurerm_monitor_autoscale_setting.test"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -511,6 +559,51 @@ resource "azurerm_monitor_autoscale_setting" "test" {
`, template, rInt)
}

func testAccAzureRMMonitorAutoScaleSetting_capacity(rInt int, rString string, location string, min int, max int, defaultVal int) string {
template := testAccAzureRMMonitorAutoScaleSetting_template(rInt, rString, location)
return fmt.Sprintf(`
%s
resource "azurerm_monitor_autoscale_setting" "test" {
name = "acctestautoscale-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
target_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
enabled = false
profile {
name = "metricRules"
capacity {
default = %d
minimum = %d
maximum = %d
}
rule {
metric_trigger {
metric_name = "Percentage CPU"
metric_resource_id = "${azurerm_virtual_machine_scale_set.test.id}"
time_grain = "PT1M"
statistic = "Average"
time_window = "PT5M"
time_aggregation = "Average"
operator = "GreaterThan"
threshold = 75
}
scale_action {
direction = "Increase"
type = "ChangeCount"
value = 1
cooldown = "PT1M"
}
}
}
}
`, template, rInt, defaultVal, min, max)
}

func testAccAzureRMMonitorAutoScaleSetting_multipleRules(rInt int, rString string, location string) string {
template := testAccAzureRMMonitorAutoScaleSetting_template(rInt, rString, location)
return fmt.Sprintf(`
Expand Down
6 changes: 3 additions & 3 deletions website/docs/r/monitor_autoscale_setting.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ A `profile` block supports the following:

A `capacity` block supports the following:

* `default` - (Required) The number of instances that are available for scaling if metrics are not available for evaluation. The default is only used if the current instance count is lower than the default.
* `default` - (Required) The number of instances that are available for scaling if metrics are not available for evaluation. The default is only used if the current instance count is lower than the default. Valid values are between `0` and `1000`.

* `maximum` - (Required) The maximum number of instances for this resource. Valid values are between `1` and `40`.
* `maximum` - (Required) The maximum number of instances for this resource. Valid values are between `0` and `1000`.

-> **NOTE:** The maximum number of instances is also limited by the amount of Cores available in the subscription.

* `minimum` - (Required) The minimum number of instances for this resource. Valid values are between `1` and `40`.
* `minimum` - (Required) The minimum number of instances for this resource. Valid values are between `0` and `1000`.

---

Expand Down

0 comments on commit 85593b5

Please sign in to comment.