Merge pull request #3996 from hashicorp/b-aws-test-fixes

Adjustments for AWS Acceptance tests
This commit is contained in:
Clint 2015-11-20 13:28:25 -06:00
commit ed3399593a
2 changed files with 23 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package aws
import ( import (
"fmt" "fmt"
"os"
"testing" "testing"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -13,7 +12,6 @@ import (
func TestAccAWSFlowLog_basic(t *testing.T) { func TestAccAWSFlowLog_basic(t *testing.T) {
var flowLog ec2.FlowLog var flowLog ec2.FlowLog
lgn := os.Getenv("LOG_GROUP_NAME")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -21,7 +19,7 @@ func TestAccAWSFlowLog_basic(t *testing.T) {
CheckDestroy: testAccCheckFlowLogDestroy, CheckDestroy: testAccCheckFlowLogDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: fmt.Sprintf(testAccFlowLogConfig_basic, lgn), Config: testAccFlowLogConfig_basic,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckFlowLogExists("aws_flow_log.test_flow_log", &flowLog), testAccCheckFlowLogExists("aws_flow_log.test_flow_log", &flowLog),
testAccCheckAWSFlowLogAttributes(&flowLog), testAccCheckAWSFlowLogAttributes(&flowLog),
@ -142,6 +140,9 @@ resource "aws_iam_role" "test_role" {
EOF EOF
} }
resource "aws_cloudwatch_log_group" "foobar" {
name = "foo-bar"
}
resource "aws_flow_log" "test_flow_log" { resource "aws_flow_log" "test_flow_log" {
# log_group_name needs to exist before hand # log_group_name needs to exist before hand
# until we have a CloudWatch Log Group Resource # until we have a CloudWatch Log Group Resource
@ -154,7 +155,7 @@ resource "aws_flow_log" "test_flow_log" {
resource "aws_flow_log" "test_flow_log_subnet" { resource "aws_flow_log" "test_flow_log_subnet" {
# log_group_name needs to exist before hand # log_group_name needs to exist before hand
# until we have a CloudWatch Log Group Resource # until we have a CloudWatch Log Group Resource
log_group_name = "%s" log_group_name = "${aws_cloudwatch_log_group.foobar.name}"
iam_role_arn = "${aws_iam_role.test_role.arn}" iam_role_arn = "${aws_iam_role.test_role.arn}"
subnet_id = "${aws_subnet.test_subnet.id}" subnet_id = "${aws_subnet.test_subnet.id}"
traffic_type = "ALL" traffic_type = "ALL"

View File

@ -168,24 +168,34 @@ func resourceAwsVpnGatewayAttach(d *schema.ResourceData, meta interface{}) error
d.Id(), d.Id(),
d.Get("vpc_id").(string)) d.Get("vpc_id").(string))
_, err := conn.AttachVpnGateway(&ec2.AttachVpnGatewayInput{ req := &ec2.AttachVpnGatewayInput{
VpnGatewayId: aws.String(d.Id()), VpnGatewayId: aws.String(d.Id()),
VpcId: aws.String(d.Get("vpc_id").(string)), VpcId: aws.String(d.Get("vpc_id").(string)),
}
err := resource.Retry(30*time.Second, func() error {
_, err := conn.AttachVpnGateway(req)
if err != nil {
if ec2err, ok := err.(awserr.Error); ok {
if "InvalidVpnGatewayID.NotFound" == ec2err.Code() {
//retry
return fmt.Errorf("Gateway not found, retry for eventual consistancy")
}
}
return resource.RetryError{Err: err}
}
return nil
}) })
if err != nil { if err != nil {
return err return err
} }
// A note on the states below: the AWS docs (as of July, 2014) say
// that the states would be: attached, attaching, detached, detaching,
// but when running, I noticed that the state is usually "available" when
// it is attached.
// Wait for it to be fully attached before continuing // Wait for it to be fully attached before continuing
log.Printf("[DEBUG] Waiting for VPN gateway (%s) to attach", d.Id()) log.Printf("[DEBUG] Waiting for VPN gateway (%s) to attach", d.Id())
stateConf := &resource.StateChangeConf{ stateConf := &resource.StateChangeConf{
Pending: []string{"detached", "attaching"}, Pending: []string{"detached", "attaching"},
Target: "available", Target: "attached",
Refresh: vpnGatewayAttachStateRefreshFunc(conn, d.Id(), "available"), Refresh: vpnGatewayAttachStateRefreshFunc(conn, d.Id(), "available"),
Timeout: 1 * time.Minute, Timeout: 1 * time.Minute,
} }
@ -271,6 +281,7 @@ func vpnGatewayAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string)
resp, err := conn.DescribeVpnGateways(&ec2.DescribeVpnGatewaysInput{ resp, err := conn.DescribeVpnGateways(&ec2.DescribeVpnGatewaysInput{
VpnGatewayIds: []*string{aws.String(id)}, VpnGatewayIds: []*string{aws.String(id)},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnGatewayID.NotFound" { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnGatewayID.NotFound" {
resp = nil resp = nil
@ -288,10 +299,6 @@ func vpnGatewayAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string)
vpnGateway := resp.VpnGateways[0] vpnGateway := resp.VpnGateways[0]
if time.Now().Sub(start) > 10*time.Second {
return vpnGateway, expected, nil
}
if len(vpnGateway.VpcAttachments) == 0 { if len(vpnGateway.VpcAttachments) == 0 {
// No attachments, we're detached // No attachments, we're detached
return vpnGateway, "detached", nil return vpnGateway, "detached", nil