From 6b7628a175babb84cdc91abcc84a79f4742ab51b Mon Sep 17 00:00:00 2001 From: feelobot Date: Mon, 10 Aug 2015 09:13:14 -0700 Subject: [PATCH] Use SDK to Validate VpcID with SubnetId Signed-off-by: feelobot --- drivers/amazonec2/amazonec2.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/amazonec2/amazonec2.go b/drivers/amazonec2/amazonec2.go index 62e8fe1603..72dd69e82f 100644 --- a/drivers/amazonec2/amazonec2.go +++ b/drivers/amazonec2/amazonec2.go @@ -231,6 +231,24 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { return fmt.Errorf("amazonec2 driver requires either the --amazonec2-subnet-id or --amazonec2-vpc-id option") } + if d.SubnetId != "" && d.VpcId != "" { + filters := []amz.Filter{ + { + Name: "subnet-id", + Value: d.SubnetId, + }, + } + + subnets, err := d.getClient().GetSubnets(filters) + if err != nil { + return err + } + + if subnets[0].VpcId != d.VpcId { + return fmt.Errorf("SubnetId: %s does not belong to VpcId: %s", d.SubnetId, d.VpcId) + } + } + if d.isSwarmMaster() { u, err := url.Parse(d.SwarmHost) if err != nil {