diff --git a/builtin/providers/aws/resource_aws_appautoscaling_policy.go b/builtin/providers/aws/resource_aws_appautoscaling_policy.go index 1ce898781..e75e76152 100644 --- a/builtin/providers/aws/resource_aws_appautoscaling_policy.go +++ b/builtin/providers/aws/resource_aws_appautoscaling_policy.go @@ -47,16 +47,16 @@ func resourceAwsAppautoscalingPolicy() *schema.Resource { Required: true, }, "scalable_dimension": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Default: "ecs:service:DesiredCount", - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateAppautoscalingScalableDimension, }, "service_namespace": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Default: "ecs", - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateAppautoscalingServiceNamespace, }, "adjustment_type": &schema.Schema{ Type: schema.TypeString, @@ -258,10 +258,6 @@ func getAwsAppautoscalingPutScalingPolicyInput(d *schema.ResourceData) (applicat params.ServiceNamespace = aws.String(v.(string)) } - if v, ok := d.GetOk("policy_type"); ok { - params.PolicyType = aws.String(v.(string)) - } - if v, ok := d.GetOk("scalable_dimension"); ok { params.ScalableDimension = aws.String(v.(string)) } diff --git a/builtin/providers/aws/resource_aws_appautoscaling_policy_test.go b/builtin/providers/aws/resource_aws_appautoscaling_policy_test.go index 0b5b0888d..36abf932c 100644 --- a/builtin/providers/aws/resource_aws_appautoscaling_policy_test.go +++ b/builtin/providers/aws/resource_aws_appautoscaling_policy_test.go @@ -39,6 +39,29 @@ func TestAccAWSAppautoScalingPolicy_basic(t *testing.T) { }) } +func TestAccAWSAppautoScalingPolicy_spotFleetRequest(t *testing.T) { + var policy applicationautoscaling.ScalingPolicy + + randPolicyName := fmt.Sprintf("test-appautoscaling-policy-%s", acctest.RandString(5)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAppautoscalingPolicyDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSAppautoscalingPolicySpotFleetRequestConfig(randPolicyName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAppautoscalingPolicyExists("aws_appautoscaling_policy.test", &policy), + resource.TestCheckResourceAttr("aws_appautoscaling_policy.test", "name", randPolicyName), + resource.TestCheckResourceAttr("aws_appautoscaling_policy.test", "service_namespace", "ec2"), + resource.TestCheckResourceAttr("aws_appautoscaling_policy.test", "scalable_dimension", "ec2:spot-fleet-request:TargetCapacity"), + ), + }, + }, + }) +} + func testAccCheckAWSAppautoscalingPolicyExists(n string, policy *applicationautoscaling.ScalingPolicy) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -171,3 +194,99 @@ resource "aws_appautoscaling_policy" "foobar_simple" { } `, randClusterName, randClusterName, randClusterName, randPolicyName) } + +func testAccAWSAppautoscalingPolicySpotFleetRequestConfig( + randPolicyName string) string { + return fmt.Sprintf(` +resource "aws_iam_role" "fleet_role" { + assume_role_policy = < 255 { - errors = append(errors, fmt.Errorf( - "%q cannot be longer than 255 characters", k)) - } - return - }, - }, - "arn": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, "max_capacity": &schema.Schema{ Type: schema.TypeInt, Required: true, @@ -60,16 +41,16 @@ func resourceAwsAppautoscalingTarget() *schema.Resource { ForceNew: true, }, "scalable_dimension": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Default: "ecs:service:DesiredCount", - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateAppautoscalingScalableDimension, }, "service_namespace": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Default: "ecs", - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateAppautoscalingServiceNamespace, }, }, } diff --git a/builtin/providers/aws/resource_aws_appautoscaling_target_test.go b/builtin/providers/aws/resource_aws_appautoscaling_target_test.go index 88f979391..313534fce 100644 --- a/builtin/providers/aws/resource_aws_appautoscaling_target_test.go +++ b/builtin/providers/aws/resource_aws_appautoscaling_target_test.go @@ -46,6 +46,27 @@ func TestAccAWSAppautoScalingTarget_basic(t *testing.T) { }) } +func TestAccAWSAppautoScalingTarget_spotFleetRequest(t *testing.T) { + var target applicationautoscaling.ScalableTarget + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "aws_appautoscaling_target.test", + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAppautoscalingTargetDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSAppautoscalingTargetSpotFleetRequestConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAppautoscalingTargetExists("aws_appautoscaling_target.test", &target), + resource.TestCheckResourceAttr("aws_appautoscaling_target.test", "service_namespace", "ec2"), + resource.TestCheckResourceAttr("aws_appautoscaling_target.test", "scalable_dimension", "ec2:spot-fleet-request:TargetCapacity"), + ), + }, + }, + }) +} + func testAccCheckAWSAppautoscalingTargetDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).appautoscalingconn @@ -174,6 +195,7 @@ EOF resource "aws_ecs_cluster" "foo" { name = "%s" } + resource "aws_ecs_task_definition" "task" { family = "foobar" container_definitions = <