provider/aws: switch to helper for LC names

This commit is contained in:
Paul Hinze 2015-04-22 12:53:47 -05:00
parent d1106e9e22
commit 94f703692c

View File

@ -364,16 +364,13 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
createLaunchConfigurationOpts.BlockDeviceMappings = blockDevices createLaunchConfigurationOpts.BlockDeviceMappings = blockDevices
} }
var id string var lcName string
if v, ok := d.GetOk("name"); ok { if v, ok := d.GetOk("name"); ok {
id = v.(string) lcName = v.(string)
} else { } else {
hash := sha1.Sum([]byte(fmt.Sprintf("%#v", createLaunchConfigurationOpts))) lcName = resource.UniqueId()
configName := fmt.Sprintf("terraform-%s", base64.URLEncoding.EncodeToString(hash[:]))
log.Printf("[DEBUG] Computed Launch config name: %s", configName)
id = configName
} }
createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(id) createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(lcName)
log.Printf( log.Printf(
"[DEBUG] autoscaling create launch configuration: %#v", createLaunchConfigurationOpts) "[DEBUG] autoscaling create launch configuration: %#v", createLaunchConfigurationOpts)
@ -382,7 +379,7 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
return fmt.Errorf("Error creating launch configuration: %s", err) return fmt.Errorf("Error creating launch configuration: %s", err)
} }
d.SetId(id) d.SetId(lcName)
log.Printf("[INFO] launch configuration ID: %s", d.Id()) log.Printf("[INFO] launch configuration ID: %s", d.Id())
// We put a Retry here since sometimes eventual consistency bites // We put a Retry here since sometimes eventual consistency bites