Merge pull request #1079 from bobtfish/launch_configuration_computed_names

RFC for making launch configuration names computed.
This commit is contained in:
Paul Hinze 2015-04-02 12:10:22 -05:00
commit f8a699f3d8
2 changed files with 32 additions and 2 deletions

View File

@ -24,7 +24,8 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"name": &schema.Schema{ "name": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Optional: true,
Computed: true,
ForceNew: true, ForceNew: true,
}, },
@ -122,13 +123,23 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
v.(*schema.Set).List()) v.(*schema.Set).List())
} }
if v, ok := d.GetOk("name"); ok {
createLaunchConfigurationOpts.LaunchConfigurationName = aws.String(v.(string))
d.SetId(d.Get("name").(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)
}
log.Printf("[DEBUG] autoscaling create launch configuration: %#v", createLaunchConfigurationOpts) log.Printf("[DEBUG] autoscaling create launch configuration: %#v", createLaunchConfigurationOpts)
err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts) err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts)
if err != nil { if err != nil {
return fmt.Errorf("Error creating launch configuration: %s", err) return fmt.Errorf("Error creating launch configuration: %s", err)
} }
d.SetId(d.Get("name").(string))
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

View File

@ -45,6 +45,16 @@ func TestAccAWSLaunchConfiguration(t *testing.T) {
"aws_launch_configuration.bar", "spot_price", "0.01"), "aws_launch_configuration.bar", "spot_price", "0.01"),
), ),
}, },
resource.TestStep{
Config: testAccAWSLaunchConfigurationNoNameConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.bar", &conf),
testAccCheckAWSLaunchConfigurationAttributes(&conf),
resource.TestCheckResourceAttr(
"aws_launch_configuration.bar", "name", "terraform-foo"), // FIXME - This should fail?!?!?
),
},
}, },
}) })
} }
@ -153,3 +163,12 @@ resource "aws_launch_configuration" "bar" {
spot_price = "0.01" spot_price = "0.01"
} }
` `
const testAccAWSLaunchConfigurationNoNameConfig = `
resource "aws_launch_configuration" "bar" {
image_id = "ami-21f78e12"
instance_type = "t1.micro"
user_data = "foobar-user-data-change"
associate_public_ip_address = false
}
`