From 4d0699b9ddecab2e16eadda4ceb81b50e8d69193 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 19 Nov 2015 16:19:49 -0600 Subject: [PATCH 1/5] mark snapshots as computed for ElastiCache clusters --- builtin/providers/aws/resource_aws_elasticache_cluster.go | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster.go b/builtin/providers/aws/resource_aws_elasticache_cluster.go index 18a4ddf41..a0350c401 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster.go @@ -141,6 +141,7 @@ func resourceAwsElasticacheCluster() *schema.Resource { "snapshot_window": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, }, "snapshot_retention_limit": &schema.Schema{ From fe204bb29137f29941c771d38e46fa1e4ff767f1 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 19 Nov 2015 16:24:17 -0600 Subject: [PATCH 2/5] error test when env var is not supplied --- builtin/providers/aws/resource_aws_flow_log_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/providers/aws/resource_aws_flow_log_test.go b/builtin/providers/aws/resource_aws_flow_log_test.go index 9f9ca0570..530559389 100644 --- a/builtin/providers/aws/resource_aws_flow_log_test.go +++ b/builtin/providers/aws/resource_aws_flow_log_test.go @@ -34,6 +34,9 @@ func TestAccAWSFlowLog_basic(t *testing.T) { func TestAccAWSFlowLog_subnet(t *testing.T) { var flowLog ec2.FlowLog lgn := os.Getenv("LOG_GROUP_NAME") + if lgn == "" { + t.Fatalf("LOG_GROUP_NAME env var needed for TestAccAWSFlowLog_subnet") + } resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, From 73475edceb835d9463f1958f9e23ea67046c2fe1 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Thu, 19 Nov 2015 16:27:56 -0600 Subject: [PATCH 3/5] update TestAccAWSFlowLog_subnet to use new cloudwatch resource, not needing env var anymore --- .../providers/aws/resource_aws_elasticache_cluster.go | 2 +- builtin/providers/aws/resource_aws_flow_log_test.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elasticache_cluster.go b/builtin/providers/aws/resource_aws_elasticache_cluster.go index a0350c401..d03ae89e8 100644 --- a/builtin/providers/aws/resource_aws_elasticache_cluster.go +++ b/builtin/providers/aws/resource_aws_elasticache_cluster.go @@ -141,7 +141,7 @@ func resourceAwsElasticacheCluster() *schema.Resource { "snapshot_window": &schema.Schema{ Type: schema.TypeString, Optional: true, - Computed: true, + Computed: true, }, "snapshot_retention_limit": &schema.Schema{ diff --git a/builtin/providers/aws/resource_aws_flow_log_test.go b/builtin/providers/aws/resource_aws_flow_log_test.go index 530559389..02fb3cfd8 100644 --- a/builtin/providers/aws/resource_aws_flow_log_test.go +++ b/builtin/providers/aws/resource_aws_flow_log_test.go @@ -33,10 +33,6 @@ func TestAccAWSFlowLog_basic(t *testing.T) { func TestAccAWSFlowLog_subnet(t *testing.T) { var flowLog ec2.FlowLog - lgn := os.Getenv("LOG_GROUP_NAME") - if lgn == "" { - t.Fatalf("LOG_GROUP_NAME env var needed for TestAccAWSFlowLog_subnet") - } resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -44,7 +40,7 @@ func TestAccAWSFlowLog_subnet(t *testing.T) { CheckDestroy: testAccCheckFlowLogDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: fmt.Sprintf(testAccFlowLogConfig_subnet, lgn), + Config: testAccFlowLogConfig_subnet, Check: resource.ComposeTestCheckFunc( testAccCheckFlowLogExists("aws_flow_log.test_flow_log_subnet", &flowLog), testAccCheckAWSFlowLogAttributes(&flowLog), @@ -203,11 +199,14 @@ resource "aws_iam_role" "test_role" { } EOF } +resource "aws_cloudwatch_log_group" "foobar" { + name = "foo-bar" +} resource "aws_flow_log" "test_flow_log_subnet" { # log_group_name needs to exist before hand # 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}" subnet_id = "${aws_subnet.test_subnet.id}" traffic_type = "ALL" From cf5b32617b89995a06865335c3b6ced03ecfb08b Mon Sep 17 00:00:00 2001 From: clint shryock Date: Fri, 20 Nov 2015 11:44:29 -0600 Subject: [PATCH 4/5] fix vpn gateway refresh/reattach issue --- .../providers/aws/resource_aws_vpn_gateway.go | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpn_gateway.go b/builtin/providers/aws/resource_aws_vpn_gateway.go index debd0ec91..4d7860dec 100644 --- a/builtin/providers/aws/resource_aws_vpn_gateway.go +++ b/builtin/providers/aws/resource_aws_vpn_gateway.go @@ -168,24 +168,34 @@ func resourceAwsVpnGatewayAttach(d *schema.ResourceData, meta interface{}) error d.Id(), d.Get("vpc_id").(string)) - _, err := conn.AttachVpnGateway(&ec2.AttachVpnGatewayInput{ + req := &ec2.AttachVpnGatewayInput{ VpnGatewayId: aws.String(d.Id()), 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 { 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 log.Printf("[DEBUG] Waiting for VPN gateway (%s) to attach", d.Id()) stateConf := &resource.StateChangeConf{ Pending: []string{"detached", "attaching"}, - Target: "available", + Target: "attached", Refresh: vpnGatewayAttachStateRefreshFunc(conn, d.Id(), "available"), Timeout: 1 * time.Minute, } @@ -271,6 +281,7 @@ func vpnGatewayAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string) resp, err := conn.DescribeVpnGateways(&ec2.DescribeVpnGatewaysInput{ VpnGatewayIds: []*string{aws.String(id)}, }) + if err != nil { if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnGatewayID.NotFound" { resp = nil @@ -288,10 +299,6 @@ func vpnGatewayAttachStateRefreshFunc(conn *ec2.EC2, id string, expected string) vpnGateway := resp.VpnGateways[0] - if time.Now().Sub(start) > 10*time.Second { - return vpnGateway, expected, nil - } - if len(vpnGateway.VpcAttachments) == 0 { // No attachments, we're detached return vpnGateway, "detached", nil From 9eb46c28b27c250730818960adaa794e5d49b10a Mon Sep 17 00:00:00 2001 From: clint shryock Date: Fri, 20 Nov 2015 13:15:20 -0600 Subject: [PATCH 5/5] use a log group resourcE --- builtin/providers/aws/resource_aws_flow_log_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_flow_log_test.go b/builtin/providers/aws/resource_aws_flow_log_test.go index 02fb3cfd8..061643e94 100644 --- a/builtin/providers/aws/resource_aws_flow_log_test.go +++ b/builtin/providers/aws/resource_aws_flow_log_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "os" "testing" "github.com/aws/aws-sdk-go/aws" @@ -13,7 +12,6 @@ import ( func TestAccAWSFlowLog_basic(t *testing.T) { var flowLog ec2.FlowLog - lgn := os.Getenv("LOG_GROUP_NAME") resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -21,7 +19,7 @@ func TestAccAWSFlowLog_basic(t *testing.T) { CheckDestroy: testAccCheckFlowLogDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: fmt.Sprintf(testAccFlowLogConfig_basic, lgn), + Config: testAccFlowLogConfig_basic, Check: resource.ComposeTestCheckFunc( testAccCheckFlowLogExists("aws_flow_log.test_flow_log", &flowLog), testAccCheckAWSFlowLogAttributes(&flowLog), @@ -142,6 +140,9 @@ resource "aws_iam_role" "test_role" { EOF } +resource "aws_cloudwatch_log_group" "foobar" { + name = "foo-bar" +} resource "aws_flow_log" "test_flow_log" { # log_group_name needs to exist before hand # 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" { # log_group_name needs to exist before hand # 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}" subnet_id = "${aws_subnet.test_subnet.id}" traffic_type = "ALL"