forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source_aws_autoscaling_group_test.go
99 lines (87 loc) · 3.85 KB
/
data_source_aws_autoscaling_group_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package aws
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAwsAutoScalingGroupDataSource_basic(t *testing.T) {
datasourceName := "data.aws_autoscaling_group.good_match"
resourceName := "aws_autoscaling_group.foo"
rName := fmt.Sprintf("tf-test-asg-%d", acctest.RandInt())
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAutoScalingGroupDataResourceConfig(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(datasourceName, "availability_zones.#", resourceName, "availability_zones.#"),
resource.TestCheckResourceAttrPair(datasourceName, "default_cooldown", resourceName, "default_cooldown"),
resource.TestCheckResourceAttrPair(datasourceName, "desired_capacity", resourceName, "desired_capacity"),
resource.TestCheckResourceAttrPair(datasourceName, "health_check_grace_period", resourceName, "health_check_grace_period"),
resource.TestCheckResourceAttrPair(datasourceName, "health_check_type", resourceName, "health_check_type"),
resource.TestCheckResourceAttrPair(datasourceName, "launch_configuration", resourceName, "launch_configuration"),
resource.TestCheckResourceAttrPair(datasourceName, "load_balancers.#", resourceName, "load_balancers.#"),
resource.TestCheckResourceAttr(datasourceName, "new_instances_protected_from_scale_in", "false"),
resource.TestCheckResourceAttrPair(datasourceName, "max_size", resourceName, "max_size"),
resource.TestCheckResourceAttrPair(datasourceName, "min_size", resourceName, "min_size"),
resource.TestCheckResourceAttrPair(datasourceName, "target_group_arns.#", resourceName, "target_group_arns.#"),
resource.TestCheckResourceAttr(datasourceName, "vpc_zone_identifier", ""),
),
},
},
})
}
// Lookup based on AutoScalingGroupName
func testAccAutoScalingGroupDataResourceConfig(rName string) string {
return fmt.Sprintf(`
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
data "aws_availability_zones" "available" {
state = "available"
}
resource "aws_launch_configuration" "data_source_aws_autoscaling_group_test" {
name = "%[1]s"
image_id = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.micro"
}
resource "aws_autoscaling_group" "foo" {
name = "%[1]s_foo"
max_size = 0
min_size = 0
health_check_grace_period = 300
health_check_type = "ELB"
desired_capacity = 0
force_delete = true
launch_configuration = "${aws_launch_configuration.data_source_aws_autoscaling_group_test.name}"
availability_zones = ["${data.aws_availability_zones.available.names[0]}", "${data.aws_availability_zones.available.names[1]}"]
}
resource "aws_autoscaling_group" "bar" {
name = "%[1]s_bar"
max_size = 0
min_size = 0
health_check_grace_period = 300
health_check_type = "ELB"
desired_capacity = 0
force_delete = true
launch_configuration = "${aws_launch_configuration.data_source_aws_autoscaling_group_test.name}"
availability_zones = ["${data.aws_availability_zones.available.names[0]}", "${data.aws_availability_zones.available.names[1]}"]
}
data "aws_autoscaling_group" "good_match" {
name = "${aws_autoscaling_group.foo.name}"
}
`, rName)
}