provider/aws: Fix issue with disabling source dest check on first run

This commit is contained in:
Clint Shryock 2015-10-01 17:00:30 -05:00
parent 0c3f2a915c
commit efa26ed2a7
2 changed files with 20 additions and 15 deletions

View File

@ -414,11 +414,6 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
})
}
// Set our attributes
if err := resourceAwsInstanceRead(d, meta); err != nil {
return err
}
// Update if we need to
return resourceAwsInstanceUpdate(d, meta)
}
@ -548,7 +543,8 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
}
// SourceDestCheck can only be set on VPC instances
if d.Get("subnet_id").(string) != "" {
// AWS will return an error of InvalidParameterCombination if we attempt
// to modify the source_dest_check of an instance in EC2 Classic
log.Printf("[INFO] Modifying instance %s", d.Id())
_, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
InstanceId: aws.String(d.Id()),
@ -557,8 +553,14 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
},
})
if err != nil {
if ec2err, ok := err.(awserr.Error); ok {
// Toloerate InvalidParameterCombination error in Classic, otherwise
// return the error
if "InvalidParameterCombination" != ec2err.Code() {
return err
}
log.Printf("[WARN] Attempted to modify SourceDestCheck on non VPC instance: %s", ec2err.Message())
}
}
if d.HasChange("vpc_security_group_ids") {

View File

@ -190,6 +190,9 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
testCheck := func(enabled bool) resource.TestCheckFunc {
return func(*terraform.State) error {
if v.SourceDestCheck == nil {
return fmt.Errorf("bad source_dest_check: got nil")
}
if *v.SourceDestCheck != enabled {
return fmt.Errorf("bad source_dest_check: %#v", *v.SourceDestCheck)
}