aws_autoscaling_policy: Add tests for StepScaling policies.
This commit is contained in:
parent
305a450239
commit
2cf6afa6c1
|
@ -21,9 +21,20 @@ func TestAccAWSAutoscalingPolicy_basic(t *testing.T) {
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSAutoscalingPolicyConfig,
|
Config: testAccAWSAutoscalingPolicyConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckScalingPolicyExists("aws_autoscaling_policy.foobar", &policy),
|
testAccCheckScalingPolicyExists("aws_autoscaling_policy.foobar_simple", &policy),
|
||||||
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar", "adjustment_type", "ChangeInCapacity"),
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "adjustment_type", "ChangeInCapacity"),
|
||||||
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar", "cooldown", "300"),
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "policy_type", "SimpleScaling"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "cooldown", "300"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "name", "foobar_simple"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "scaling_adjustment", "2"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_simple", "autoscaling_group_name", "terraform-test-foobar5"),
|
||||||
|
testAccCheckScalingPolicyExists("aws_autoscaling_policy.foobar_step", &policy),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "adjustment_type", "ChangeInCapacity"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "policy_type", "StepScaling"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "name", "foobar_step"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "metric_aggregation_type", "Minimum"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "estimated_instance_warmup", "200"),
|
||||||
|
resource.TestCheckResourceAttr("aws_autoscaling_policy.foobar_step", "autoscaling_group_name", "terraform-test-foobar5"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -104,11 +115,25 @@ resource "aws_autoscaling_group" "foobar" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_autoscaling_policy" "foobar" {
|
resource "aws_autoscaling_policy" "foobar_simple" {
|
||||||
name = "foobar"
|
name = "foobar_simple"
|
||||||
scaling_adjustment = 4
|
|
||||||
adjustment_type = "ChangeInCapacity"
|
adjustment_type = "ChangeInCapacity"
|
||||||
cooldown = 300
|
cooldown = 300
|
||||||
|
policy_type = "SimpleScaling"
|
||||||
|
scaling_adjustment = 2
|
||||||
|
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_autoscaling_policy" "foobar_step" {
|
||||||
|
name = "foobar_step"
|
||||||
|
adjustment_type = "ChangeInCapacity"
|
||||||
|
policy_type = "StepScaling"
|
||||||
|
estimated_instance_warmup = 200
|
||||||
|
metric_aggregation_type = "Minimum"
|
||||||
|
step_adjustment {
|
||||||
|
scaling_adjustment = 1
|
||||||
|
metric_interval_lower_bound = 2.0
|
||||||
|
}
|
||||||
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
|
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
|
@ -526,6 +526,33 @@ func TestexpandElasticacheParameters(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExpandStepAdjustments(t *testing.T) {
|
||||||
|
expanded := []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"metric_interval_lower_bound": "1.0",
|
||||||
|
"metric_interval_upper_bound": "2.0",
|
||||||
|
"scaling_adjustment": 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
parameters, err := expandStepAdjustments(expanded)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("bad: %#v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := &autoscaling.StepAdjustment{
|
||||||
|
MetricIntervalLowerBound: aws.Float64(1.0),
|
||||||
|
MetricIntervalUpperBound: aws.Float64(2.0),
|
||||||
|
ScalingAdjustment: aws.Int64(int64(1)),
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(parameters[0], expected) {
|
||||||
|
t.Fatalf(
|
||||||
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
||||||
|
parameters[0],
|
||||||
|
expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFlattenParameters(t *testing.T) {
|
func TestFlattenParameters(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
Input []*rds.Parameter
|
Input []*rds.Parameter
|
||||||
|
@ -728,6 +755,30 @@ func TestFlattenAttachment(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestflattenStepAdjustments(t *testing.T) {
|
||||||
|
expanded := []*autoscaling.StepAdjustment{
|
||||||
|
&autoscaling.StepAdjustment{
|
||||||
|
MetricIntervalLowerBound: aws.Float64(1.0),
|
||||||
|
MetricIntervalUpperBound: aws.Float64(2.0),
|
||||||
|
ScalingAdjustment: aws.Int64(int64(1)),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
result := flattenStepAdjustments(expanded)[0]
|
||||||
|
if result == nil {
|
||||||
|
t.Fatal("expected result to have value, but got nil")
|
||||||
|
}
|
||||||
|
if result["metric_interval_lower_bound"] != float64(1.0) {
|
||||||
|
t.Fatalf("expected metric_interval_lower_bound to be 1.0, but got %d", result["metric_interval_lower_bound"])
|
||||||
|
}
|
||||||
|
if result["metric_interval_upper_bound"] != float64(2.0) {
|
||||||
|
t.Fatalf("expected metric_interval_upper_bound to be 1.0, but got %d", result["metric_interval_upper_bound"])
|
||||||
|
}
|
||||||
|
if result["scaling_adjustment"] != int64(1) {
|
||||||
|
t.Fatalf("expected scaling_adjustment to be 1, but got %d", result["scaling_adjustment"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFlattenResourceRecords(t *testing.T) {
|
func TestFlattenResourceRecords(t *testing.T) {
|
||||||
expanded := []*route53.ResourceRecord{
|
expanded := []*route53.ResourceRecord{
|
||||||
&route53.ResourceRecord{
|
&route53.ResourceRecord{
|
||||||
|
|
Loading…
Reference in New Issue