Allow launch configuration names to be computed
This allows you to set lifecycle create_before_destroy = true and fixes #532 as then we'll make a new launch config, change the launch config on the ASG, and *then* delete the old launch config. Also tried adding tests which unfortunately don't seem to fail...
This commit is contained in:
parent
f680e9a0f8
commit
09f5935993
|
@ -24,7 +24,8 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
|
|||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
|
@ -122,13 +123,23 @@ func resourceAwsLaunchConfigurationCreate(d *schema.ResourceData, meta interface
|
|||
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)
|
||||
err := autoscalingconn.CreateLaunchConfiguration(&createLaunchConfigurationOpts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating launch configuration: %s", err)
|
||||
}
|
||||
|
||||
d.SetId(d.Get("name").(string))
|
||||
log.Printf("[INFO] launch configuration ID: %s", d.Id())
|
||||
|
||||
// We put a Retry here since sometimes eventual consistency bites
|
||||
|
|
|
@ -45,6 +45,16 @@ func TestAccAWSLaunchConfiguration(t *testing.T) {
|
|||
"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"
|
||||
}
|
||||
`
|
||||
|
||||
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
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue