Merge pull request #991 from hashicorp/b-autoscale-lc-update
providers/aws: allow in-place update of launch configuration
This commit is contained in:
commit
e04def93e6
|
@ -29,7 +29,6 @@ func resourceAwsAutoscalingGroup() *schema.Resource {
|
||||||
"launch_configuration": &schema.Schema{
|
"launch_configuration": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"desired_capacity": &schema.Schema{
|
"desired_capacity": &schema.Schema{
|
||||||
|
@ -150,17 +149,17 @@ func resourceAwsAutoscalingGroupCreate(d *schema.ResourceData, meta interface{})
|
||||||
autoScalingGroupOpts.SetHealthCheckGracePeriod = true
|
autoScalingGroupOpts.SetHealthCheckGracePeriod = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("load_balancers"); ok {
|
if v, ok := d.GetOk("load_balancers"); ok && v.(*schema.Set).Len() > 0 {
|
||||||
autoScalingGroupOpts.LoadBalancerNames = expandStringList(
|
autoScalingGroupOpts.LoadBalancerNames = expandStringList(
|
||||||
v.(*schema.Set).List())
|
v.(*schema.Set).List())
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("vpc_zone_identifier"); ok {
|
if v, ok := d.GetOk("vpc_zone_identifier"); ok && v.(*schema.Set).Len() > 0 {
|
||||||
autoScalingGroupOpts.VPCZoneIdentifier = expandStringList(
|
autoScalingGroupOpts.VPCZoneIdentifier = expandStringList(
|
||||||
v.(*schema.Set).List())
|
v.(*schema.Set).List())
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := d.GetOk("termination_policies"); ok {
|
if v, ok := d.GetOk("termination_policies"); ok && v.(*schema.Set).Len() > 0 {
|
||||||
autoScalingGroupOpts.TerminationPolicies = expandStringList(
|
autoScalingGroupOpts.TerminationPolicies = expandStringList(
|
||||||
v.(*schema.Set).List())
|
v.(*schema.Set).List())
|
||||||
}
|
}
|
||||||
|
@ -214,6 +213,10 @@ func resourceAwsAutoscalingGroupUpdate(d *schema.ResourceData, meta interface{})
|
||||||
opts.SetDesiredCapacity = true
|
opts.SetDesiredCapacity = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if d.HasChange("launch_configuration") {
|
||||||
|
opts.LaunchConfigurationName = d.Get("launch_configuration").(string)
|
||||||
|
}
|
||||||
|
|
||||||
if d.HasChange("min_size") {
|
if d.HasChange("min_size") {
|
||||||
opts.MinSize = d.Get("min_size").(int)
|
opts.MinSize = d.Get("min_size").(int)
|
||||||
opts.SetMinSize = true
|
opts.SetMinSize = true
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
func TestAccAWSAutoScalingGroup_basic(t *testing.T) {
|
func TestAccAWSAutoScalingGroup_basic(t *testing.T) {
|
||||||
var group autoscaling.AutoScalingGroup
|
var group autoscaling.AutoScalingGroup
|
||||||
|
var lc autoscaling.LaunchConfiguration
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -47,8 +48,11 @@ func TestAccAWSAutoScalingGroup_basic(t *testing.T) {
|
||||||
Config: testAccAWSAutoScalingGroupConfigUpdate,
|
Config: testAccAWSAutoScalingGroupConfigUpdate,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
testAccCheckAWSAutoScalingGroupExists("aws_autoscaling_group.bar", &group),
|
||||||
|
testAccCheckAWSLaunchConfigurationExists("aws_launch_configuration.new", &lc),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_autoscaling_group.bar", "desired_capacity", "5"),
|
"aws_autoscaling_group.bar", "desired_capacity", "5"),
|
||||||
|
resource.TestCheckResourceAttrPtr(
|
||||||
|
"aws_autoscaling_group.bar", "launch_configuration", &lc.Name),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -217,6 +221,12 @@ resource "aws_launch_configuration" "foobar" {
|
||||||
instance_type = "t1.micro"
|
instance_type = "t1.micro"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "aws_launch_configuration" "new" {
|
||||||
|
name = "foobarautoscaling-terraform-test-new"
|
||||||
|
image_id = "ami-21f78e11"
|
||||||
|
instance_type = "t1.micro"
|
||||||
|
}
|
||||||
|
|
||||||
resource "aws_autoscaling_group" "bar" {
|
resource "aws_autoscaling_group" "bar" {
|
||||||
availability_zones = ["us-west-2a"]
|
availability_zones = ["us-west-2a"]
|
||||||
name = "foobar3-terraform-test"
|
name = "foobar3-terraform-test"
|
||||||
|
@ -227,7 +237,7 @@ resource "aws_autoscaling_group" "bar" {
|
||||||
desired_capacity = 5
|
desired_capacity = 5
|
||||||
force_delete = true
|
force_delete = true
|
||||||
|
|
||||||
launch_configuration = "${aws_launch_configuration.foobar.name}"
|
launch_configuration = "${aws_launch_configuration.new.name}"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
|
@ -275,6 +275,15 @@ func TestCheckResourceAttr(name, key, value string) TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestCheckResourceAttrPtr is like TestCheckResourceAttr except the
|
||||||
|
// value is a pointer so that it can be updated while the test is running.
|
||||||
|
// It will only be dereferenced at the point this step is run.
|
||||||
|
func TestCheckResourceAttrPtr(name string, key string, value *string) TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
return TestCheckResourceAttr(name, key, *value)(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestT is the interface used to handle the test lifecycle of a test.
|
// TestT is the interface used to handle the test lifecycle of a test.
|
||||||
//
|
//
|
||||||
// Users should just use a *testing.T object, which implements this.
|
// Users should just use a *testing.T object, which implements this.
|
||||||
|
|
|
@ -70,13 +70,14 @@ func (d *ResourceData) GetChange(key string) (interface{}, interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOk returns the data for the given key and whether or not the key
|
// GetOk returns the data for the given key and whether or not the key
|
||||||
// has been set.
|
// has been set to a non-zero value at some point.
|
||||||
//
|
//
|
||||||
// The first result will not necessarilly be nil if the value doesn't exist.
|
// The first result will not necessarilly be nil if the value doesn't exist.
|
||||||
// The second result should be checked to determine this information.
|
// The second result should be checked to determine this information.
|
||||||
func (d *ResourceData) GetOk(key string) (interface{}, bool) {
|
func (d *ResourceData) GetOk(key string) (interface{}, bool) {
|
||||||
r := d.getRaw(key, getSourceSet)
|
r := d.getRaw(key, getSourceSet)
|
||||||
return r.Value, r.Exists && !r.Computed
|
exists := r.Exists && !r.Computed
|
||||||
|
return r.Value, exists
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ResourceData) getRaw(key string, level getSource) getResult {
|
func (d *ResourceData) getRaw(key string, level getSource) getResult {
|
||||||
|
@ -361,11 +362,13 @@ func (d *ResourceData) get(addr []string, source getSource) getResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the result doesn't exist, then we set the value to the zero value
|
// If the result doesn't exist, then we set the value to the zero value
|
||||||
if result.Value == nil {
|
var schema *Schema
|
||||||
if schemaL := addrToSchema(addr, d.schema); len(schemaL) > 0 {
|
if schemaL := addrToSchema(addr, d.schema); len(schemaL) > 0 {
|
||||||
schema := schemaL[len(schemaL)-1]
|
schema = schemaL[len(schemaL)-1]
|
||||||
result.Value = result.ValueOrZero(schema)
|
}
|
||||||
}
|
|
||||||
|
if result.Value == nil && schema != nil {
|
||||||
|
result.Value = result.ValueOrZero(schema)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform the FieldReadResult into a getResult. It might be worth
|
// Transform the FieldReadResult into a getResult. It might be worth
|
||||||
|
@ -375,5 +378,6 @@ func (d *ResourceData) get(addr []string, source getSource) getResult {
|
||||||
ValueProcessed: result.ValueProcessed,
|
ValueProcessed: result.ValueProcessed,
|
||||||
Computed: result.Computed,
|
Computed: result.Computed,
|
||||||
Exists: result.Exists,
|
Exists: result.Exists,
|
||||||
|
Schema: schema,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue