Skip to content

Commit

Permalink
Fix route table importing to avoid route deletion
Browse files Browse the repository at this point in the history
Import route tables using inline routes in the resource data. This
is the same way resource data is structured when routes tables are
read (and created) which enables imports to line up properly with
existing resources.

Previously, if you applied a state that included the import of a
route table, all routes in the route table would be deleted. This
bug occurred because the import function
(resourceAwsRouteTableImportState()) would return a target state
including both a route table resource and separate route resources
for each route. The route table read function
(resourceAwsRouteTableRead()) returns a state with a route table
resource having inline routes. Despite being equivalent, since the
states did not match, Terraform would delete all routes in the
route table when applying the change plan.

Fixes hashicorp#5631

Update functions names to comply with convention

This commit is planned to occur after PR hashicorp#5687 which changes the
names of these functions. In order to avoid merge conflicts at that
time, this pre-emptively renames the functions.
  • Loading branch information
YakDriver committed Dec 26, 2018
1 parent 6cb94d4 commit 3f472eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 108 deletions.
107 changes: 0 additions & 107 deletions aws/import_aws_route_table.go

This file was deleted.

13 changes: 12 additions & 1 deletion aws/resource_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@ func resourceAwsRouteTable() *schema.Resource {
Update: resourceAwsRouteTableUpdate,
Delete: resourceAwsRouteTableDelete,
Importer: &schema.ResourceImporter{
State: resourceAwsRouteTableImportState,
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
log.Printf("[INFO] Importing Route Table ID: %s", d.Id())

err := resourceAwsRouteTableRead(d, meta)
if err != nil {
return nil, err
}

results := make([]*schema.ResourceData, 1)
results[0] = d
return results, nil
},
},

Schema: map[string]*schema.Schema{
Expand Down

0 comments on commit 3f472eb

Please sign in to comment.