diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index e6253b3bc..bb18df637 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -90,6 +90,11 @@ func resourceAwsInstance() *schema.Resource { Type: schema.TypeBool, Optional: true, Default: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + // Suppress diff if network_interface is set + _, ok := d.GetOk("network_interface") + return ok + }, }, "user_data": { @@ -642,6 +647,7 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error { d.Set("primary_network_interface_id", primaryNetworkInterface.NetworkInterfaceId) d.Set("associate_public_ip_address", primaryNetworkInterface.Association != nil) d.Set("ipv6_address_count", len(primaryNetworkInterface.Ipv6Addresses)) + d.Set("source_dest_check", *primaryNetworkInterface.SourceDestCheck) for _, address := range primaryNetworkInterface.Ipv6Addresses { ipv6Addresses = append(ipv6Addresses, *address.Ipv6Address) diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index 01dd6d99c..f4131b09a 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -966,6 +966,27 @@ func TestAccAWSInstance_primaryNetworkInterface(t *testing.T) { }) } +func TestAccAWSInstance_primaryNetworkInterfaceSourceDestCheck(t *testing.T) { + var instance ec2.Instance + var ini ec2.NetworkInterface + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckInstanceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccInstanceConfigPrimaryNetworkInterfaceSourceDestCheck, + Check: resource.ComposeTestCheckFunc( + testAccCheckInstanceExists("aws_instance.foo", &instance), + testAccCheckAWSENIExists("aws_network_interface.bar", &ini), + resource.TestCheckResourceAttr("aws_instance.foo", "source_dest_check", "false"), + ), + }, + }, + }) +} + func TestAccAWSInstance_addSecondaryInterface(t *testing.T) { var before ec2.Instance var after ec2.Instance @@ -1866,6 +1887,42 @@ resource "aws_instance" "foo" { } ` +const testAccInstanceConfigPrimaryNetworkInterfaceSourceDestCheck = ` +resource "aws_vpc" "foo" { + cidr_block = "172.16.0.0/16" + tags { + Name = "tf-instance-test" + } +} + +resource "aws_subnet" "foo" { + vpc_id = "${aws_vpc.foo.id}" + cidr_block = "172.16.10.0/24" + availability_zone = "us-west-2a" + tags { + Name = "tf-instance-test" + } +} + +resource "aws_network_interface" "bar" { + subnet_id = "${aws_subnet.foo.id}" + private_ips = ["172.16.10.100"] + source_dest_check = false + tags { + Name = "primary_network_interface" + } +} + +resource "aws_instance" "foo" { + ami = "ami-22b9a343" + instance_type = "t2.micro" + network_interface { + network_interface_id = "${aws_network_interface.bar.id}" + device_index = 0 + } +} +` + const testAccInstanceConfigAddSecondaryNetworkInterfaceBefore = ` resource "aws_vpc" "foo" { cidr_block = "172.16.0.0/16"