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,7 +543,8 @@ 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
|
||||||
|
// to modify the source_dest_check of an instance in EC2 Classic
|
||||||
log.Printf("[INFO] Modifying instance %s", d.Id())
|
log.Printf("[INFO] Modifying instance %s", d.Id())
|
||||||
_, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
|
_, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
|
||||||
InstanceId: aws.String(d.Id()),
|
InstanceId: aws.String(d.Id()),
|
||||||
|
@ -557,8 +553,14 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
log.Printf("[WARN] Attempted to modify SourceDestCheck on non VPC instance: %s", ec2err.Message())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("vpc_security_group_ids") {
|
if d.HasChange("vpc_security_group_ids") {
|
||||||
|
|
|
@ -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