provider/aws: Fix issue with disabling source dest check on first run
This commit is contained in:
parent
0c3f2a915c
commit
efa26ed2a7
|
@ -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
|
// Update if we need to
|
||||||
return resourceAwsInstanceUpdate(d, meta)
|
return resourceAwsInstanceUpdate(d, meta)
|
||||||
}
|
}
|
||||||
|
@ -548,16 +543,23 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceDestCheck can only be set on VPC instances
|
// SourceDestCheck can only be set on VPC instances
|
||||||
if d.Get("subnet_id").(string) != "" {
|
// AWS will return an error of InvalidParameterCombination if we attempt
|
||||||
log.Printf("[INFO] Modifying instance %s", d.Id())
|
// to modify the source_dest_check of an instance in EC2 Classic
|
||||||
_, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
|
log.Printf("[INFO] Modifying instance %s", d.Id())
|
||||||
InstanceId: aws.String(d.Id()),
|
_, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
|
||||||
SourceDestCheck: &ec2.AttributeBooleanValue{
|
InstanceId: aws.String(d.Id()),
|
||||||
Value: aws.Bool(d.Get("source_dest_check").(bool)),
|
SourceDestCheck: &ec2.AttributeBooleanValue{
|
||||||
},
|
Value: aws.Bool(d.Get("source_dest_check").(bool)),
|
||||||
})
|
},
|
||||||
if err != nil {
|
})
|
||||||
return err
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,6 +190,9 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
|
||||||
|
|
||||||
testCheck := func(enabled bool) resource.TestCheckFunc {
|
testCheck := func(enabled bool) resource.TestCheckFunc {
|
||||||
return func(*terraform.State) error {
|
return func(*terraform.State) error {
|
||||||
|
if v.SourceDestCheck == nil {
|
||||||
|
return fmt.Errorf("bad source_dest_check: got nil")
|
||||||
|
}
|
||||||
if *v.SourceDestCheck != enabled {
|
if *v.SourceDestCheck != enabled {
|
||||||
return fmt.Errorf("bad source_dest_check: %#v", *v.SourceDestCheck)
|
return fmt.Errorf("bad source_dest_check: %#v", *v.SourceDestCheck)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue