provider/aws: Update Autoscaling attachment test
This commit is contained in:
parent
ca4841b9b0
commit
2d045a3302
|
@ -6,45 +6,49 @@ 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"
|
||||
)
|
||||
|
||||
func TestAccAwsAutoscalingAttachment_basic(t *testing.T) {
|
||||
|
||||
rInt := acctest.RandInt()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccAWSAutoscalingAttachment_basic,
|
||||
Config: testAccAWSAutoscalingAttachment_basic(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 0),
|
||||
),
|
||||
},
|
||||
// Add in one association
|
||||
resource.TestStep{
|
||||
Config: testAccAWSAutoscalingAttachment_associated,
|
||||
Config: testAccAWSAutoscalingAttachment_associated(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 1),
|
||||
),
|
||||
},
|
||||
// Test adding a 2nd
|
||||
resource.TestStep{
|
||||
Config: testAccAWSAutoscalingAttachment_double_associated,
|
||||
Config: testAccAWSAutoscalingAttachment_double_associated(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 2),
|
||||
),
|
||||
},
|
||||
// Now remove that newest one
|
||||
resource.TestStep{
|
||||
Config: testAccAWSAutoscalingAttachment_associated,
|
||||
Config: testAccAWSAutoscalingAttachment_associated(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 1),
|
||||
),
|
||||
},
|
||||
// Now remove them both
|
||||
resource.TestStep{
|
||||
Config: testAccAWSAutoscalingAttachment_basic,
|
||||
Config: testAccAWSAutoscalingAttachment_basic(rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 0),
|
||||
),
|
||||
|
@ -79,7 +83,8 @@ func testAccCheckAWSAutocalingAttachmentExists(asgname string, loadBalancerCount
|
|||
}
|
||||
}
|
||||
|
||||
const testAccAWSAutoscalingAttachment_basic = `
|
||||
func testAccAWSAutoscalingAttachment_basic(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_elb" "foo" {
|
||||
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
||||
|
||||
|
@ -103,14 +108,14 @@ resource "aws_elb" "bar" {
|
|||
}
|
||||
|
||||
resource "aws_launch_configuration" "as_conf" {
|
||||
name = "test_config"
|
||||
name = "test_config_%d"
|
||||
image_id = "ami-f34032c3"
|
||||
instance_type = "t1.micro"
|
||||
}
|
||||
|
||||
resource "aws_autoscaling_group" "asg" {
|
||||
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
||||
name = "asg-lb-assoc-terraform-test"
|
||||
name = "asg-lb-assoc-terraform-test_%d"
|
||||
max_size = 1
|
||||
min_size = 0
|
||||
desired_capacity = 0
|
||||
|
@ -123,22 +128,21 @@ resource "aws_autoscaling_group" "asg" {
|
|||
value = "terraform-asg-lg-assoc-test"
|
||||
propagate_at_launch = true
|
||||
}
|
||||
}`, rInt, rInt)
|
||||
}
|
||||
|
||||
`
|
||||
|
||||
const testAccAWSAutoscalingAttachment_associated = testAccAWSAutoscalingAttachment_basic + `
|
||||
func testAccAWSAutoscalingAttachment_associated(rInt int) string {
|
||||
return testAccAWSAutoscalingAttachment_basic(rInt) + `
|
||||
resource "aws_autoscaling_attachment" "asg_attachment_foo" {
|
||||
autoscaling_group_name = "${aws_autoscaling_group.asg.id}"
|
||||
elb = "${aws_elb.foo.id}"
|
||||
}`
|
||||
}
|
||||
|
||||
`
|
||||
|
||||
const testAccAWSAutoscalingAttachment_double_associated = testAccAWSAutoscalingAttachment_associated + `
|
||||
func testAccAWSAutoscalingAttachment_double_associated(rInt int) string {
|
||||
return testAccAWSAutoscalingAttachment_associated(rInt) + `
|
||||
resource "aws_autoscaling_attachment" "asg_attachment_bar" {
|
||||
autoscaling_group_name = "${aws_autoscaling_group.asg.id}"
|
||||
elb = "${aws_elb.bar.id}"
|
||||
}`
|
||||
}
|
||||
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue