provider/aws: Convert Route table and Route table association to upstream aws-sdk-go

This commit is contained in:
Clint Shryock 2015-04-10 17:09:36 -05:00
parent 56836c236f
commit c89470a754
4 changed files with 58 additions and 58 deletions

View File

@ -6,8 +6,8 @@ import (
"log" "log"
"time" "time"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -62,15 +62,15 @@ func resourceAwsRouteTable() *schema.Resource {
} }
func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
// Create the routing table // Create the routing table
createOpts := &ec2.CreateRouteTableRequest{ createOpts := &ec2.CreateRouteTableInput{
VPCID: aws.String(d.Get("vpc_id").(string)), VPCID: aws.String(d.Get("vpc_id").(string)),
} }
log.Printf("[DEBUG] RouteTable create config: %#v", createOpts) log.Printf("[DEBUG] RouteTable create config: %#v", createOpts)
resp, err := ec2conn.CreateRouteTable(createOpts) resp, err := conn.CreateRouteTable(createOpts)
if err != nil { if err != nil {
return fmt.Errorf("Error creating route table: %s", err) return fmt.Errorf("Error creating route table: %s", err)
} }
@ -87,7 +87,7 @@ func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error
stateConf := &resource.StateChangeConf{ stateConf := &resource.StateChangeConf{
Pending: []string{"pending"}, Pending: []string{"pending"},
Target: "ready", Target: "ready",
Refresh: resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id()), Refresh: resourceAwsRouteTableStateRefreshFunc(conn, d.Id()),
Timeout: 1 * time.Minute, Timeout: 1 * time.Minute,
} }
if _, err := stateConf.WaitForState(); err != nil { if _, err := stateConf.WaitForState(); err != nil {
@ -100,9 +100,9 @@ func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error
} }
func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id())() rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(conn, d.Id())()
if err != nil { if err != nil {
return err return err
} }
@ -147,13 +147,13 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
d.Set("route", route) d.Set("route", route)
// Tags // Tags
d.Set("tags", tagsToMap(rt.Tags)) d.Set("tags", tagsToMapSDK(rt.Tags))
return nil return nil
} }
func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
// Check if the route set as a whole has changed // Check if the route set as a whole has changed
if d.HasChange("route") { if d.HasChange("route") {
@ -169,7 +169,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
log.Printf( log.Printf(
"[INFO] Deleting route from %s: %s", "[INFO] Deleting route from %s: %s",
d.Id(), m["cidr_block"].(string)) d.Id(), m["cidr_block"].(string))
err := ec2conn.DeleteRoute(&ec2.DeleteRouteRequest{ _, err := conn.DeleteRoute(&ec2.DeleteRouteInput{
RouteTableID: aws.String(d.Id()), RouteTableID: aws.String(d.Id()),
DestinationCIDRBlock: aws.String(m["cidr_block"].(string)), DestinationCIDRBlock: aws.String(m["cidr_block"].(string)),
}) })
@ -186,7 +186,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
for _, route := range nrs.List() { for _, route := range nrs.List() {
m := route.(map[string]interface{}) m := route.(map[string]interface{})
opts := ec2.CreateRouteRequest{ opts := ec2.CreateRouteInput{
RouteTableID: aws.String(d.Id()), RouteTableID: aws.String(d.Id()),
DestinationCIDRBlock: aws.String(m["cidr_block"].(string)), DestinationCIDRBlock: aws.String(m["cidr_block"].(string)),
GatewayID: aws.String(m["gateway_id"].(string)), GatewayID: aws.String(m["gateway_id"].(string)),
@ -195,7 +195,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
} }
log.Printf("[INFO] Creating route for %s: %#v", d.Id(), opts) log.Printf("[INFO] Creating route for %s: %#v", d.Id(), opts)
if err := ec2conn.CreateRoute(&opts); err != nil { if _, err := conn.CreateRoute(&opts); err != nil {
return err return err
} }
@ -204,7 +204,7 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
} }
} }
if err := setTags(ec2conn, d); err != nil { if err := setTagsSDK(conn, d); err != nil {
return err return err
} else { } else {
d.SetPartial("tags") d.SetPartial("tags")
@ -214,11 +214,11 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
} }
func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error { func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
// First request the routing table since we'll have to disassociate // First request the routing table since we'll have to disassociate
// all the subnets first. // all the subnets first.
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id())() rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(conn, d.Id())()
if err != nil { if err != nil {
return err return err
} }
@ -230,7 +230,7 @@ func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error
// Do all the disassociations // Do all the disassociations
for _, a := range rt.Associations { for _, a := range rt.Associations {
log.Printf("[INFO] Disassociating association: %s", *a.RouteTableAssociationID) log.Printf("[INFO] Disassociating association: %s", *a.RouteTableAssociationID)
err := ec2conn.DisassociateRouteTable(&ec2.DisassociateRouteTableRequest{ _, err := conn.DisassociateRouteTable(&ec2.DisassociateRouteTableInput{
AssociationID: a.RouteTableAssociationID, AssociationID: a.RouteTableAssociationID,
}) })
if err != nil { if err != nil {
@ -240,7 +240,7 @@ func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error
// Delete the route table // Delete the route table
log.Printf("[INFO] Deleting Route Table: %s", d.Id()) log.Printf("[INFO] Deleting Route Table: %s", d.Id())
err = ec2conn.DeleteRouteTable(&ec2.DeleteRouteTableRequest{ _, err = conn.DeleteRouteTable(&ec2.DeleteRouteTableInput{
RouteTableID: aws.String(d.Id()), RouteTableID: aws.String(d.Id()),
}) })
if err != nil { if err != nil {
@ -260,7 +260,7 @@ func resourceAwsRouteTableDelete(d *schema.ResourceData, meta interface{}) error
stateConf := &resource.StateChangeConf{ stateConf := &resource.StateChangeConf{
Pending: []string{"ready"}, Pending: []string{"ready"},
Target: "", Target: "",
Refresh: resourceAwsRouteTableStateRefreshFunc(ec2conn, d.Id()), Refresh: resourceAwsRouteTableStateRefreshFunc(conn, d.Id()),
Timeout: 1 * time.Minute, Timeout: 1 * time.Minute,
} }
if _, err := stateConf.WaitForState(); err != nil { if _, err := stateConf.WaitForState(); err != nil {
@ -296,8 +296,8 @@ func resourceAwsRouteTableHash(v interface{}) int {
// a RouteTable. // a RouteTable.
func resourceAwsRouteTableStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { func resourceAwsRouteTableStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) { return func() (interface{}, string, error) {
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{ resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
RouteTableIDs: []string{id}, RouteTableIDs: []*string{aws.String(id)},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidRouteTableID.NotFound" { if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidRouteTableID.NotFound" {
@ -314,7 +314,7 @@ func resourceAwsRouteTableStateRefreshFunc(conn *ec2.EC2, id string) resource.St
return nil, "", nil return nil, "", nil
} }
rt := &resp.RouteTables[0] rt := resp.RouteTables[0]
return rt, "ready", nil return rt, "ready", nil
} }
} }

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"log" "log"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -32,14 +32,14 @@ func resourceAwsRouteTableAssociation() *schema.Resource {
} }
func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
log.Printf( log.Printf(
"[INFO] Creating route table association: %s => %s", "[INFO] Creating route table association: %s => %s",
d.Get("subnet_id").(string), d.Get("subnet_id").(string),
d.Get("route_table_id").(string)) d.Get("route_table_id").(string))
resp, err := ec2conn.AssociateRouteTable(&ec2.AssociateRouteTableRequest{ resp, err := conn.AssociateRouteTable(&ec2.AssociateRouteTableInput{
RouteTableID: aws.String(d.Get("route_table_id").(string)), RouteTableID: aws.String(d.Get("route_table_id").(string)),
SubnetID: aws.String(d.Get("subnet_id").(string)), SubnetID: aws.String(d.Get("subnet_id").(string)),
}) })
@ -56,11 +56,11 @@ func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interfa
} }
func resourceAwsRouteTableAssociationRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsRouteTableAssociationRead(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
// Get the routing table that this association belongs to // Get the routing table that this association belongs to
rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc( rtRaw, _, err := resourceAwsRouteTableStateRefreshFunc(
ec2conn, d.Get("route_table_id").(string))() conn, d.Get("route_table_id").(string))()
if err != nil { if err != nil {
return err return err
} }
@ -88,18 +88,18 @@ func resourceAwsRouteTableAssociationRead(d *schema.ResourceData, meta interface
} }
func resourceAwsRouteTableAssociationUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAwsRouteTableAssociationUpdate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
log.Printf( log.Printf(
"[INFO] Creating route table association: %s => %s", "[INFO] Creating route table association: %s => %s",
d.Get("subnet_id").(string), d.Get("subnet_id").(string),
d.Get("route_table_id").(string)) d.Get("route_table_id").(string))
req := &ec2.ReplaceRouteTableAssociationRequest{ req := &ec2.ReplaceRouteTableAssociationInput{
AssociationID: aws.String(d.Id()), AssociationID: aws.String(d.Id()),
RouteTableID: aws.String(d.Get("route_table_id").(string)), RouteTableID: aws.String(d.Get("route_table_id").(string)),
} }
resp, err := ec2conn.ReplaceRouteTableAssociation(req) resp, err := conn.ReplaceRouteTableAssociation(req)
if err != nil { if err != nil {
ec2err, ok := err.(aws.APIError) ec2err, ok := err.(aws.APIError)
@ -119,10 +119,10 @@ func resourceAwsRouteTableAssociationUpdate(d *schema.ResourceData, meta interfa
} }
func resourceAwsRouteTableAssociationDelete(d *schema.ResourceData, meta interface{}) error { func resourceAwsRouteTableAssociationDelete(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
log.Printf("[INFO] Deleting route table association: %s", d.Id()) log.Printf("[INFO] Deleting route table association: %s", d.Id())
err := ec2conn.DisassociateRouteTable(&ec2.DisassociateRouteTableRequest{ _, err := conn.DisassociateRouteTable(&ec2.DisassociateRouteTableInput{
AssociationID: aws.String(d.Id()), AssociationID: aws.String(d.Id()),
}) })
if err != nil { if err != nil {

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -38,7 +38,7 @@ func TestAccAWSRouteTableAssociation(t *testing.T) {
} }
func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error { func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route_table_association" { if rs.Type != "aws_route_table_association" {
@ -46,8 +46,8 @@ func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error {
} }
// Try to find the resource // Try to find the resource
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{ resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
RouteTableIDs: []string{rs.Primary.Attributes["route_table_id"]}, RouteTableIDs: []*string{aws.String(rs.Primary.Attributes["route_table_id"])},
}) })
if err != nil { if err != nil {
// Verify the error is what we want // Verify the error is what we want
@ -83,9 +83,9 @@ func testAccCheckRouteTableAssociationExists(n string, v *ec2.RouteTable) resour
return fmt.Errorf("No ID is set") return fmt.Errorf("No ID is set")
} }
conn := testAccProvider.Meta().(*AWSClient).ec2conn conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{ resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
RouteTableIDs: []string{rs.Primary.Attributes["route_table_id"]}, RouteTableIDs: []*string{aws.String(rs.Primary.Attributes["route_table_id"])},
}) })
if err != nil { if err != nil {
return err return err
@ -94,7 +94,7 @@ func testAccCheckRouteTableAssociationExists(n string, v *ec2.RouteTable) resour
return fmt.Errorf("RouteTable not found") return fmt.Errorf("RouteTable not found")
} }
*v = resp.RouteTables[0] *v = *resp.RouteTables[0]
if len(v.Associations) == 0 { if len(v.Associations) == 0 {
return fmt.Errorf("no associations") return fmt.Errorf("no associations")

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -18,7 +18,7 @@ func TestAccAWSRouteTable_normal(t *testing.T) {
return fmt.Errorf("bad routes: %#v", v.Routes) return fmt.Errorf("bad routes: %#v", v.Routes)
} }
routes := make(map[string]ec2.Route) routes := make(map[string]*ec2.Route)
for _, r := range v.Routes { for _, r := range v.Routes {
routes[*r.DestinationCIDRBlock] = r routes[*r.DestinationCIDRBlock] = r
} }
@ -38,7 +38,7 @@ func TestAccAWSRouteTable_normal(t *testing.T) {
return fmt.Errorf("bad routes: %#v", v.Routes) return fmt.Errorf("bad routes: %#v", v.Routes)
} }
routes := make(map[string]ec2.Route) routes := make(map[string]*ec2.Route)
for _, r := range v.Routes { for _, r := range v.Routes {
routes[*r.DestinationCIDRBlock] = r routes[*r.DestinationCIDRBlock] = r
} }
@ -90,7 +90,7 @@ func TestAccAWSRouteTable_instance(t *testing.T) {
return fmt.Errorf("bad routes: %#v", v.Routes) return fmt.Errorf("bad routes: %#v", v.Routes)
} }
routes := make(map[string]ec2.Route) routes := make(map[string]*ec2.Route)
for _, r := range v.Routes { for _, r := range v.Routes {
routes[*r.DestinationCIDRBlock] = r routes[*r.DestinationCIDRBlock] = r
} }
@ -134,7 +134,7 @@ func TestAccAWSRouteTable_tags(t *testing.T) {
Config: testAccRouteTableConfigTags, Config: testAccRouteTableConfigTags,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists("aws_route_table.foo", &route_table), testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
testAccCheckTags(&route_table.Tags, "foo", "bar"), testAccCheckTagsSDK(&route_table.Tags, "foo", "bar"),
), ),
}, },
@ -142,8 +142,8 @@ func TestAccAWSRouteTable_tags(t *testing.T) {
Config: testAccRouteTableConfigTagsUpdate, Config: testAccRouteTableConfigTagsUpdate,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckRouteTableExists("aws_route_table.foo", &route_table), testAccCheckRouteTableExists("aws_route_table.foo", &route_table),
testAccCheckTags(&route_table.Tags, "foo", ""), testAccCheckTagsSDK(&route_table.Tags, "foo", ""),
testAccCheckTags(&route_table.Tags, "bar", "baz"), testAccCheckTagsSDK(&route_table.Tags, "bar", "baz"),
), ),
}, },
}, },
@ -151,7 +151,7 @@ func TestAccAWSRouteTable_tags(t *testing.T) {
} }
func testAccCheckRouteTableDestroy(s *terraform.State) error { func testAccCheckRouteTableDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route_table" { if rs.Type != "aws_route_table" {
@ -159,8 +159,8 @@ func testAccCheckRouteTableDestroy(s *terraform.State) error {
} }
// Try to find the resource // Try to find the resource
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{ resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
RouteTableIDs: []string{rs.Primary.ID}, RouteTableIDs: []*string{aws.String(rs.Primary.ID)},
}) })
if err == nil { if err == nil {
if len(resp.RouteTables) > 0 { if len(resp.RouteTables) > 0 {
@ -194,9 +194,9 @@ func testAccCheckRouteTableExists(n string, v *ec2.RouteTable) resource.TestChec
return fmt.Errorf("No ID is set") return fmt.Errorf("No ID is set")
} }
conn := testAccProvider.Meta().(*AWSClient).ec2conn conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesRequest{ resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{
RouteTableIDs: []string{rs.Primary.ID}, RouteTableIDs: []*string{aws.String(rs.Primary.ID)},
}) })
if err != nil { if err != nil {
return err return err
@ -205,7 +205,7 @@ func testAccCheckRouteTableExists(n string, v *ec2.RouteTable) resource.TestChec
return fmt.Errorf("RouteTable not found") return fmt.Errorf("RouteTable not found")
} }
*v = resp.RouteTables[0] *v = *resp.RouteTables[0]
return nil return nil
} }
@ -222,7 +222,7 @@ func _TestAccAWSRouteTable_vpcPeering(t *testing.T) {
return fmt.Errorf("bad routes: %#v", v.Routes) return fmt.Errorf("bad routes: %#v", v.Routes)
} }
routes := make(map[string]ec2.Route) routes := make(map[string]*ec2.Route)
for _, r := range v.Routes { for _, r := range v.Routes {
routes[*r.DestinationCIDRBlock] = r routes[*r.DestinationCIDRBlock] = r
} }