provider/aws: Stop aws_instance source_dest_check triggering an API call on each (#8450)

terraform run

Fixes #3550

The simple fix here was to check if the Resource was new (to set the
value the first time) then check it has changed each time

I was able to see from the TF log the following:

```
Config

resource "aws_vpc" "foo" {
	cidr_block = "10.10.0.0/16"
}

resource "aws_subnet" "foo" {
	cidr_block = "10.10.1.0/24"
	vpc_id = "${aws_vpc.foo.id}"
}

resource "aws_instance" "foo" {
	ami = "ami-4fccb37f"
	instance_type = "m1.small"
	subnet_id = "${aws_subnet.foo.id}"
	source_dest_check = false
        disable_api_termination = true
}
```

No longer caused any Modifying source_dest_check entries in the LOG
This commit is contained in:
Paul Stack 2016-08-25 22:11:01 +01:00 committed by GitHub
parent f326dad2ba
commit 338aab9169

View File

@ -597,10 +597,10 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
d.SetPartial("tags") d.SetPartial("tags")
} }
// SourceDestCheck can only be set on VPC instances if d.HasChange("source_dest_check") || d.IsNewResource() {
// AWS will return an error of InvalidParameterCombination if we attempt // SourceDestCheck can only be set on VPC instances // AWS will return an error of InvalidParameterCombination if we attempt
// to modify the source_dest_check of an instance in EC2 Classic // to modify the source_dest_check of an instance in EC2 Classic
log.Printf("[INFO] Modifying instance %s", d.Id()) log.Printf("[INFO] Modifying `source_dest_check` on Instance %s", d.Id())
_, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{ _, err := conn.ModifyInstanceAttribute(&ec2.ModifyInstanceAttributeInput{
InstanceId: aws.String(d.Id()), InstanceId: aws.String(d.Id()),
SourceDestCheck: &ec2.AttributeBooleanValue{ SourceDestCheck: &ec2.AttributeBooleanValue{
@ -617,6 +617,7 @@ func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[WARN] Attempted to modify SourceDestCheck on non VPC instance: %s", ec2err.Message()) 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") {
var groups []*string var groups []*string