Skip to content

Commit

Permalink
Compute private ip addresses of ENIs if they are not specified
Browse files Browse the repository at this point in the history
As AWS will assign the ENI an address
  • Loading branch information
Jesse Szwedko authored and braintreeps committed Jul 27, 2015
1 parent b6b3626 commit affa09e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/providers/aws/resource_aws_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
37 changes: 37 additions & 0 deletions builtin/providers/aws/resource_aws_network_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit affa09e

Please sign in to comment.