Merge pull request #11333 from radeksimko/f-aws-alb-wait
provider/aws: Wait until ALB is actually provisioned
This commit is contained in:
commit
6013dc06a9
|
@ -74,7 +74,7 @@ func testAccDataSourceAWSALBListenerConfigBasic(albName, targetGroupName string)
|
|||
|
||||
resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
@ -221,6 +221,14 @@ resource "aws_vpc" "alb_test" {
|
|||
}
|
||||
}
|
||||
|
||||
resource "aws_internet_gateway" "gw" {
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "alb_test" {
|
||||
count = 2
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestAccDataSourceAWSALB_basic(t *testing.T) {
|
|||
Config: testAccDataSourceAWSALBConfigBasic(albName),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "name", albName),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "internal", "true"),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "tags.%", "1"),
|
||||
|
@ -31,7 +31,7 @@ func TestAccDataSourceAWSALB_basic(t *testing.T) {
|
|||
resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_arn", "dns_name"),
|
||||
resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_arn", "arn"),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "name", albName),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "internal", "true"),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "tags.%", "1"),
|
||||
|
@ -51,7 +51,7 @@ func TestAccDataSourceAWSALB_basic(t *testing.T) {
|
|||
func testAccDataSourceAWSALBConfigBasic(albName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/elbv2"
|
||||
|
@ -169,9 +170,38 @@ func resourceAwsAlbCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
return fmt.Errorf("No load balancers returned following creation of %s", d.Get("name").(string))
|
||||
}
|
||||
|
||||
d.SetId(*resp.LoadBalancers[0].LoadBalancerArn)
|
||||
lb := resp.LoadBalancers[0]
|
||||
d.SetId(*lb.LoadBalancerArn)
|
||||
log.Printf("[INFO] ALB ID: %s", d.Id())
|
||||
|
||||
stateConf := &resource.StateChangeConf{
|
||||
Pending: []string{"active", "provisioning", "failed"},
|
||||
Target: []string{"active"},
|
||||
Refresh: func() (interface{}, string, error) {
|
||||
describeResp, err := elbconn.DescribeLoadBalancers(&elbv2.DescribeLoadBalancersInput{
|
||||
LoadBalancerArns: []*string{lb.LoadBalancerArn},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
if len(describeResp.LoadBalancers) != 1 {
|
||||
return nil, "", fmt.Errorf("No load balancers returned for %s", *lb.LoadBalancerArn)
|
||||
}
|
||||
dLb := describeResp.LoadBalancers[0]
|
||||
|
||||
log.Printf("[INFO] ALB state: %s", *dLb.State.Code)
|
||||
|
||||
return describeResp, *dLb.State.Code, nil
|
||||
},
|
||||
Timeout: 5 * time.Minute,
|
||||
MinTimeout: 3 * time.Second,
|
||||
}
|
||||
_, err = stateConf.WaitForState()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return resourceAwsAlbUpdate(d, meta)
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ resource "aws_alb_listener" "front_end" {
|
|||
|
||||
resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ func testAccAWSALBListenerConfig_basic(albName, targetGroupName string) string {
|
|||
|
||||
resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
@ -291,6 +291,14 @@ resource "aws_vpc" "alb_test" {
|
|||
}
|
||||
}
|
||||
|
||||
resource "aws_internet_gateway" "gw" {
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
|
||||
tags {
|
||||
TestName = "TestAccAWSALB_basic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "alb_test" {
|
||||
count = 2
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
|
|
|
@ -60,7 +60,7 @@ func TestAccAWSALB_basic(t *testing.T) {
|
|||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "true"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
|
||||
|
@ -197,7 +197,7 @@ func TestAccAWSALB_noSecurityGroup(t *testing.T) {
|
|||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "true"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
|
||||
|
@ -229,7 +229,7 @@ func TestAccAWSALB_accesslogs(t *testing.T) {
|
|||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "true"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
|
||||
|
@ -247,7 +247,7 @@ func TestAccAWSALB_accesslogs(t *testing.T) {
|
|||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "true"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
|
||||
|
@ -269,7 +269,7 @@ func TestAccAWSALB_accesslogs(t *testing.T) {
|
|||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
testAccCheckAWSALBExists("aws_alb.alb_test", &conf),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "name", albName),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "false"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "internal", "true"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "subnets.#", "2"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "security_groups.#", "1"),
|
||||
resource.TestCheckResourceAttr("aws_alb.alb_test", "tags.%", "1"),
|
||||
|
@ -362,7 +362,7 @@ func testAccCheckAWSALBDestroy(s *terraform.State) error {
|
|||
func testAccAWSALBConfig_basic(albName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
@ -429,7 +429,7 @@ resource "aws_security_group" "alb_test" {
|
|||
func testAccAWSALBConfig_generatedName() string {
|
||||
return fmt.Sprintf(`
|
||||
resource "aws_alb" "alb_test" {
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
@ -456,6 +456,14 @@ resource "aws_vpc" "alb_test" {
|
|||
}
|
||||
}
|
||||
|
||||
resource "aws_internet_gateway" "gw" {
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
|
||||
tags {
|
||||
Name = "TestAccAWSALB_basic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_subnet" "alb_test" {
|
||||
count = 2
|
||||
vpc_id = "${aws_vpc.alb_test.id}"
|
||||
|
@ -497,7 +505,7 @@ func testAccAWSALBConfig_namePrefix() string {
|
|||
return fmt.Sprintf(`
|
||||
resource "aws_alb" "alb_test" {
|
||||
name_prefix = "tf-lb"
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
@ -563,7 +571,7 @@ resource "aws_security_group" "alb_test" {
|
|||
func testAccAWSALBConfig_updatedTags(albName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
@ -631,7 +639,7 @@ resource "aws_security_group" "alb_test" {
|
|||
func testAccAWSALBConfig_accessLogs(enabled bool, albName, bucketName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
@ -742,7 +750,7 @@ resource "aws_security_group" "alb_test" {
|
|||
func testAccAWSALBConfig_nosg(albName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
internal = true
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
idle_timeout = 30
|
||||
|
@ -784,7 +792,7 @@ resource "aws_subnet" "alb_test" {
|
|||
func testAccAWSALBConfig_updateSecurityGroups(albName string) string {
|
||||
return fmt.Sprintf(`resource "aws_alb" "alb_test" {
|
||||
name = "%s"
|
||||
internal = false
|
||||
internal = true
|
||||
security_groups = ["${aws_security_group.alb_test.id}", "${aws_security_group.alb_test_2.id}"]
|
||||
subnets = ["${aws_subnet.alb_test.*.id}"]
|
||||
|
||||
|
|
Loading…
Reference in New Issue