2014-07-14 17:36:25 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-03-03 23:36:25 +01:00
|
|
|
"reflect"
|
2015-10-31 10:24:46 +01:00
|
|
|
"regexp"
|
2016-08-19 21:07:53 +02:00
|
|
|
"sort"
|
2015-05-07 01:34:20 +02:00
|
|
|
"strings"
|
2014-07-14 17:36:25 +02:00
|
|
|
"testing"
|
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
"github.com/aws/aws-sdk-go/service/autoscaling"
|
2016-08-19 21:07:53 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/elbv2"
|
2016-04-11 19:06:28 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2014-07-14 17:36:25 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
2014-10-10 23:34:40 +02:00
|
|
|
func TestAccAWSAutoScalingGroup_basic(t *testing.T) {
|
2015-05-29 09:55:59 +02:00
|
|
|
var group autoscaling.Group
|
2015-04-16 14:10:17 +02:00
|
|
|
var lc autoscaling.LaunchConfiguration
|
2014-07-14 17:36:25 +02:00
|
|
|
|
2016-04-11 19:06:28 +02:00
|
|
|
randName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
|
|
|
|
|
2014-07-14 17:36:25 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
2016-04-22 06:36:14 +02:00
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
IDRefreshName: "aws_autoscaling_group.bar",
|
|
|
|
IDRefreshIgnore: []string{"force_delete", "metrics_granularity", "wait_for_capacity_timeout"},
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
2014-07-14 17:36:25 +02:00
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-04-11 19:06:28 +02:00
|
|
|
Config: testAccAWSAutoScalingGroupConfig(randName),
|
2014-07-14 17:36:25 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
2015-05-07 01:34:20 +02:00
|
|
|
testAccCheckAWSAutoScalingGroupHealthyCapacity(&group, 2),
|
2016-04-11 19:06:28 +02:00
|
|
|
testAccCheckAWSAutoScalingGroupAttributes(&group, randName),
|
2014-07-14 17:36:25 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-04-01 17:42:53 +02:00
|
|
|
"aws_autoscaling_group.bar", "availability_zones.2487133097", "us-west-2a"),
|
2014-07-15 00:48:22 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-04-11 19:06:28 +02:00
|
|
|
"aws_autoscaling_group.bar", "name", randName),
|
2014-07-15 00:48:22 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "max_size", "5"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "min_size", "2"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "health_check_grace_period", "300"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "health_check_type", "ELB"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2014-07-29 16:42:31 +02:00
|
|
|
"aws_autoscaling_group.bar", "desired_capacity", "4"),
|
2014-07-15 00:48:22 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-07-14 17:41:49 +02:00
|
|
|
"aws_autoscaling_group.bar", "force_delete", "true"),
|
2014-10-23 23:58:54 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2015-07-29 23:44:02 +02:00
|
|
|
"aws_autoscaling_group.bar", "termination_policies.0", "OldestInstance"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "termination_policies.1", "ClosestToNextInstanceHour"),
|
2016-06-29 08:36:34 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "protect_from_scale_in", "false"),
|
2014-07-14 17:36:25 +02:00
|
|
|
),
|
|
|
|
},
|
2014-10-11 01:25:23 +02:00
|
|
|
|
|
|
|
resource.TestStep{
|
2016-04-11 19:06:28 +02:00
|
|
|
Config: testAccAWSAutoScalingGroupConfigUpdate(randName),
|
2014-10-11 01:25:23 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
2015-02-18 01:12:02 +01:00
|
|
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.new", &lc),
|
2014-10-11 01:25:23 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "desired_capacity", "5"),
|
2015-07-29 23:44:02 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "termination_policies.0", "ClosestToNextInstanceHour"),
|
2016-06-29 08:36:34 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "protect_from_scale_in", "true"),
|
2015-02-20 23:26:43 +01:00
|
|
|
testLaunchConfigurationName("aws_autoscaling_group.bar", &lc),
|
2015-03-26 20:49:15 +01:00
|
|
|
testAccCheckAutoscalingTags(&group.Tags, "Bar", map[string]interface{}{
|
|
|
|
"value": "bar-foo",
|
|
|
|
"propagate_at_launch": true,
|
|
|
|
}),
|
2015-03-03 23:36:25 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-10-31 10:24:46 +01:00
|
|
|
func TestAccAWSAutoScalingGroup_autoGeneratedName(t *testing.T) {
|
|
|
|
asgNameRegexp := regexp.MustCompile("^tf-asg-")
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig_autoGeneratedName,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestMatchResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "name", asgNameRegexp),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-11 17:53:34 +01:00
|
|
|
func TestAccAWSAutoScalingGroup_terminationPolicies(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig_terminationPoliciesEmpty,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "termination_policies.#", "0"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig_terminationPoliciesUpdate,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "termination_policies.#", "1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "termination_policies.0", "OldestInstance"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig_terminationPoliciesExplicitDefault,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "termination_policies.#", "1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "termination_policies.0", "Default"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig_terminationPoliciesEmpty,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "termination_policies.#", "0"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-03-03 23:36:25 +01:00
|
|
|
func TestAccAWSAutoScalingGroup_tags(t *testing.T) {
|
2015-05-29 09:55:59 +02:00
|
|
|
var group autoscaling.Group
|
2015-03-03 23:36:25 +01:00
|
|
|
|
2016-04-11 19:06:28 +02:00
|
|
|
randName := fmt.Sprintf("tfautotags-%s", acctest.RandString(5))
|
|
|
|
|
2015-03-03 23:36:25 +01:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-04-11 19:06:28 +02:00
|
|
|
Config: testAccAWSAutoScalingGroupConfig(randName),
|
2015-03-03 23:36:25 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
2015-03-26 20:49:15 +01:00
|
|
|
testAccCheckAutoscalingTags(&group.Tags, "Foo", map[string]interface{}{
|
|
|
|
"value": "foo-bar",
|
2015-03-03 23:36:25 +01:00
|
|
|
"propagate_at_launch": true,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
2016-04-11 19:06:28 +02:00
|
|
|
Config: testAccAWSAutoScalingGroupConfigUpdate(randName),
|
2015-03-03 23:36:25 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
2015-03-26 20:49:15 +01:00
|
|
|
testAccCheckAutoscalingTagNotExists(&group.Tags, "Foo"),
|
|
|
|
testAccCheckAutoscalingTags(&group.Tags, "Bar", map[string]interface{}{
|
|
|
|
"value": "bar-foo",
|
2015-03-03 23:36:25 +01:00
|
|
|
"propagate_at_launch": true,
|
|
|
|
}),
|
2014-10-11 01:25:23 +02:00
|
|
|
),
|
|
|
|
},
|
2014-07-14 17:36:25 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-07-14 17:19:10 +02:00
|
|
|
func TestAccAWSAutoScalingGroup_VpcUpdates(t *testing.T) {
|
|
|
|
var group autoscaling.Group
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfigWithAZ,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
2016-02-07 22:36:29 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "availability_zones.#", "1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "availability_zones.2487133097", "us-west-2a"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "vpc_zone_identifier.#", "1"),
|
2015-07-14 17:19:10 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfigWithVPCIdent,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
testAccCheckAWSAutoScalingGroupAttributesVPCZoneIdentifer(&group),
|
2016-02-07 22:36:29 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-02-07 22:52:33 +01:00
|
|
|
"aws_autoscaling_group.bar", "availability_zones.#", "1"),
|
2016-02-07 22:36:29 +01:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "availability_zones.2487133097", "us-west-2a"),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-02-07 22:52:33 +01:00
|
|
|
"aws_autoscaling_group.bar", "vpc_zone_identifier.#", "1"),
|
2015-07-14 17:19:10 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-04-13 23:43:28 +02:00
|
|
|
func TestAccAWSAutoScalingGroup_WithLoadBalancer(t *testing.T) {
|
2015-05-29 09:55:59 +02:00
|
|
|
var group autoscaling.Group
|
2014-08-20 19:40:43 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-04-11 19:06:28 +02:00
|
|
|
Config: testAccAWSAutoScalingGroupConfigWithLoadBalancer,
|
2014-08-20 19:40:43 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(&group),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2015-05-07 01:34:20 +02:00
|
|
|
|
2015-12-04 01:17:54 +01:00
|
|
|
func TestAccAWSAutoScalingGroup_withPlacementGroup(t *testing.T) {
|
|
|
|
var group autoscaling.Group
|
|
|
|
|
2016-04-11 19:06:28 +02:00
|
|
|
randName := fmt.Sprintf("tf_placement_test-%s", acctest.RandString(5))
|
2015-12-04 01:17:54 +01:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-04-11 19:06:28 +02:00
|
|
|
Config: testAccAWSAutoScalingGroupConfig_withPlacementGroup(randName),
|
2015-12-04 01:17:54 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
resource.TestCheckResourceAttr(
|
2016-04-11 19:06:28 +02:00
|
|
|
"aws_autoscaling_group.bar", "placement_group", randName),
|
2015-12-04 01:17:54 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-07-20 20:36:45 +02:00
|
|
|
func TestAccAWSAutoScalingGroup_enablingMetrics(t *testing.T) {
|
|
|
|
var group autoscaling.Group
|
|
|
|
randName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig(randName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "enabled_metrics.#", ""),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoscalingMetricsCollectionConfig_updatingMetricsCollected,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "enabled_metrics.#", "5"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-29 21:58:41 +01:00
|
|
|
func TestAccAWSAutoScalingGroup_withMetrics(t *testing.T) {
|
|
|
|
var group autoscaling.Group
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoscalingMetricsCollectionConfig_allMetricsCollected,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "enabled_metrics.#", "7"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoscalingMetricsCollectionConfig_updatingMetricsCollected,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "enabled_metrics.#", "5"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-08-19 21:07:53 +02:00
|
|
|
func TestAccAWSAutoScalingGroup_ALB_TargetGroups(t *testing.T) {
|
|
|
|
var group autoscaling.Group
|
|
|
|
var tg elbv2.TargetGroup
|
|
|
|
var tg2 elbv2.TargetGroup
|
|
|
|
|
|
|
|
testCheck := func(targets []*elbv2.TargetGroup) resource.TestCheckFunc {
|
|
|
|
return func(*terraform.State) error {
|
|
|
|
var ts []string
|
|
|
|
var gs []string
|
|
|
|
for _, t := range targets {
|
|
|
|
ts = append(ts, *t.TargetGroupArn)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range group.TargetGroupARNs {
|
|
|
|
gs = append(gs, *s)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Strings(ts)
|
|
|
|
sort.Strings(gs)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(ts, gs) {
|
|
|
|
return fmt.Errorf("Error: target group match not found!\nASG Target groups: %#v\nTarget Group: %#v", ts, gs)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_pre,
|
|
|
|
Check: resource.ComposeAggregateTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "target_group_arns.#", "0"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_post_duo,
|
|
|
|
Check: resource.ComposeAggregateTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
|
|
|
|
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test_more", &tg2),
|
|
|
|
testCheck([]*elbv2.TargetGroup{&tg, &tg2}),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "target_group_arns.#", "2"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_post,
|
|
|
|
Check: resource.ComposeAggregateTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
testAccCheckAWSALBTargetGroupExists("aws_alb_target_group.test", &tg),
|
|
|
|
testCheck([]*elbv2.TargetGroup{&tg}),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "target_group_arns.#", "1"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_pre,
|
|
|
|
Check: resource.ComposeAggregateTestCheckFunc(
|
|
|
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"aws_autoscaling_group.bar", "target_group_arns.#", "0"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:36:25 +02:00
|
|
|
func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error {
|
2015-04-16 14:10:17 +02:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn
|
2014-07-14 17:36:25 +02:00
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
for _, rs := range s.RootModule().Resources {
|
2014-07-14 17:36:25 +02:00
|
|
|
if rs.Type != "aws_autoscaling_group" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find the Group
|
2014-07-15 00:48:22 +02:00
|
|
|
describeGroups, err := conn.DescribeAutoScalingGroups(
|
2015-04-15 22:30:35 +02:00
|
|
|
&autoscaling.DescribeAutoScalingGroupsInput{
|
|
|
|
AutoScalingGroupNames: []*string{aws.String(rs.Primary.ID)},
|
2014-07-15 00:48:22 +02:00
|
|
|
})
|
2014-07-14 17:36:25 +02:00
|
|
|
|
2014-07-15 00:48:22 +02:00
|
|
|
if err == nil {
|
|
|
|
if len(describeGroups.AutoScalingGroups) != 0 &&
|
2015-02-20 23:26:43 +01:00
|
|
|
*describeGroups.AutoScalingGroups[0].AutoScalingGroupName == rs.Primary.ID {
|
2014-07-15 00:48:22 +02:00
|
|
|
return fmt.Errorf("AutoScaling Group still exists")
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 17:36:25 +02:00
|
|
|
|
|
|
|
// Verify the error
|
2015-05-20 13:21:23 +02:00
|
|
|
ec2err, ok := err.(awserr.Error)
|
2014-07-14 17:36:25 +02:00
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-20 13:21:23 +02:00
|
|
|
if ec2err.Code() != "InvalidGroup.NotFound" {
|
2014-07-14 17:36:25 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-11 19:06:28 +02:00
|
|
|
func testAccCheckAWSAutoScalingGroupAttributes(group *autoscaling.Group, name string) resource.TestCheckFunc {
|
2014-07-14 17:36:25 +02:00
|
|
|
return func(s *terraform.State) error {
|
2015-04-15 22:30:35 +02:00
|
|
|
if *group.AvailabilityZones[0] != "us-west-2a" {
|
2015-04-15 22:32:20 +02:00
|
|
|
return fmt.Errorf("Bad availability_zones: %#v", group.AvailabilityZones[0])
|
2014-07-14 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
2016-04-11 19:06:28 +02:00
|
|
|
if *group.AutoScalingGroupName != name {
|
|
|
|
return fmt.Errorf("Bad Autoscaling Group name, expected (%s), got (%s)", name, *group.AutoScalingGroupName)
|
2014-07-14 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
2015-02-20 23:26:43 +01:00
|
|
|
if *group.MaxSize != 5 {
|
|
|
|
return fmt.Errorf("Bad max_size: %d", *group.MaxSize)
|
2014-07-14 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
2015-02-20 23:26:43 +01:00
|
|
|
if *group.MinSize != 2 {
|
|
|
|
return fmt.Errorf("Bad max_size: %d", *group.MinSize)
|
2014-07-14 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
2015-02-20 23:26:43 +01:00
|
|
|
if *group.HealthCheckType != "ELB" {
|
2015-03-20 16:11:12 +01:00
|
|
|
return fmt.Errorf("Bad health_check_type,\nexpected: %s\ngot: %s", "ELB", *group.HealthCheckType)
|
2014-07-14 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
2015-02-20 23:26:43 +01:00
|
|
|
if *group.HealthCheckGracePeriod != 300 {
|
|
|
|
return fmt.Errorf("Bad health_check_grace_period: %d", *group.HealthCheckGracePeriod)
|
2014-07-14 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
2015-02-20 23:26:43 +01:00
|
|
|
if *group.DesiredCapacity != 4 {
|
|
|
|
return fmt.Errorf("Bad desired_capacity: %d", *group.DesiredCapacity)
|
2014-07-14 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
2015-02-20 23:26:43 +01:00
|
|
|
if *group.LaunchConfigurationName == "" {
|
|
|
|
return fmt.Errorf("Bad launch configuration name: %s", *group.LaunchConfigurationName)
|
2014-07-14 17:36:25 +02:00
|
|
|
}
|
|
|
|
|
2015-04-15 22:30:35 +02:00
|
|
|
t := &autoscaling.TagDescription{
|
2015-03-26 20:49:15 +01:00
|
|
|
Key: aws.String("Foo"),
|
2015-03-03 23:36:25 +01:00
|
|
|
Value: aws.String("foo-bar"),
|
2015-07-28 22:29:46 +02:00
|
|
|
PropagateAtLaunch: aws.Bool(true),
|
2015-03-26 20:49:15 +01:00
|
|
|
ResourceType: aws.String("auto-scaling-group"),
|
2015-08-17 20:27:16 +02:00
|
|
|
ResourceId: group.AutoScalingGroupName,
|
2015-03-03 23:36:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(group.Tags[0], t) {
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
|
|
|
group.Tags[0],
|
|
|
|
t)
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:36:25 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 09:55:59 +02:00
|
|
|
func testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(group *autoscaling.Group) resource.TestCheckFunc {
|
2014-08-20 19:40:43 +02:00
|
|
|
return func(s *terraform.State) error {
|
2015-12-22 00:41:55 +01:00
|
|
|
if len(group.LoadBalancerNames) != 1 {
|
|
|
|
return fmt.Errorf("Bad load_balancers: %v", group.LoadBalancerNames)
|
2014-08-20 19:40:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 09:55:59 +02:00
|
|
|
func testAccCheckAWSAutoScalingGroupExists(n string, group *autoscaling.Group) resource.TestCheckFunc {
|
2014-07-14 17:36:25 +02:00
|
|
|
return func(s *terraform.State) error {
|
2014-09-17 02:44:42 +02:00
|
|
|
rs, ok := s.RootModule().Resources[n]
|
2014-07-14 17:36:25 +02:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
2014-09-17 02:44:42 +02:00
|
|
|
if rs.Primary.ID == "" {
|
2014-07-14 17:36:25 +02:00
|
|
|
return fmt.Errorf("No AutoScaling Group ID is set")
|
|
|
|
}
|
|
|
|
|
2015-04-16 14:10:17 +02:00
|
|
|
conn := testAccProvider.Meta().(*AWSClient).autoscalingconn
|
2014-07-14 17:36:25 +02:00
|
|
|
|
2015-04-15 22:30:35 +02:00
|
|
|
describeGroups, err := conn.DescribeAutoScalingGroups(
|
|
|
|
&autoscaling.DescribeAutoScalingGroupsInput{
|
|
|
|
AutoScalingGroupNames: []*string{aws.String(rs.Primary.ID)},
|
|
|
|
})
|
2014-07-14 17:36:25 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(describeGroups.AutoScalingGroups) != 1 ||
|
2015-02-20 23:26:43 +01:00
|
|
|
*describeGroups.AutoScalingGroups[0].AutoScalingGroupName != rs.Primary.ID {
|
2014-07-14 17:36:25 +02:00
|
|
|
return fmt.Errorf("AutoScaling Group not found")
|
|
|
|
}
|
|
|
|
|
2015-04-15 22:30:35 +02:00
|
|
|
*group = *describeGroups.AutoScalingGroups[0]
|
2014-07-14 17:36:25 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 14:10:17 +02:00
|
|
|
func testLaunchConfigurationName(n string, lc *autoscaling.LaunchConfiguration) resource.TestCheckFunc {
|
2015-02-20 23:26:43 +01:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *lc.LaunchConfigurationName != rs.Primary.Attributes["launch_configuration"] {
|
|
|
|
return fmt.Errorf("Launch configuration names do not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-07 01:34:20 +02:00
|
|
|
func testAccCheckAWSAutoScalingGroupHealthyCapacity(
|
2015-05-29 09:55:59 +02:00
|
|
|
g *autoscaling.Group, exp int) resource.TestCheckFunc {
|
2015-05-07 01:34:20 +02:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
healthy := 0
|
|
|
|
for _, i := range g.Instances {
|
|
|
|
if i.HealthStatus == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if strings.EqualFold(*i.HealthStatus, "Healthy") {
|
|
|
|
healthy++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if healthy < exp {
|
|
|
|
return fmt.Errorf("Expected at least %d healthy, got %d.", exp, healthy)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-14 17:19:10 +02:00
|
|
|
func testAccCheckAWSAutoScalingGroupAttributesVPCZoneIdentifer(group *autoscaling.Group) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
// Grab Subnet Ids
|
|
|
|
var subnets []string
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_subnet" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
subnets = append(subnets, rs.Primary.Attributes["id"])
|
|
|
|
}
|
|
|
|
|
2015-07-14 17:39:31 +02:00
|
|
|
if group.VPCZoneIdentifier == nil {
|
2015-07-14 17:19:10 +02:00
|
|
|
return fmt.Errorf("Bad VPC Zone Identifier\nexpected: %s\ngot nil", subnets)
|
|
|
|
}
|
|
|
|
|
|
|
|
zones := strings.Split(*group.VPCZoneIdentifier, ",")
|
2015-07-14 17:39:31 +02:00
|
|
|
|
2015-07-14 17:19:10 +02:00
|
|
|
remaining := len(zones)
|
|
|
|
for _, z := range zones {
|
|
|
|
for _, s := range subnets {
|
|
|
|
if z == s {
|
|
|
|
remaining--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if remaining != 0 {
|
|
|
|
return fmt.Errorf("Bad VPC Zone Identifier match\nexpected: %s\ngot:%s", zones, subnets)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-31 10:24:46 +01:00
|
|
|
const testAccAWSAutoScalingGroupConfig_autoGeneratedName = `
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
availability_zones = ["us-west-2a"]
|
2016-02-09 05:02:57 +01:00
|
|
|
desired_capacity = 0
|
|
|
|
max_size = 0
|
|
|
|
min_size = 0
|
2015-10-31 10:24:46 +01:00
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2016-02-11 17:53:34 +01:00
|
|
|
const testAccAWSAutoScalingGroupConfig_terminationPoliciesEmpty = `
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
max_size = 0
|
|
|
|
min_size = 0
|
|
|
|
desired_capacity = 0
|
|
|
|
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSAutoScalingGroupConfig_terminationPoliciesExplicitDefault = `
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
max_size = 0
|
|
|
|
min_size = 0
|
|
|
|
desired_capacity = 0
|
|
|
|
termination_policies = ["Default"]
|
|
|
|
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSAutoScalingGroupConfig_terminationPoliciesUpdate = `
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
max_size = 0
|
|
|
|
min_size = 0
|
|
|
|
desired_capacity = 0
|
|
|
|
termination_policies = ["OldestInstance"]
|
|
|
|
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2016-04-11 19:06:28 +02:00
|
|
|
func testAccAWSAutoScalingGroupConfig(name string) string {
|
|
|
|
return fmt.Sprintf(`
|
2014-07-14 17:36:25 +02:00
|
|
|
resource "aws_launch_configuration" "foobar" {
|
2014-07-28 17:27:50 +02:00
|
|
|
image_id = "ami-21f78e11"
|
2014-07-14 17:36:25 +02:00
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
|
2015-11-13 19:40:19 +01:00
|
|
|
resource "aws_placement_group" "test" {
|
2016-06-10 16:01:30 +02:00
|
|
|
name = "asg_pg_%s"
|
2015-11-13 19:40:19 +01:00
|
|
|
strategy = "cluster"
|
|
|
|
}
|
|
|
|
|
2014-07-14 17:36:25 +02:00
|
|
|
resource "aws_autoscaling_group" "bar" {
|
2014-07-28 17:27:50 +02:00
|
|
|
availability_zones = ["us-west-2a"]
|
2016-04-11 19:06:28 +02:00
|
|
|
name = "%s"
|
2014-07-14 17:36:25 +02:00
|
|
|
max_size = 5
|
|
|
|
min_size = 2
|
|
|
|
health_check_type = "ELB"
|
2014-07-28 17:27:50 +02:00
|
|
|
desired_capacity = 4
|
2014-07-14 17:36:25 +02:00
|
|
|
force_delete = true
|
2015-07-29 23:44:02 +02:00
|
|
|
termination_policies = ["OldestInstance","ClosestToNextInstanceHour"]
|
2014-12-12 23:21:20 +01:00
|
|
|
|
2014-07-14 17:36:25 +02:00
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
2015-03-03 23:36:25 +01:00
|
|
|
|
|
|
|
tag {
|
2015-03-26 20:49:15 +01:00
|
|
|
key = "Foo"
|
2015-03-03 23:36:25 +01:00
|
|
|
value = "foo-bar"
|
|
|
|
propagate_at_launch = true
|
|
|
|
}
|
2014-07-14 17:36:25 +02:00
|
|
|
}
|
2016-04-11 19:06:28 +02:00
|
|
|
`, name, name)
|
|
|
|
}
|
2014-08-20 19:40:43 +02:00
|
|
|
|
2016-04-11 19:06:28 +02:00
|
|
|
func testAccAWSAutoScalingGroupConfigUpdate(name string) string {
|
|
|
|
return fmt.Sprintf(`
|
2014-10-11 01:25:23 +02:00
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
|
2015-02-18 01:12:02 +01:00
|
|
|
resource "aws_launch_configuration" "new" {
|
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
|
2014-10-11 01:25:23 +02:00
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
availability_zones = ["us-west-2a"]
|
2016-04-11 19:06:28 +02:00
|
|
|
name = "%s"
|
2014-10-11 01:25:23 +02:00
|
|
|
max_size = 5
|
|
|
|
min_size = 2
|
|
|
|
health_check_grace_period = 300
|
|
|
|
health_check_type = "ELB"
|
|
|
|
desired_capacity = 5
|
|
|
|
force_delete = true
|
2015-07-29 23:44:02 +02:00
|
|
|
termination_policies = ["ClosestToNextInstanceHour"]
|
2016-06-29 08:36:34 +02:00
|
|
|
protect_from_scale_in = true
|
2014-10-11 01:25:23 +02:00
|
|
|
|
2015-02-18 01:12:02 +01:00
|
|
|
launch_configuration = "${aws_launch_configuration.new.name}"
|
2015-03-03 23:36:25 +01:00
|
|
|
|
|
|
|
tag {
|
2015-03-26 20:49:15 +01:00
|
|
|
key = "Bar"
|
2015-03-03 23:36:25 +01:00
|
|
|
value = "bar-foo"
|
|
|
|
propagate_at_launch = true
|
|
|
|
}
|
2014-10-11 01:25:23 +02:00
|
|
|
}
|
2016-04-11 19:06:28 +02:00
|
|
|
`, name)
|
|
|
|
}
|
2014-10-11 01:25:23 +02:00
|
|
|
|
2014-08-20 19:40:43 +02:00
|
|
|
const testAccAWSAutoScalingGroupConfigWithLoadBalancer = `
|
2015-06-01 19:03:44 +02:00
|
|
|
resource "aws_vpc" "foo" {
|
|
|
|
cidr_block = "10.1.0.0/16"
|
|
|
|
tags { Name = "tf-asg-test" }
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_internet_gateway" "gw" {
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "foo" {
|
|
|
|
cidr_block = "10.1.1.0/24"
|
|
|
|
vpc_id = "${aws_vpc.foo.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "foo" {
|
|
|
|
vpc_id="${aws_vpc.foo.id}"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
protocol = "-1"
|
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
|
|
|
|
egress {
|
|
|
|
protocol = "-1"
|
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-20 19:40:43 +02:00
|
|
|
resource "aws_elb" "bar" {
|
2015-06-01 19:03:44 +02:00
|
|
|
subnets = ["${aws_subnet.foo.id}"]
|
|
|
|
security_groups = ["${aws_security_group.foo.id}"]
|
2014-08-20 19:40:43 +02:00
|
|
|
|
|
|
|
listener {
|
2015-05-14 19:45:21 +02:00
|
|
|
instance_port = 80
|
2014-08-20 19:40:43 +02:00
|
|
|
instance_protocol = "http"
|
|
|
|
lb_port = 80
|
|
|
|
lb_protocol = "http"
|
|
|
|
}
|
2015-05-14 19:45:21 +02:00
|
|
|
|
|
|
|
health_check {
|
|
|
|
healthy_threshold = 2
|
|
|
|
unhealthy_threshold = 2
|
|
|
|
target = "HTTP:80/"
|
|
|
|
interval = 5
|
|
|
|
timeout = 2
|
|
|
|
}
|
2015-06-01 19:03:44 +02:00
|
|
|
|
|
|
|
depends_on = ["aws_internet_gateway.gw"]
|
2014-08-20 19:40:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
2015-05-14 19:45:21 +02:00
|
|
|
// need an AMI that listens on :80 at boot, this is:
|
|
|
|
// bitnami-nginxstack-1.6.1-0-linux-ubuntu-14.04.1-x86_64-hvm-ebs-ami-99f5b1a9-3
|
|
|
|
image_id = "ami-b5b3fc85"
|
|
|
|
instance_type = "t2.micro"
|
2015-06-01 19:03:44 +02:00
|
|
|
security_groups = ["${aws_security_group.foo.id}"]
|
2014-08-20 19:40:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
2015-06-01 19:03:44 +02:00
|
|
|
availability_zones = ["${aws_subnet.foo.availability_zone}"]
|
|
|
|
vpc_zone_identifier = ["${aws_subnet.foo.id}"]
|
2015-05-14 19:45:21 +02:00
|
|
|
max_size = 2
|
2014-08-20 19:40:43 +02:00
|
|
|
min_size = 2
|
|
|
|
health_check_grace_period = 300
|
|
|
|
health_check_type = "ELB"
|
2015-11-17 01:16:22 +01:00
|
|
|
wait_for_elb_capacity = 2
|
2014-08-20 19:40:43 +02:00
|
|
|
force_delete = true
|
|
|
|
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
load_balancers = ["${aws_elb.bar.name}"]
|
|
|
|
}
|
|
|
|
`
|
2015-07-14 17:19:10 +02:00
|
|
|
|
|
|
|
const testAccAWSAutoScalingGroupConfigWithAZ = `
|
|
|
|
resource "aws_vpc" "default" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
tags {
|
|
|
|
Name = "terraform-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "main" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.1.0/24"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
tags {
|
|
|
|
Name = "terraform-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-b5b3fc85"
|
|
|
|
instance_type = "t2.micro"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
2016-02-07 22:52:33 +01:00
|
|
|
availability_zones = [
|
|
|
|
"us-west-2a"
|
|
|
|
]
|
|
|
|
desired_capacity = 0
|
|
|
|
max_size = 0
|
|
|
|
min_size = 0
|
2015-07-14 17:19:10 +02:00
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSAutoScalingGroupConfigWithVPCIdent = `
|
|
|
|
resource "aws_vpc" "default" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
tags {
|
|
|
|
Name = "terraform-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "main" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.1.0/24"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
tags {
|
|
|
|
Name = "terraform-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-b5b3fc85"
|
|
|
|
instance_type = "t2.micro"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
vpc_zone_identifier = [
|
|
|
|
"${aws_subnet.main.id}",
|
|
|
|
]
|
2016-02-07 22:52:33 +01:00
|
|
|
desired_capacity = 0
|
|
|
|
max_size = 0
|
|
|
|
min_size = 0
|
2015-07-14 17:19:10 +02:00
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
}
|
|
|
|
`
|
2015-12-04 01:17:54 +01:00
|
|
|
|
2016-04-11 19:06:28 +02:00
|
|
|
func testAccAWSAutoScalingGroupConfig_withPlacementGroup(name string) string {
|
|
|
|
return fmt.Sprintf(`
|
2015-12-04 01:17:54 +01:00
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-21f78e11"
|
2016-03-07 23:35:07 +01:00
|
|
|
instance_type = "c3.large"
|
2015-12-04 01:17:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_placement_group" "test" {
|
2016-04-11 19:06:28 +02:00
|
|
|
name = "%s"
|
2015-12-04 01:17:54 +01:00
|
|
|
strategy = "cluster"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
availability_zones = ["us-west-2a"]
|
2016-04-11 19:06:28 +02:00
|
|
|
name = "%s"
|
2015-12-04 01:17:54 +01:00
|
|
|
max_size = 1
|
|
|
|
min_size = 1
|
|
|
|
health_check_grace_period = 300
|
|
|
|
health_check_type = "ELB"
|
|
|
|
desired_capacity = 1
|
|
|
|
force_delete = true
|
|
|
|
termination_policies = ["OldestInstance","ClosestToNextInstanceHour"]
|
|
|
|
placement_group = "${aws_placement_group.test.name}"
|
|
|
|
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
|
|
|
|
tag {
|
|
|
|
key = "Foo"
|
|
|
|
value = "foo-bar"
|
|
|
|
propagate_at_launch = true
|
|
|
|
}
|
|
|
|
}
|
2016-04-11 19:06:28 +02:00
|
|
|
`, name, name)
|
|
|
|
}
|
2016-02-29 21:58:41 +01:00
|
|
|
|
|
|
|
const testAccAWSAutoscalingMetricsCollectionConfig_allMetricsCollected = `
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
max_size = 1
|
|
|
|
min_size = 0
|
|
|
|
health_check_grace_period = 300
|
|
|
|
health_check_type = "EC2"
|
|
|
|
desired_capacity = 0
|
|
|
|
force_delete = true
|
|
|
|
termination_policies = ["OldestInstance","ClosestToNextInstanceHour"]
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
enabled_metrics = ["GroupTotalInstances",
|
|
|
|
"GroupPendingInstances",
|
|
|
|
"GroupTerminatingInstances",
|
|
|
|
"GroupDesiredCapacity",
|
|
|
|
"GroupInServiceInstances",
|
|
|
|
"GroupMinSize",
|
|
|
|
"GroupMaxSize"
|
|
|
|
]
|
|
|
|
metrics_granularity = "1Minute"
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSAutoscalingMetricsCollectionConfig_updatingMetricsCollected = `
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
image_id = "ami-21f78e11"
|
|
|
|
instance_type = "t1.micro"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
availability_zones = ["us-west-2a"]
|
|
|
|
max_size = 1
|
|
|
|
min_size = 0
|
|
|
|
health_check_grace_period = 300
|
|
|
|
health_check_type = "EC2"
|
|
|
|
desired_capacity = 0
|
|
|
|
force_delete = true
|
|
|
|
termination_policies = ["OldestInstance","ClosestToNextInstanceHour"]
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
enabled_metrics = ["GroupTotalInstances",
|
|
|
|
"GroupPendingInstances",
|
|
|
|
"GroupTerminatingInstances",
|
|
|
|
"GroupDesiredCapacity",
|
|
|
|
"GroupMaxSize"
|
|
|
|
]
|
|
|
|
metrics_granularity = "1Minute"
|
|
|
|
}
|
|
|
|
`
|
2016-08-19 21:07:53 +02:00
|
|
|
|
|
|
|
const testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_pre = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-west-2"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc" "default" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_alb_target_group" "test" {
|
|
|
|
name = "tf-example-alb-tg"
|
|
|
|
port = 80
|
|
|
|
protocol = "HTTP"
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "main" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.1.0/24"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "alt" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.2.0/24"
|
|
|
|
availability_zone = "us-west-2b"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
# Golang-base from cts-hashi aws account, shared with tf testing account
|
|
|
|
image_id = "ami-1817d178"
|
|
|
|
instance_type = "t2.micro"
|
|
|
|
enable_monitoring = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
vpc_zone_identifier = [
|
|
|
|
"${aws_subnet.main.id}",
|
|
|
|
"${aws_subnet.alt.id}",
|
|
|
|
]
|
|
|
|
|
|
|
|
max_size = 2
|
|
|
|
min_size = 0
|
|
|
|
health_check_grace_period = 300
|
|
|
|
health_check_type = "ELB"
|
|
|
|
desired_capacity = 0
|
|
|
|
force_delete = true
|
|
|
|
termination_policies = ["OldestInstance"]
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "tf_test_self" {
|
|
|
|
name = "tf_test_alb_asg"
|
|
|
|
description = "tf_test_alb_asg"
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
from_port = 80
|
|
|
|
to_port = 80
|
|
|
|
protocol = "tcp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_post = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-west-2"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc" "default" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_alb_target_group" "test" {
|
|
|
|
name = "tf-example-alb-tg"
|
|
|
|
port = 80
|
|
|
|
protocol = "HTTP"
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "main" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.1.0/24"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "alt" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.2.0/24"
|
|
|
|
availability_zone = "us-west-2b"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
# Golang-base from cts-hashi aws account, shared with tf testing account
|
|
|
|
image_id = "ami-1817d178"
|
|
|
|
instance_type = "t2.micro"
|
|
|
|
enable_monitoring = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
vpc_zone_identifier = [
|
|
|
|
"${aws_subnet.main.id}",
|
|
|
|
"${aws_subnet.alt.id}",
|
|
|
|
]
|
|
|
|
|
|
|
|
target_group_arns = ["${aws_alb_target_group.test.arn}"]
|
|
|
|
|
|
|
|
max_size = 2
|
|
|
|
min_size = 0
|
|
|
|
health_check_grace_period = 300
|
|
|
|
health_check_type = "ELB"
|
|
|
|
desired_capacity = 0
|
|
|
|
force_delete = true
|
|
|
|
termination_policies = ["OldestInstance"]
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "tf_test_self" {
|
|
|
|
name = "tf_test_alb_asg"
|
|
|
|
description = "tf_test_alb_asg"
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
from_port = 80
|
|
|
|
to_port = 80
|
|
|
|
protocol = "tcp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
const testAccAWSAutoScalingGroupConfig_ALB_TargetGroup_post_duo = `
|
|
|
|
provider "aws" {
|
|
|
|
region = "us-west-2"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_vpc" "default" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_alb_target_group" "test" {
|
|
|
|
name = "tf-example-alb-tg"
|
|
|
|
port = 80
|
|
|
|
protocol = "HTTP"
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_alb_target_group" "test_more" {
|
|
|
|
name = "tf-example-alb-tg-more"
|
|
|
|
port = 80
|
|
|
|
protocol = "HTTP"
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "main" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.1.0/24"
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "alt" {
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
cidr_block = "10.0.2.0/24"
|
|
|
|
availability_zone = "us-west-2b"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_launch_configuration" "foobar" {
|
|
|
|
# Golang-base from cts-hashi aws account, shared with tf testing account
|
|
|
|
image_id = "ami-1817d178"
|
|
|
|
instance_type = "t2.micro"
|
|
|
|
enable_monitoring = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_autoscaling_group" "bar" {
|
|
|
|
vpc_zone_identifier = [
|
|
|
|
"${aws_subnet.main.id}",
|
|
|
|
"${aws_subnet.alt.id}",
|
|
|
|
]
|
|
|
|
|
|
|
|
target_group_arns = [
|
|
|
|
"${aws_alb_target_group.test.arn}",
|
|
|
|
"${aws_alb_target_group.test_more.arn}",
|
|
|
|
]
|
|
|
|
|
|
|
|
max_size = 2
|
|
|
|
min_size = 0
|
|
|
|
health_check_grace_period = 300
|
|
|
|
health_check_type = "ELB"
|
|
|
|
desired_capacity = 0
|
|
|
|
force_delete = true
|
|
|
|
termination_policies = ["OldestInstance"]
|
|
|
|
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "tf_test_self" {
|
|
|
|
name = "tf_test_alb_asg"
|
|
|
|
description = "tf_test_alb_asg"
|
|
|
|
vpc_id = "${aws_vpc.default.id}"
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
from_port = 80
|
|
|
|
to_port = 80
|
|
|
|
protocol = "tcp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "testAccAWSAutoScalingGroupConfig_ALB_TargetGroup"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|