Commit 69717945 authored by Gene's avatar Gene Committed by Joffrey F

amazonec2: correct mis-handling of 'none' VPC

Without this change,

docker-machine create \
    --driver amazonec2 \
    --amazonec2-security-group parity-security-group \
    --amazonec2-instance-type t2.medium \
    --amazonec2-access-key ... \
    --amazonec2-secret-key ... \
    --amazonec2-root-size 128 \

yields the program output

Error with pre-create check: "unable to find a subnet in the zone: us-e

which comes from drivers/amazonec2/amazonec2.go:506.

But that message is misleading.  After sprinkling in some
`fmt.Println`s, I discovered that the missing piece of info is not
actually the subnet, but rather the VPC ID, which is "none".

With this change, that same command now yields:

Error setting machine configuration from flags provided: amazonec2 driv
er requires either the --amazonec2-subnet-id or --amazonec2-vpc-id opti
on or an AWS Account with a default vpc-id
Signed-off-by: default avatarF. Eugene Aumson <[email protected]>
parent 7768a5bd
......@@ -1235,7 +1235,11 @@ func (d *Driver) getDefaultVPCId() (string, error) {
for _, attribute := range output.AccountAttributes {
if *attribute.AttributeName == "default-vpc" {
return *attribute.AttributeValues[0].AttributeValue, nil
value := *attribute.AttributeValues[0].AttributeValue
if value == "none" {
return "", errors.New("default-vpc is 'none'")
return value, nil
......@@ -227,6 +227,31 @@ func TestDefaultVPCIsMissing(t *testing.T) {
assert.Empty(t, vpc)
func TestDefaultVPCIsNone(t *testing.T) {
driver := NewDriver("machineFoo", "path")
attributeName := "default-vpc"
vpcName := "none"
driver.clientFactory = func() Ec2Client {
return &fakeEC2WithDescribe{
output: &ec2.DescribeAccountAttributesOutput{
AccountAttributes: []*ec2.AccountAttribute{
AttributeName: &attributeName,
AttributeValues: []*ec2.AccountAttributeValue{
{AttributeValue: &vpcName},
vpc, err := driver.getDefaultVPCId()
assert.EqualError(t, err, "default-vpc is 'none'")
assert.Empty(t, vpc)
func TestGetRegionZoneForDefaultEndpoint(t *testing.T) {
driver := NewCustomTestDriver(&fakeEC2WithLogin{})
driver.awsCredentialsFactory = NewValidAwsCredentials
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment