chef-boneyard / chef-provisioning-aws

AWS driver and resources for Chef that uses the AWS SDK
Apache License 2.0
142 stars 121 forks source link

VPC peering - cannot peer to outside VPCs #427

Open keen99 opened 8 years ago

keen99 commented 8 years ago

Attempting to create a aws_vpc_peering_connection to a VPC that's not managed by chef-provisioning (and therefor doesn't have a data bag) results in failure.

had an error: RuntimeError: Chef::Resource::AwsVpc[centraltech] does not exist!

had an error: RuntimeError: Chef::Resource::AwsVpc[vpc-48123462d] does not exist!

These lookups happen here:

https://github.com/chef/chef-provisioning-aws/blob/13e69c444b95aac2f41ee7f0bd307f13bba33734/lib/chef/provider/aws_vpc_peering_connection.rb#L30

and here:

https://github.com/chef/chef-provisioning-aws/blob/13e69c444b95aac2f41ee7f0bd307f13bba33734/lib/chef/provider/aws_vpc_peering_connection.rb#L58-L59

Clearly the intent here is to allow the more friendly vpc "Name" tag to be used to define the peering relationship. That's great....but the actual API just requires a vpc-x123x5 style ID.

PR incoming to support passing real vpc IDs both for new_resource.vpc and new_resource.peer_vpc - in those cases we'll avoid the lookup.

Not sure where to start (and running out of week...) for adding tests to test these cases though.

mar-io commented 8 years ago

I agree that passing the vpc id would be nice but I actually went for a different approach. I just created the data bag myself. Created a json file like so:

{
    "id": "my_vpc_name",
    "reference": {
    "id": "vpc-M2343249"
    },
    "driver_url": "aws::us-east-1"
}

Saved as mydatabag.json. Then:

knife data bag from file aws_vpc mydatabag.json

And I was able to call by my friendly vpc name.

aws_vpc_peering_connection "peer1" do 
  vpc "chef_vpc"
  peer_vpc 'my_vpc_name'
end
keen99 commented 8 years ago

I just created the data bag myself. Created a json file like so:

Great workaround for those who need to do this but cant/wont run a patched version, thanks!