Skip to content

Commit

Permalink
Merge pull request #3122 from terraform-providers/b-aws_appautoscalin…
Browse files Browse the repository at this point in the history
…g_policy-more-metric-validation

resource/aws_appautoscaling_policy: Support additional predefined metric types in validation
  • Loading branch information
bflad authored Jan 26, 2018
2 parents 11c07d2 + b9edadc commit 8d14082
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
13 changes: 11 additions & 2 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/aws/aws-sdk-go/service/applicationautoscaling"
"github.com/aws/aws-sdk-go/service/cognitoidentity"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go/service/s3"
Expand Down Expand Up @@ -1152,8 +1153,16 @@ func validateAppautoscalingCustomizedMetricSpecificationStatistic(v interface{},

func validateAppautoscalingPredefinedMetricSpecification(v interface{}, k string) (ws []string, errors []error) {
validMetrics := []string{
"DynamoDBReadCapacityUtilization",
"DynamoDBWriteCapacityUtilization",
applicationautoscaling.MetricTypeAlbrequestCountPerTarget,
applicationautoscaling.MetricTypeDynamoDbreadCapacityUtilization,
applicationautoscaling.MetricTypeDynamoDbwriteCapacityUtilization,
applicationautoscaling.MetricTypeEc2spotFleetRequestAverageCpuutilization,
applicationautoscaling.MetricTypeEc2spotFleetRequestAverageNetworkIn,
applicationautoscaling.MetricTypeEc2spotFleetRequestAverageNetworkOut,
applicationautoscaling.MetricTypeEcsserviceAverageCpuutilization,
applicationautoscaling.MetricTypeEcsserviceAverageMemoryUtilization,
applicationautoscaling.MetricTypeRdsreaderAverageCpuutilization,
applicationautoscaling.MetricTypeRdsreaderAverageDatabaseConnections,
}
metric := v.(string)
for _, o := range validMetrics {
Expand Down
59 changes: 59 additions & 0 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2888,6 +2888,65 @@ func TestResourceAWSElastiCacheReplicationGroupAuthTokenValidation(t *testing.T)
}
}

func TestValidateAppautoscalingPredefinedMetricSpecification(t *testing.T) {
cases := []struct {
Value string
ErrCount int
}{
{
Value: "ALBRequestCountPerTarget",
ErrCount: 0,
},
{
Value: "DynamoDBReadCapacityUtilization",
ErrCount: 0,
},
{
Value: "DynamoDBWriteCapacityUtilization",
ErrCount: 0,
},
{
Value: "EC2SpotFleetRequestAverageCPUUtilization",
ErrCount: 0,
},
{
Value: "EC2SpotFleetRequestAverageNetworkIn",
ErrCount: 0,
},
{
Value: "EC2SpotFleetRequestAverageNetworkOut",
ErrCount: 0,
},
{
Value: "ECSServiceAverageCPUUtilization",
ErrCount: 0,
},
{
Value: "ECSServiceAverageMemoryUtilization",
ErrCount: 0,
},
{
Value: "RDSReaderAverageCPUUtilization",
ErrCount: 0,
},
{
Value: "RDSReaderAverageDatabaseConnections",
ErrCount: 0,
},
{
Value: "NotValid",
ErrCount: 1,
},
}
for _, tc := range cases {
_, errors := validateAppautoscalingPredefinedMetricSpecification(tc.Value, "predefined_metric_type")

if len(errors) != tc.ErrCount {
t.Fatalf("Expected %d errors, got %d: %s", tc.ErrCount, len(errors), errors)
}
}
}

func TestValidateCognitoUserPoolDomain(t *testing.T) {
validTypes := []string{
"valid-domain",
Expand Down

0 comments on commit 8d14082

Please sign in to comment.