mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-20 11:48:24 -06:00
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/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/autoscaling"
|
"github.com/aws/aws-sdk-go/service/autoscaling"
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccAwsAutoscalingAttachment_basic(t *testing.T) {
|
func TestAccAwsAutoscalingAttachment_basic(t *testing.T) {
|
||||||
|
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSAutoscalingAttachment_basic,
|
Config: testAccAWSAutoscalingAttachment_basic(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 0),
|
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 0),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
// Add in one association
|
// Add in one association
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSAutoscalingAttachment_associated,
|
Config: testAccAWSAutoscalingAttachment_associated(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 1),
|
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 1),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
// Test adding a 2nd
|
// Test adding a 2nd
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSAutoscalingAttachment_double_associated,
|
Config: testAccAWSAutoscalingAttachment_double_associated(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 2),
|
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 2),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
// Now remove that newest one
|
// Now remove that newest one
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSAutoscalingAttachment_associated,
|
Config: testAccAWSAutoscalingAttachment_associated(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 1),
|
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 1),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
// Now remove them both
|
// Now remove them both
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSAutoscalingAttachment_basic,
|
Config: testAccAWSAutoscalingAttachment_basic(rInt),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSAutocalingAttachmentExists("aws_autoscaling_group.asg", 0),
|
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" {
|
resource "aws_elb" "foo" {
|
||||||
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
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" {
|
resource "aws_launch_configuration" "as_conf" {
|
||||||
name = "test_config"
|
name = "test_config_%d"
|
||||||
image_id = "ami-f34032c3"
|
image_id = "ami-f34032c3"
|
||||||
instance_type = "t1.micro"
|
instance_type = "t1.micro"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_autoscaling_group" "asg" {
|
resource "aws_autoscaling_group" "asg" {
|
||||||
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
|
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
|
max_size = 1
|
||||||
min_size = 0
|
min_size = 0
|
||||||
desired_capacity = 0
|
desired_capacity = 0
|
||||||
@ -123,22 +128,21 @@ resource "aws_autoscaling_group" "asg" {
|
|||||||
value = "terraform-asg-lg-assoc-test"
|
value = "terraform-asg-lg-assoc-test"
|
||||||
propagate_at_launch = true
|
propagate_at_launch = true
|
||||||
}
|
}
|
||||||
|
}`, rInt, rInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
`
|
func testAccAWSAutoscalingAttachment_associated(rInt int) string {
|
||||||
|
return testAccAWSAutoscalingAttachment_basic(rInt) + `
|
||||||
const testAccAWSAutoscalingAttachment_associated = testAccAWSAutoscalingAttachment_basic + `
|
|
||||||
resource "aws_autoscaling_attachment" "asg_attachment_foo" {
|
resource "aws_autoscaling_attachment" "asg_attachment_foo" {
|
||||||
autoscaling_group_name = "${aws_autoscaling_group.asg.id}"
|
autoscaling_group_name = "${aws_autoscaling_group.asg.id}"
|
||||||
elb = "${aws_elb.foo.id}"
|
elb = "${aws_elb.foo.id}"
|
||||||
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
`
|
func testAccAWSAutoscalingAttachment_double_associated(rInt int) string {
|
||||||
|
return testAccAWSAutoscalingAttachment_associated(rInt) + `
|
||||||
const testAccAWSAutoscalingAttachment_double_associated = testAccAWSAutoscalingAttachment_associated + `
|
|
||||||
resource "aws_autoscaling_attachment" "asg_attachment_bar" {
|
resource "aws_autoscaling_attachment" "asg_attachment_bar" {
|
||||||
autoscaling_group_name = "${aws_autoscaling_group.asg.id}"
|
autoscaling_group_name = "${aws_autoscaling_group.asg.id}"
|
||||||
elb = "${aws_elb.bar.id}"
|
elb = "${aws_elb.bar.id}"
|
||||||
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
`
|
|
||||||
|
Loading…
Reference in New Issue
Block a user