aws: Make EFS MT creation fail for 2+ targets per AZ (#8205)

This commit is contained in:
Radek Simko 2016-08-17 07:07:54 +01:00 committed by GitHub
parent e6d1e77a9a
commit 7433be5b4c
1 changed files with 17 additions and 2 deletions

View File

@ -67,9 +67,24 @@ func resourceAwsEfsMountTarget() *schema.Resource {
func resourceAwsEfsMountTargetCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).efsconn
fsId := d.Get("file_system_id").(string)
subnetId := d.Get("subnet_id").(string)
// CreateMountTarget would return the same Mount Target ID
// to parallel requests if they both include the same AZ
// and we would end up managing the same MT as 2 resources.
// So we make it fail by calling 1 request per AZ at a time.
az, err := getAzFromSubnetId(subnetId, meta.(*AWSClient).ec2conn)
if err != nil {
return fmt.Errorf("Failed getting AZ from subnet ID (%s): %s", subnetId, err)
}
mtKey := "efs-mt-" + fsId + "-" + az
awsMutexKV.Lock(mtKey)
defer awsMutexKV.Unlock(mtKey)
input := efs.CreateMountTargetInput{
FileSystemId: aws.String(d.Get("file_system_id").(string)),
SubnetId: aws.String(d.Get("subnet_id").(string)),
FileSystemId: aws.String(fsId),
SubnetId: aws.String(subnetId),
}
if v, ok := d.GetOk("ip_address"); ok {