Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 6971794

Browse files
feuGeneAshin-
authored andcommitted
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 \ parity-node yields the program output Error with pre-create check: "unable to find a subnet in the zone: us-e ast-1a" 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: F. Eugene Aumson <feuGeneA@github.com>
1 parent 7768a5b commit 6971794

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

‎drivers/amazonec2/amazonec2.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,11 @@ func (d *Driver) getDefaultVPCId() (string, error) {
12351235

12361236
for _, attribute := range output.AccountAttributes {
12371237
if *attribute.AttributeName == "default-vpc" {
1238-
return *attribute.AttributeValues[0].AttributeValue, nil
1238+
value := *attribute.AttributeValues[0].AttributeValue
1239+
if value == "none" {
1240+
return "", errors.New("default-vpc is 'none'")
1241+
}
1242+
return value, nil
12391243
}
12401244
}
12411245

‎drivers/amazonec2/amazonec2_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,31 @@ func TestDefaultVPCIsMissing(t *testing.T) {
227227
assert.Empty(t, vpc)
228228
}
229229

230+
func TestDefaultVPCIsNone(t *testing.T) {
231+
driver := NewDriver("machineFoo", "path")
232+
attributeName := "default-vpc"
233+
vpcName := "none"
234+
driver.clientFactory = func() Ec2Client {
235+
return &fakeEC2WithDescribe{
236+
output: &ec2.DescribeAccountAttributesOutput{
237+
AccountAttributes: []*ec2.AccountAttribute{
238+
{
239+
AttributeName: &attributeName,
240+
AttributeValues: []*ec2.AccountAttributeValue{
241+
{AttributeValue: &vpcName},
242+
},
243+
},
244+
},
245+
},
246+
}
247+
}
248+
249+
vpc, err := driver.getDefaultVPCId()
250+
251+
assert.EqualError(t, err, "default-vpc is 'none'")
252+
assert.Empty(t, vpc)
253+
}
254+
230255
func TestGetRegionZoneForDefaultEndpoint(t *testing.T) {
231256
driver := NewCustomTestDriver(&fakeEC2WithLogin{})
232257
driver.awsCredentialsFactory = NewValidAwsCredentials

0 commit comments

Comments
 (0)