provider/aws: More Acc test updates

Working on the green

- randomize some Autoscaling lifecycle hook test names
- use vpc_security_group_ids for this test
This commit is contained in:
clint shryock 2016-03-10 11:03:00 -06:00
parent 01b3e215d7
commit 02ba1bf2d4
2 changed files with 54 additions and 44 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
@ -13,16 +14,18 @@ import (
func TestAccAWSAutoscalingLifecycleHook_basic(t *testing.T) {
var hook autoscaling.LifecycleHook
resourceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAutoscalingLifecycleHookDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSAutoscalingLifecycleHookConfig,
Config: testAccAWSAutoscalingLifecycleHookConfig(resourceName),
Check: resource.ComposeTestCheckFunc(
testAccCheckLifecycleHookExists("aws_autoscaling_lifecycle_hook.foobar", &hook),
resource.TestCheckResourceAttr("aws_autoscaling_lifecycle_hook.foobar", "autoscaling_group_name", "terraform-test-foobar5"),
resource.TestCheckResourceAttr("aws_autoscaling_lifecycle_hook.foobar", "autoscaling_group_name", resourceName),
resource.TestCheckResourceAttr("aws_autoscaling_lifecycle_hook.foobar", "default_result", "CONTINUE"),
resource.TestCheckResourceAttr("aws_autoscaling_lifecycle_hook.foobar", "heartbeat_timeout", "2000"),
resource.TestCheckResourceAttr("aws_autoscaling_lifecycle_hook.foobar", "lifecycle_transition", "autoscaling:EC2_INSTANCE_LAUNCHING"),
@ -41,7 +44,7 @@ func TestAccAWSAutoscalingLifecycleHook_omitDefaultResult(t *testing.T) {
CheckDestroy: testAccCheckAWSAutoscalingLifecycleHookDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAWSAutoscalingLifecycleHookConfig_omitDefaultResult,
Config: testAccAWSAutoscalingLifecycleHookConfig_omitDefaultResult(acctest.RandString(10)),
Check: resource.ComposeTestCheckFunc(
testAccCheckLifecycleHookExists("aws_autoscaling_lifecycle_hook.foobar", &hook),
resource.TestCheckResourceAttr("aws_autoscaling_lifecycle_hook.foobar", "default_result", "ABANDON"),
@ -101,9 +104,10 @@ func testAccCheckAWSAutoscalingLifecycleHookDestroy(s *terraform.State) error {
return nil
}
var testAccAWSAutoscalingLifecycleHookConfig = fmt.Sprintf(`
func testAccAWSAutoscalingLifecycleHookConfig(name string) string {
return fmt.Sprintf(`
resource "aws_launch_configuration" "foobar" {
name = "terraform-test-foobar5"
name = "%s"
image_id = "ami-21f78e11"
instance_type = "t1.micro"
}
@ -154,7 +158,7 @@ EOF
resource "aws_autoscaling_group" "foobar" {
availability_zones = ["us-west-2a"]
name = "terraform-test-foobar5"
name = "%s"
max_size = 5
min_size = 2
health_check_grace_period = 300
@ -183,11 +187,13 @@ EOF
notification_target_arn = "${aws_sqs_queue.foobar.arn}"
role_arn = "${aws_iam_role.foobar.arn}"
}
`)
`, name, name)
}
var testAccAWSAutoscalingLifecycleHookConfig_omitDefaultResult = fmt.Sprintf(`
func testAccAWSAutoscalingLifecycleHookConfig_omitDefaultResult(name string) string {
return fmt.Sprintf(`
resource "aws_launch_configuration" "foobar" {
name = "terraform-test-foobar5"
name = "%s"
image_id = "ami-21f78e11"
instance_type = "t1.micro"
}
@ -202,6 +208,7 @@ resource "aws_sqs_queue" "foobar" {
resource "aws_iam_role" "foobar" {
name = "foobar"
assume_role_policy = <<EOF
{
"Version" : "2012-10-17",
@ -217,6 +224,7 @@ EOF
resource "aws_iam_role_policy" "foobar" {
name = "foobar"
role = "${aws_iam_role.foobar.id}"
policy = <<EOF
{
"Version" : "2012-10-17",
@ -235,10 +243,9 @@ resource "aws_iam_role_policy" "foobar" {
EOF
}
resource "aws_autoscaling_group" "foobar" {
availability_zones = ["us-west-2a"]
name = "terraform-test-foobar5"
name = "%s"
max_size = 5
min_size = 2
health_check_grace_period = 300
@ -246,6 +253,7 @@ resource "aws_autoscaling_group" "foobar" {
force_delete = true
termination_policies = ["OldestInstance"]
launch_configuration = "${aws_launch_configuration.foobar.name}"
tag {
key = "Foo"
value = "foo-bar"
@ -258,12 +266,14 @@ resource "aws_autoscaling_lifecycle_hook" "foobar" {
autoscaling_group_name = "${aws_autoscaling_group.foobar.name}"
heartbeat_timeout = 2000
lifecycle_transition = "autoscaling:EC2_INSTANCE_LAUNCHING"
notification_metadata = <<EOF
{
"foo": "bar"
}
EOF
notification_target_arn = "${aws_sqs_queue.foobar.arn}"
role_arn = "${aws_iam_role.foobar.arn}"
}`, name, name)
}
`)

View File

@ -944,7 +944,7 @@ resource "aws_subnet" "foo" {
resource "aws_instance" "foo_instance" {
ami = "ami-21f78e11"
instance_type = "t1.micro"
security_groups = ["${aws_security_group.tf_test_foo.id}"]
vpc_security_group_ids = ["${aws_security_group.tf_test_foo.id}"]
subnet_id = "${aws_subnet.foo.id}"
associate_public_ip_address = true
depends_on = ["aws_internet_gateway.gw"]