diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index 1e7e5da88..7b82d3eb8 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -89,6 +89,7 @@ func resource_aws_instance_update( if attr, ok := d.Attributes["source_dest_check"]; ok { modify = true opts.SourceDestCheck = attr.New != "" && attr.New != "false" + opts.SetSourceDestCheck = true rs.Attributes["source_dest_check"] = strconv.FormatBool( opts.SourceDestCheck) } @@ -98,6 +99,9 @@ func resource_aws_instance_update( if _, err := ec2conn.ModifyInstance(s.ID, opts); err != nil { return s, err } + + // TODO(mitchellh): wait for the attributes we modified to + // persist the change... } return rs, nil diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index b26a80f85..70acfb5f2 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -31,12 +31,14 @@ func TestAccAWSInstance(t *testing.T) { func TestAccAWSInstance_sourceDestCheck(t *testing.T) { var v ec2.Instance - testCheck := func(*terraform.State) error { - if !v.SourceDestCheck { - return fmt.Errorf("no source_dest_check") - } + testCheck := func(enabled bool) resource.TestCheckFunc { + return func(*terraform.State) error { + if v.SourceDestCheck != enabled { + return fmt.Errorf("bad source_dest_check: %#v", v.SourceDestCheck) + } - return nil + return nil + } } resource.Test(t, resource.TestCase{ @@ -49,7 +51,16 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists( "aws_instance.foo", &v), - testCheck, + testCheck(true), + ), + }, + + resource.TestStep{ + Config: testAccInstanceConfigSourceDestDisable, + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists( + "aws_instance.foo", &v), + testCheck(false), ), }, }, @@ -161,6 +172,25 @@ resource "aws_instance" "foo" { } ` +const testAccInstanceConfigSourceDestDisable = ` +resource "aws_vpc" "foo" { + cidr_block = "10.1.0.0/16" +} + +resource "aws_subnet" "foo" { + cidr_block = "10.1.1.0/24" + vpc_id = "${aws_vpc.foo.id}" +} + +resource "aws_instance" "foo" { + # us-west-2 + ami = "ami-4fccb37f" + instance_type = "m1.small" + subnet_id = "${aws_subnet.foo.id}" + source_dest_check = false +} +` + const testAccInstanceConfigVPC = ` resource "aws_vpc" "foo" { cidr_block = "10.1.0.0/16"