Fix AWS region vs zone
We were specifying a region, but naming it as a zone in util.sh The zone matters just as much as the region, e.g. for EBS volumes. We also change the config to require a Zone, not a Region. But we fallback to get the information from the metadata service.
This commit is contained in:
parent
8fde691aa7
commit
ffadd5533a
@ -75,7 +75,7 @@ func main() {
|
||||
|
||||
if *provider == "aws" {
|
||||
awsConfig := "[Global]\n"
|
||||
awsConfig += fmt.Sprintf("Region=%s\n", *gceZone)
|
||||
awsConfig += fmt.Sprintf("Zone=%s\n", *gceZone)
|
||||
|
||||
var err error
|
||||
cloudConfig.Provider, err = cloudprovider.GetCloudProvider(*provider, strings.NewReader(awsConfig))
|
||||
|
@ -43,7 +43,6 @@ type EC2 interface {
|
||||
// Query EC2 for instances matching the filter
|
||||
Instances(instIds []string, filter *ec2InstanceFilter) (resp *ec2.InstancesResp, err error)
|
||||
|
||||
|
||||
// Attach a volume to an instance
|
||||
AttachVolume(volumeId string, instanceId string, mountDevice string) (resp *ec2.AttachVolumeResp, err error)
|
||||
// Detach a volume from whatever instance it is attached to
|
||||
@ -241,22 +240,18 @@ func newAWSCloud(config io.Reader, authFunc AuthFunc, instanceId string, metadat
|
||||
|
||||
ec2 := &goamzEC2{ec2: ec2.New(auth, region)}
|
||||
|
||||
if instanceId == "" {
|
||||
instanceIdBytes, err := ec2.GetMetaData("instance-id")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error fetching instance-id from ec2 metadata service: %v", err)
|
||||
}
|
||||
instanceId = string(instanceIdBytes)
|
||||
}
|
||||
|
||||
awsCloud := &AWSCloud{
|
||||
ec2: ec2,
|
||||
cfg: cfg,
|
||||
ec2: ec2,
|
||||
cfg: cfg,
|
||||
region: region,
|
||||
availabilityZone: zone,
|
||||
}
|
||||
|
||||
awsCloud.selfAwsInstance = newAwsInstance(ec2, instanceId)
|
||||
instanceIdBytes, err := metadata.GetMetaData("instance-id")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error fetching instance-id from ec2 metadata service: %v", err)
|
||||
}
|
||||
awsCloud.selfAwsInstance = newAwsInstance(ec2, string(instanceIdBytes))
|
||||
|
||||
return awsCloud, nil
|
||||
}
|
||||
|
@ -178,11 +178,14 @@ func (self *FakeEC2) Instances(instanceIds []string, filter *ec2InstanceFilter)
|
||||
|
||||
type FakeMetadata struct {
|
||||
availabilityZone string
|
||||
instanceId string
|
||||
}
|
||||
|
||||
func (self *FakeMetadata) GetMetaData(key string) ([]byte, error) {
|
||||
if key == "placement/availability-zone" {
|
||||
return []byte(self.availabilityZone), nil
|
||||
} else if key == "instance-id" {
|
||||
return []byte(self.instanceId), nil
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user