Skip to content

Commit

Permalink
Fix PeeringConnection:
Browse files Browse the repository at this point in the history
When we have a vpc that belongs to some other account, we can't lookup it.
  • Loading branch information
joaogbcravo committed Mar 1, 2016
1 parent d5ef16b commit 4461bec
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/chef/provider/aws_vpc_peering_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ def create_aws_object

options = {}
options[:vpc_id] = new_resource.vpc
options[:peer_vpc_id] = new_resource.peer_vpc
options[:peer_owner_id] = new_resource.peer_owner_id unless new_resource.peer_owner_id.nil?
options = AWSResource.lookup_options(options, resource: new_resource)

if new_resource.peer_owner_id.nil?
options[:peer_vpc_id] = new_resource.peer_vpc
options = AWSResource.lookup_options(options, resource: new_resource)
else
options = AWSResource.lookup_options(options, resource: new_resource)
options[:peer_vpc_id] = new_resource.peer_vpc
options[:peer_owner_id] = new_resource.peer_owner_id
end

ec2_resource = new_resource.driver.ec2_resource
vpc = ec2_resource.vpc(options[:vpc_id])
Expand Down Expand Up @@ -56,8 +62,13 @@ def update_aws_object(vpc_peering_connection)
peer_owner_id = vpc_peering_connection.accepter_vpc_info.owner_id

desired_vpc_id = Chef::Resource::AwsVpc.get_aws_object_id(new_resource.vpc, resource: new_resource)
desired_peer_vpc_id = Chef::Resource::AwsVpc.get_aws_object_id(new_resource.peer_vpc, resource: new_resource)
desired_peer_owner_id = new_resource.peer_owner_id
if new_resource.peer_owner_id.nil?
desired_peer_owner_id = new_resource.peer_owner_id
desired_peer_vpc_id = Chef::Resource::AwsVpc.get_aws_object_id(new_resource.peer_vpc, resource: new_resource)
else
desired_peer_vpc_id = new_resource.peer_vpc
desired_peer_owner_id = new_resource.peer_owner_id
end

if desired_vpc_id && vpc_id != desired_vpc_id
raise "VCP peering connection requester vpc cannot be changed after being created! Desired requester vpc id for #{new_resource.name} (#{vpc_peering_connection.id}) was \"#{desired_vpc_id}\" and actual id is \"#{vpc_id}\""
Expand Down

0 comments on commit 4461bec

Please sign in to comment.