Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws:Allow reassignment of EIP instances appropriately #7686

Merged
merged 1 commit into from
Oct 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -219,11 +219,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 @@ -236,8 +237,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 @@ -259,8 +270,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