From 38a8232e9a3234377a07a1360bc9e380ee393641 Mon Sep 17 00:00:00 2001 From: Rahul Menon Date: Wed, 25 Feb 2015 15:04:17 +0530 Subject: [PATCH 1/7] Added Connection to config --- builtin/providers/aws/config.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index 7a1896c14..9d324e495 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -14,6 +14,7 @@ import ( awsGo "github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/gen/autoscaling" + awsEc2 "github.com/awslabs/aws-sdk-go/gen/ec2" "github.com/awslabs/aws-sdk-go/gen/route53" "github.com/awslabs/aws-sdk-go/gen/s3" ) @@ -32,6 +33,7 @@ type AWSClient struct { rdsconn *rds.Rds r53conn *route53.Route53 region string + awsEc2conn *awsEc2.EC2 } // Client configures and returns a fully initailized AWSClient @@ -76,6 +78,10 @@ func (c *Config) Client() (interface{}, error) { // See http://docs.aws.amazon.com/general/latest/gr/sigv4_changes.html log.Println("[INFO] Initializing Route53 connection") client.r53conn = route53.New(creds, "us-east-1", nil) + + //Check about using us-east-1 for all + log.Println("[INFO] Initializing AWS-GO EC2 Connection") + client.awsEc2conn = awsEc2.New(creds, "us-east-1", nil) } if len(errs) > 0 { From 1472f976d7dabf4702edef4a166253a48b033db9 Mon Sep 17 00:00:00 2001 From: Rahul Menon Date: Wed, 25 Feb 2015 16:17:55 +0530 Subject: [PATCH 2/7] First refactor --- builtin/providers/aws/resource_aws_vpc.go | 74 +++++++++++++++-------- 1 file changed, 49 insertions(+), 25 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index f4ac2162e..496096106 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -5,9 +5,10 @@ import ( "log" "time" + awsGo "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/gen/ec2" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" - "github.com/mitchellh/goamz/ec2" ) func resourceAwsVpc() *schema.Resource { @@ -57,29 +58,33 @@ func resourceAwsVpc() *schema.Resource { Computed: true, }, - "tags": tagsSchema(), + // "tags": tagsSchema(), }, } } func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn - + ec2conn := meta.(*AWSClient).awsEc2conn + cidr := d.Get("cidr_block").(string) + instance_tenancy := "default" + if v := d.Get("instance_tenancy"); v != nil { + instance_tenancy = v.(string) + } // Create the VPC - createOpts := &ec2.CreateVpc{ - CidrBlock: d.Get("cidr_block").(string), - InstanceTenancy: d.Get("instance_tenancy").(string), + createOpts := &ec2.CreateVPCRequest{ + CIDRBlock: &cidr, + InstanceTenancy: &instance_tenancy, } log.Printf("[DEBUG] VPC create config: %#v", createOpts) - vpcResp, err := ec2conn.CreateVpc(createOpts) + vpcResp, err := ec2conn.CreateVPC(createOpts) if err != nil { return fmt.Errorf("Error creating VPC: %s", err) } // Get the ID and store it - vpc := &vpcResp.VPC - log.Printf("[INFO] VPC ID: %s", vpc.VpcId) - d.SetId(vpc.VpcId) + vpc := vpcResp.VPC + d.SetId(*vpc.VPCID) + log.Printf("[INFO] VPC ID: %s", d.Id()) // Set partial mode and say that we setup the cidr block d.Partial(true) @@ -106,7 +111,7 @@ func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error { } func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn + ec2conn := meta.(*AWSClient).awsEc2conn // Refresh the VPC state vpcRaw, _, err := VPCStateRefreshFunc(ec2conn, d.Id())() @@ -120,34 +125,53 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { // VPC stuff vpc := vpcRaw.(*ec2.VPC) - d.Set("cidr_block", vpc.CidrBlock) + vpcid := d.Id() + d.Set("cidr_block", vpc.CIDRBlock) - // Tags - d.Set("tags", tagsToMap(vpc.Tags)) + // Tags - TBD rmenn + //d.Set("tags", tagsToMap(vpc.Tags)) // Attributes - resp, err := ec2conn.VpcAttribute(d.Id(), "enableDnsSupport") + attribute := "enableDnsSupport" + DescribeAttrOpts := &ec2.DescribeVPCAttributeRequest{ + Attribute: &attribute, + VPCID: &vpcid, + } + resp, err := ec2conn.DescribeVPCAttribute(DescribeAttrOpts) if err != nil { return err } - d.Set("enable_dns_support", resp.EnableDnsSupport) - - resp, err = ec2conn.VpcAttribute(d.Id(), "enableDnsHostnames") + d.Set("enable_dns_support", *resp.EnableDNSSupport) + attribute = "enableDnsHostnames" + DescribeAttrOpts = &ec2.DescribeVPCAttributeRequest{ + Attribute: &attribute, + VPCID: &vpcid, + } + resp, err = ec2conn.DescribeVPCAttribute(DescribeAttrOpts) if err != nil { return err } - d.Set("enable_dns_hostnames", resp.EnableDnsHostnames) + d.Set("enable_dns_hostnames", *resp.EnableDNSHostnames) // Get the main routing table for this VPC - filter := ec2.NewFilter() - filter.Add("association.main", "true") - filter.Add("vpc-id", d.Id()) - routeResp, err := ec2conn.DescribeRouteTables(nil, filter) + // Really Ugly need to make this better - rmenn + filter1 := &ec2.Filter{ + Name: awsGo.String("association.main"), + Values: []string{("true")}, + } + filter2 := &ec2.Filter{ + Name: awsGo.String("VPCID"), + Values: []string{(d.Id())}, + } + DescribeRouteOpts := &ec2.DescribeRouteTablesRequest{ + Filters: []ec2.Filter{*filter1, *filter2}, + } + routeResp, err := ec2conn.DescribeRouteTables(DescribeRouteOpts) if err != nil { return err } if v := routeResp.RouteTables; len(v) > 0 { - d.Set("main_route_table_id", v[0].RouteTableId) + d.Set("main_route_table_id", *v[0].RouteTableID) } resourceAwsVpcSetDefaultNetworkAcl(ec2conn, d) From 06b2d0bbf61c5a0810747e14aad99e45fd744466 Mon Sep 17 00:00:00 2001 From: Rahul Menon Date: Wed, 25 Feb 2015 17:34:27 +0530 Subject: [PATCH 3/7] VPC Refactor --- builtin/providers/aws/resource_aws_vpc.go | 101 ++++++++++++++-------- 1 file changed, 64 insertions(+), 37 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index 496096106..153eda29a 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -181,20 +181,24 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { } func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn + ec2conn := meta.(*AWSClient).awsEc2conn // Turn on partial mode d.Partial(true) - + vpcid := d.Id() + modifyOpts := &ec2.ModifyVPCAttributeRequest{ + VPCID: &vpcid, + } if d.HasChange("enable_dns_hostnames") { - options := new(ec2.ModifyVpcAttribute) - options.EnableDnsHostnames = d.Get("enable_dns_hostnames").(bool) - options.SetEnableDnsHostnames = true + val := d.Get("enable_dns_hostnames").(bool) + modifyOpts.EnableDNSHostnames = &ec2.AttributeBooleanValue{ + Value: &val, + } log.Printf( "[INFO] Modifying enable_dns_hostnames vpc attribute for %s: %#v", - d.Id(), options) - if _, err := ec2conn.ModifyVpcAttribute(d.Id(), options); err != nil { + d.Id(), modifyOpts) + if err := ec2conn.ModifyVPCAttribute(modifyOpts); err != nil { return err } @@ -202,36 +206,40 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error { } if d.HasChange("enable_dns_support") { - options := new(ec2.ModifyVpcAttribute) - options.EnableDnsSupport = d.Get("enable_dns_support").(bool) - options.SetEnableDnsSupport = true + val := d.Get("enable_dns_hostnames").(bool) + modifyOpts.EnableDNSSupport = &ec2.AttributeBooleanValue{ + Value: &val, + } log.Printf( "[INFO] Modifying enable_dns_support vpc attribute for %s: %#v", - d.Id(), options) - if _, err := ec2conn.ModifyVpcAttribute(d.Id(), options); err != nil { + d.Id(), modifyOpts) + if err := ec2conn.ModifyVPCAttribute(modifyOpts); err != nil { return err } d.SetPartial("enable_dns_support") } - - if err := setTags(ec2conn, d); err != nil { - return err - } else { - d.SetPartial("tags") - } + //Tagging Support need to be worked on - rmenn + // if err := setTags(ec2conn, d); err != nil { + // return err + // } else { + // d.SetPartial("tags") + // } d.Partial(false) return resourceAwsVpcRead(d, meta) } func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn - + ec2conn := meta.(*AWSClient).awsEc2conn + vpcID := d.Id() + DeleteVpcOpts := &ec2.DeleteVPCRequest{ + VPCID: &vpcID, + } log.Printf("[INFO] Deleting VPC: %s", d.Id()) - if _, err := ec2conn.DeleteVpc(d.Id()); err != nil { - ec2err, ok := err.(*ec2.Error) + if err := ec2conn.DeleteVPC(DeleteVpcOpts); err != nil { + ec2err, ok := err.(*awsGo.APIError) if ok && ec2err.Code == "InvalidVpcID.NotFound" { return nil } @@ -246,9 +254,12 @@ func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error { // a VPC. func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { - resp, err := conn.DescribeVpcs([]string{id}, ec2.NewFilter()) + DescribeVpcOpts := &ec2.DescribeVPCsRequest{ + VPCIDs: []string{id}, + } + resp, err := conn.DescribeVPCs(DescribeVpcOpts) if err != nil { - if ec2err, ok := err.(*ec2.Error); ok && ec2err.Code == "InvalidVpcID.NotFound" { + if ec2err, ok := err.(*awsGo.APIError); ok && ec2err.Code == "InvalidVpcID.NotFound" { resp = nil } else { log.Printf("Error on VPCStateRefresh: %s", err) @@ -263,37 +274,53 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { } vpc := &resp.VPCs[0] - return vpc, vpc.State, nil + return vpc, *vpc.State, nil } } func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) error { - filter := ec2.NewFilter() - filter.Add("default", "true") - filter.Add("vpc-id", d.Id()) - networkAclResp, err := conn.NetworkAcls(nil, filter) + filter1 := &ec2.Filter{ + Name: awsGo.String("default"), + Values: []string{("true")}, + } + filter2 := &ec2.Filter{ + Name: awsGo.String("vpc-id"), + Values: []string{(d.Id())}, + } + DescribeNetworkACLOpts := &ec2.DescribeNetworkACLsRequest{ + Filters: []ec2.Filter{*filter1, *filter2}, + } + networkAclResp, err := conn.DescribeNetworkACLs(DescribeNetworkACLOpts) if err != nil { return err } - if v := networkAclResp.NetworkAcls; len(v) > 0 { - d.Set("default_network_acl_id", v[0].NetworkAclId) + if v := networkAclResp.NetworkACLs; len(v) > 0 { + d.Set("default_network_acl_id", v[0].NetworkACLID) } return nil } func resourceAwsVpcSetDefaultSecurityGroup(conn *ec2.EC2, d *schema.ResourceData) error { - filter := ec2.NewFilter() - filter.Add("group-name", "default") - filter.Add("vpc-id", d.Id()) - securityGroupResp, err := conn.SecurityGroups(nil, filter) + filter1 := &ec2.Filter{ + Name: awsGo.String("group-name"), + Values: []string{("default")}, + } + filter2 := &ec2.Filter{ + Name: awsGo.String("vpc-id"), + Values: []string{(d.Id())}, + } + DescribeSgOpts := &ec2.DescribeSecurityGroupsRequest{ + Filters: []ec2.Filter{*filter1, *filter2}, + } + securityGroupResp, err := conn.DescribeSecurityGroups(DescribeSgOpts) if err != nil { return err } - if v := securityGroupResp.Groups; len(v) > 0 { - d.Set("default_security_group_id", v[0].Id) + if v := securityGroupResp.SecurityGroups; len(v) > 0 { + d.Set("default_security_group_id", v[0].GroupID) } return nil From 89d01b49aba8a48b0b9f58559a02ff4eb1a287fc Mon Sep 17 00:00:00 2001 From: Rahul Menon Date: Mon, 2 Mar 2015 14:21:13 +0530 Subject: [PATCH 4/7] Refactor with Acceptance Tests --- builtin/providers/aws/config.go | 2 +- builtin/providers/aws/resource_aws_vpc.go | 8 +- .../providers/aws/resource_aws_vpc_test.go | 87 ++++++++++--------- 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index 9d324e495..c4d9a09f0 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -81,7 +81,7 @@ func (c *Config) Client() (interface{}, error) { //Check about using us-east-1 for all log.Println("[INFO] Initializing AWS-GO EC2 Connection") - client.awsEc2conn = awsEc2.New(creds, "us-east-1", nil) + client.awsEc2conn = awsEc2.New(creds, c.Region, nil) } if len(errs) > 0 { diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index 153eda29a..d3207dfa7 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -67,7 +67,7 @@ func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error { ec2conn := meta.(*AWSClient).awsEc2conn cidr := d.Get("cidr_block").(string) instance_tenancy := "default" - if v := d.Get("instance_tenancy"); v != nil { + if v, ok := d.GetOk("instance_tenancy"); ok { instance_tenancy = v.(string) } // Create the VPC @@ -75,10 +75,10 @@ func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error { CIDRBlock: &cidr, InstanceTenancy: &instance_tenancy, } - log.Printf("[DEBUG] VPC create config: %#v", createOpts) + log.Printf("[DEBUG] VPC create config: %#v", *createOpts) vpcResp, err := ec2conn.CreateVPC(createOpts) if err != nil { - return fmt.Errorf("Error creating VPC: %s", err) + return fmt.Errorf("Error creating VPC: %s : %s", err) } // Get the ID and store it @@ -160,7 +160,7 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { Values: []string{("true")}, } filter2 := &ec2.Filter{ - Name: awsGo.String("VPCID"), + Name: awsGo.String("vpc-id"), Values: []string{(d.Id())}, } DescribeRouteOpts := &ec2.DescribeRouteTablesRequest{ diff --git a/builtin/providers/aws/resource_aws_vpc_test.go b/builtin/providers/aws/resource_aws_vpc_test.go index b555e0875..f91d2ac76 100644 --- a/builtin/providers/aws/resource_aws_vpc_test.go +++ b/builtin/providers/aws/resource_aws_vpc_test.go @@ -2,11 +2,11 @@ package aws import ( "fmt" - "testing" - + awsGo "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/gen/ec2" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" - "github.com/mitchellh/goamz/ec2" + "testing" ) func TestAccVpc_basic(t *testing.T) { @@ -50,36 +50,36 @@ func TestAccVpc_dedicatedTenancy(t *testing.T) { }) } -func TestAccVpc_tags(t *testing.T) { - var vpc ec2.VPC - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckVpcDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccVpcConfigTags, - Check: resource.ComposeTestCheckFunc( - testAccCheckVpcExists("aws_vpc.foo", &vpc), - testAccCheckVpcCidr(&vpc, "10.1.0.0/16"), - resource.TestCheckResourceAttr( - "aws_vpc.foo", "cidr_block", "10.1.0.0/16"), - testAccCheckTags(&vpc.Tags, "foo", "bar"), - ), - }, - - resource.TestStep{ - Config: testAccVpcConfigTagsUpdate, - Check: resource.ComposeTestCheckFunc( - testAccCheckVpcExists("aws_vpc.foo", &vpc), - testAccCheckTags(&vpc.Tags, "foo", ""), - testAccCheckTags(&vpc.Tags, "bar", "baz"), - ), - }, - }, - }) -} +//func TestAccVpc_tags(t *testing.T) { +// var vpc ec2.VPC +// +// resource.Test(t, resource.TestCase{ +// PreCheck: func() { testAccPreCheck(t) }, +// Providers: testAccProviders, +// CheckDestroy: testAccCheckVpcDestroy, +// Steps: []resource.TestStep{ +// resource.TestStep{ +// Config: testAccVpcConfigTags, +// Check: resource.ComposeTestCheckFunc( +// testAccCheckVpcExists("aws_vpc.foo", &vpc), +// testAccCheckVpcCidr(&vpc, "10.1.0.0/16"), +// resource.TestCheckResourceAttr( +// "aws_vpc.foo", "cidr_block", "10.1.0.0/16"), +// testAccCheckTags(&vpc.Tags, "foo", "bar"), +// ), +// }, +// +// resource.TestStep{ +// Config: testAccVpcConfigTagsUpdate, +// Check: resource.ComposeTestCheckFunc( +// testAccCheckVpcExists("aws_vpc.foo", &vpc), +// testAccCheckTags(&vpc.Tags, "foo", ""), +// testAccCheckTags(&vpc.Tags, "bar", "baz"), +// ), +// }, +// }, +// }) +//} func TestAccVpcUpdate(t *testing.T) { var vpc ec2.VPC @@ -111,7 +111,7 @@ func TestAccVpcUpdate(t *testing.T) { } func testAccCheckVpcDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).ec2conn + conn := testAccProvider.Meta().(*AWSClient).awsEc2conn for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc" { @@ -119,7 +119,10 @@ func testAccCheckVpcDestroy(s *terraform.State) error { } // Try to find the VPC - resp, err := conn.DescribeVpcs([]string{rs.Primary.ID}, ec2.NewFilter()) + DescribeVpcOpts := &ec2.DescribeVPCsRequest{ + VPCIDs: []string{rs.Primary.ID}, + } + resp, err := conn.DescribeVPCs(DescribeVpcOpts) if err == nil { if len(resp.VPCs) > 0 { return fmt.Errorf("VPCs still exist.") @@ -129,7 +132,7 @@ func testAccCheckVpcDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(*ec2.Error) + ec2err, ok := err.(*awsGo.APIError) if !ok { return err } @@ -143,8 +146,9 @@ func testAccCheckVpcDestroy(s *terraform.State) error { func testAccCheckVpcCidr(vpc *ec2.VPC, expected string) resource.TestCheckFunc { return func(s *terraform.State) error { - if vpc.CidrBlock != expected { - return fmt.Errorf("Bad cidr: %s", vpc.CidrBlock) + CIDRBlock := vpc.CIDRBlock + if *CIDRBlock != expected { + return fmt.Errorf("Bad cidr: %s", *vpc.CIDRBlock) } return nil @@ -162,8 +166,11 @@ func testAccCheckVpcExists(n string, vpc *ec2.VPC) resource.TestCheckFunc { return fmt.Errorf("No VPC ID is set") } - conn := testAccProvider.Meta().(*AWSClient).ec2conn - resp, err := conn.DescribeVpcs([]string{rs.Primary.ID}, ec2.NewFilter()) + conn := testAccProvider.Meta().(*AWSClient).awsEc2conn + DescribeVpcOpts := &ec2.DescribeVPCsRequest{ + VPCIDs: []string{rs.Primary.ID}, + } + resp, err := conn.DescribeVPCs(DescribeVpcOpts) if err != nil { return err } From d77df312a36fefd10ee667e355d327146078d2fe Mon Sep 17 00:00:00 2001 From: Rahul Menon Date: Tue, 3 Mar 2015 10:45:15 +0530 Subject: [PATCH 5/7] Changed things around as suggested by @catsby --- builtin/providers/aws/resource_aws_vpc.go | 21 +++++++++---------- .../providers/aws/resource_aws_vpc_test.go | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index d3207dfa7..6e2ddc95b 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -5,7 +5,7 @@ import ( "log" "time" - awsGo "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/gen/ec2" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -65,14 +65,13 @@ func resourceAwsVpc() *schema.Resource { func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error { ec2conn := meta.(*AWSClient).awsEc2conn - cidr := d.Get("cidr_block").(string) instance_tenancy := "default" if v, ok := d.GetOk("instance_tenancy"); ok { instance_tenancy = v.(string) } // Create the VPC createOpts := &ec2.CreateVPCRequest{ - CIDRBlock: &cidr, + CIDRBlock: aws.String(d.Get("cidr_block").(string)), InstanceTenancy: &instance_tenancy, } log.Printf("[DEBUG] VPC create config: %#v", *createOpts) @@ -156,11 +155,11 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { // Get the main routing table for this VPC // Really Ugly need to make this better - rmenn filter1 := &ec2.Filter{ - Name: awsGo.String("association.main"), + Name: aws.String("association.main"), Values: []string{("true")}, } filter2 := &ec2.Filter{ - Name: awsGo.String("vpc-id"), + Name: aws.String("vpc-id"), Values: []string{(d.Id())}, } DescribeRouteOpts := &ec2.DescribeRouteTablesRequest{ @@ -239,7 +238,7 @@ func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error { } log.Printf("[INFO] Deleting VPC: %s", d.Id()) if err := ec2conn.DeleteVPC(DeleteVpcOpts); err != nil { - ec2err, ok := err.(*awsGo.APIError) + ec2err, ok := err.(*aws.APIError) if ok && ec2err.Code == "InvalidVpcID.NotFound" { return nil } @@ -259,7 +258,7 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { } resp, err := conn.DescribeVPCs(DescribeVpcOpts) if err != nil { - if ec2err, ok := err.(*awsGo.APIError); ok && ec2err.Code == "InvalidVpcID.NotFound" { + if ec2err, ok := err.(*aws.APIError); ok && ec2err.Code == "InvalidVpcID.NotFound" { resp = nil } else { log.Printf("Error on VPCStateRefresh: %s", err) @@ -280,11 +279,11 @@ func VPCStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) error { filter1 := &ec2.Filter{ - Name: awsGo.String("default"), + Name: aws.String("default"), Values: []string{("true")}, } filter2 := &ec2.Filter{ - Name: awsGo.String("vpc-id"), + Name: aws.String("vpc-id"), Values: []string{(d.Id())}, } DescribeNetworkACLOpts := &ec2.DescribeNetworkACLsRequest{ @@ -304,11 +303,11 @@ func resourceAwsVpcSetDefaultNetworkAcl(conn *ec2.EC2, d *schema.ResourceData) e func resourceAwsVpcSetDefaultSecurityGroup(conn *ec2.EC2, d *schema.ResourceData) error { filter1 := &ec2.Filter{ - Name: awsGo.String("group-name"), + Name: aws.String("group-name"), Values: []string{("default")}, } filter2 := &ec2.Filter{ - Name: awsGo.String("vpc-id"), + Name: aws.String("vpc-id"), Values: []string{(d.Id())}, } DescribeSgOpts := &ec2.DescribeSecurityGroupsRequest{ diff --git a/builtin/providers/aws/resource_aws_vpc_test.go b/builtin/providers/aws/resource_aws_vpc_test.go index f91d2ac76..dee441af8 100644 --- a/builtin/providers/aws/resource_aws_vpc_test.go +++ b/builtin/providers/aws/resource_aws_vpc_test.go @@ -2,7 +2,7 @@ package aws import ( "fmt" - awsGo "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/gen/ec2" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -132,7 +132,7 @@ func testAccCheckVpcDestroy(s *terraform.State) error { } // Verify the error is what we want - ec2err, ok := err.(*awsGo.APIError) + ec2err, ok := err.(*aws.APIError) if !ok { return err } From c5efe1e5ce4779c39b566b987b72ad84413f204a Mon Sep 17 00:00:00 2001 From: Rahul Menon Date: Tue, 3 Mar 2015 10:49:21 +0530 Subject: [PATCH 6/7] Using hashicorp/aws-sdk-go --- builtin/providers/aws/config.go | 10 +++++----- builtin/providers/aws/resource_aws_vpc.go | 4 ++-- builtin/providers/aws/resource_aws_vpc_test.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index c4d9a09f0..f603598f3 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -12,11 +12,11 @@ import ( "github.com/mitchellh/goamz/elb" "github.com/mitchellh/goamz/rds" - awsGo "github.com/awslabs/aws-sdk-go/aws" - "github.com/awslabs/aws-sdk-go/gen/autoscaling" - awsEc2 "github.com/awslabs/aws-sdk-go/gen/ec2" - "github.com/awslabs/aws-sdk-go/gen/route53" - "github.com/awslabs/aws-sdk-go/gen/s3" + awsGo "github.com/hashicorp/aws-sdk-go/aws" + "github.com/hashicorp/aws-sdk-go/gen/autoscaling" + awsEc2 "github.com/hashicorp/aws-sdk-go/gen/ec2" + "github.com/hashicorp/aws-sdk-go/gen/route53" + "github.com/hashicorp/aws-sdk-go/gen/s3" ) type Config struct { diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index 6e2ddc95b..4d1d871ba 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -5,8 +5,8 @@ import ( "log" "time" - "github.com/awslabs/aws-sdk-go/aws" - "github.com/awslabs/aws-sdk-go/gen/ec2" + "github.com/hashicorp/aws-sdk-go/aws" + "github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/builtin/providers/aws/resource_aws_vpc_test.go b/builtin/providers/aws/resource_aws_vpc_test.go index dee441af8..7570a1873 100644 --- a/builtin/providers/aws/resource_aws_vpc_test.go +++ b/builtin/providers/aws/resource_aws_vpc_test.go @@ -2,8 +2,8 @@ package aws import ( "fmt" - "github.com/awslabs/aws-sdk-go/aws" - "github.com/awslabs/aws-sdk-go/gen/ec2" + "github.com/hashicorp/aws-sdk-go/aws" + "github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "testing" From d56c683602ace8799ff6f58f3d13da43a56d657a Mon Sep 17 00:00:00 2001 From: rmenn Date: Tue, 3 Mar 2015 20:57:30 +0530 Subject: [PATCH 7/7] Removed additional variable for print, added for debugging --- builtin/providers/aws/resource_aws_vpc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index 4d1d871ba..00c8f6983 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -77,7 +77,7 @@ func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] VPC create config: %#v", *createOpts) vpcResp, err := ec2conn.CreateVPC(createOpts) if err != nil { - return fmt.Errorf("Error creating VPC: %s : %s", err) + return fmt.Errorf("Error creating VPC: %s", err) } // Get the ID and store it