From f7a2f2a2e7f482829300ab7fbd279e153495db2a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 13 Apr 2015 17:03:13 -0700 Subject: [PATCH 1/2] providers/aws: set ID after creation --- .../aws/resource_aws_launch_configuration.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/builtin/providers/aws/resource_aws_launch_configuration.go b/builtin/providers/aws/resource_aws_launch_configuration.go index a136f4ea3..87ee85f32 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration.go +++ b/builtin/providers/aws/resource_aws_launch_configuration.go @@ -364,23 +364,26 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface createLaunchConfigurationOpts.BlockDeviceMappings = blockDevices } + var id string if v, ok := d.GetOk("name"); ok { createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(v.(string)) - d.SetId(d.Get("name").(string)) + id = v.(string) } else { hash := sha1.Sum([]byte(fmt.Sprintf("%#v", createLaunchConfigurationOpts))) - config_name := fmt.Sprintf("terraform-%s", base64.URLEncoding.EncodeToString(hash[:])) - log.Printf("[DEBUG] Computed Launch config name: %s", config_name) - createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(config_name) - d.SetId(config_name) + configName := fmt.Sprintf("terraform-%s", base64.URLEncoding.EncodeToString(hash[:])) + log.Printf("[DEBUG] Computed Launch config name: %s", configName) + createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(configName) + id = configName } - log.Printf("[DEBUG] autoscaling create launch configuration: %#v", createLaunchConfigurationOpts) + log.Printf( + "[DEBUG] autoscaling create launch configuration: %#v", createLaunchConfigurationOpts) err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts) if err != nil { return fmt.Errorf("Error creating launch configuration: %s", err) } + d.SetId(id) log.Printf("[INFO] launch configuration ID: %s", d.Id()) // We put a Retry here since sometimes eventual consistency bites From 783d912b7c090b8391cbec0ad723be582702efe5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 14 Apr 2015 08:23:16 -0700 Subject: [PATCH 2/2] providers/aws: set id outside if/esle --- builtin/providers/aws/resource_aws_launch_configuration.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_launch_configuration.go b/builtin/providers/aws/resource_aws_launch_configuration.go index 87ee85f32..a7e45ae27 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration.go +++ b/builtin/providers/aws/resource_aws_launch_configuration.go @@ -366,15 +366,14 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface var id string if v, ok := d.GetOk("name"); ok { - createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(v.(string)) id = v.(string) } else { hash := sha1.Sum([]byte(fmt.Sprintf("%#v", createLaunchConfigurationOpts))) configName := fmt.Sprintf("terraform-%s", base64.URLEncoding.EncodeToString(hash[:])) log.Printf("[DEBUG] Computed Launch config name: %s", configName) - createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(configName) id = configName } + createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(id) log.Printf( "[DEBUG] autoscaling create launch configuration: %#v", createLaunchConfigurationOpts)