Skip to content

Commit

Permalink
Fixes #6076 - Adjusts check to allow for instance-id reset on aws_route
Browse files Browse the repository at this point in the history
  • Loading branch information
jrnt30 authored and catsby committed Oct 11, 2016
1 parent e81d06d commit be523d3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions builtin/providers/aws/resource_aws_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,12 @@ func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
var numTargets int
var setTarget string

allowedTargets := []string{
"gateway_id",
"nat_gateway_id",
"instance_id",
"network_interface_id",
"instance_id",
"vpc_peering_connection_id",
}
replaceOpts := &ec2.ReplaceRouteInput{}
Expand All @@ -241,8 +242,18 @@ func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error {
}
}

if numTargets > 1 {
return routeTargetValidationError
switch setTarget {
//instance_id is a special case due to the fact that AWS will "discover" the network_interace_id
//when it creates the route and return that data. In the case of an update, we should ignore the
//existing network_interface_id
case "instance_id":
if numTargets > 2 || (numTargets == 2 && len(d.Get("network_interface_id").(string)) == 0) {
return routeTargetValidationError
}
default:
if numTargets > 1 {
return routeTargetValidationError
}
}

// Formulate ReplaceRouteInput based on the target type
Expand All @@ -264,8 +275,6 @@ func resourceAwsRouteUpdate(d *schema.ResourceData, meta interface{}) error {
RouteTableId: aws.String(d.Get("route_table_id").(string)),
DestinationCidrBlock: aws.String(d.Get("destination_cidr_block").(string)),
InstanceId: aws.String(d.Get("instance_id").(string)),
//NOOP: Ensure we don't blow away network interface id that is set after instance is launched
NetworkInterfaceId: aws.String(d.Get("network_interface_id").(string)),
}
case "network_interface_id":
replaceOpts = &ec2.ReplaceRouteInput{
Expand Down

0 comments on commit be523d3

Please sign in to comment.