From be523d3792a20c75897ba91d5a367b13f3f4833e Mon Sep 17 00:00:00 2001 From: Justin Nauman Date: Fri, 13 May 2016 10:07:54 -0500 Subject: [PATCH] Fixes #6076 - Adjusts check to allow for instance-id reset on aws_route --- builtin/providers/aws/resource_aws_route.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_route.go b/builtin/providers/aws/resource_aws_route.go index 0bcc545fd..965680d1c 100644 --- a/builtin/providers/aws/resource_aws_route.go +++ b/builtin/providers/aws/resource_aws_route.go @@ -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{} @@ -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 @@ -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{