From affa09efdd6f2bb628bcc3266d329bbba96fc0f4 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 15 Jul 2015 19:09:35 +0000 Subject: [PATCH] Compute private ip addresses of ENIs if they are not specified As AWS will assign the ENI an address --- .../aws/resource_aws_network_interface.go | 1 + .../resource_aws_network_interface_test.go | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/builtin/providers/aws/resource_aws_network_interface.go b/builtin/providers/aws/resource_aws_network_interface.go index 2cf7b13c3..a26e668d9 100644 --- a/builtin/providers/aws/resource_aws_network_interface.go +++ b/builtin/providers/aws/resource_aws_network_interface.go @@ -34,6 +34,7 @@ func resourceAwsNetworkInterface() *schema.Resource { Type: schema.TypeSet, Optional: true, ForceNew: true, + Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, Set: schema.HashString, }, diff --git a/builtin/providers/aws/resource_aws_network_interface_test.go b/builtin/providers/aws/resource_aws_network_interface_test.go index a444a0136..65af4418c 100644 --- a/builtin/providers/aws/resource_aws_network_interface_test.go +++ b/builtin/providers/aws/resource_aws_network_interface_test.go @@ -77,6 +77,26 @@ func TestAccAWSENI_sourceDestCheck(t *testing.T) { }) } +func TestAccAWSENI_computedIPs(t *testing.T) { + var conf ec2.NetworkInterface + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSENIDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSENIConfigWithNoPrivateIPs, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSENIExists("aws_network_interface.bar", &conf), + resource.TestCheckResourceAttr( + "aws_network_interface.bar", "private_ips.#", "1"), + ), + }, + }, + }) +} + func testAccCheckAWSENIExists(n string, res *ec2.NetworkInterface) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -243,6 +263,23 @@ resource "aws_network_interface" "bar" { } ` +const testAccAWSENIConfigWithNoPrivateIPs = ` +resource "aws_vpc" "foo" { + cidr_block = "172.16.0.0/16" +} + +resource "aws_subnet" "foo" { + vpc_id = "${aws_vpc.foo.id}" + cidr_block = "172.16.10.0/24" + availability_zone = "us-west-2a" +} + +resource "aws_network_interface" "bar" { + subnet_id = "${aws_subnet.foo.id}" + source_dest_check = false +} +` + const testAccAWSENIConfigWithAttachment = ` resource "aws_vpc" "foo" { cidr_block = "172.16.0.0/16"