-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add acceptance test and documentation for aws_network_interfaces
- Loading branch information
1 parent
c348a10
commit b358188
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsNetworkInterfaces_Filter(t *testing.T) { | ||
rName := acctest.RandString(5) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckVpcDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsNetworkInterfacesConfig_Filter(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_network_interfaces.test", "ids.#", "2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAwsNetworkInterfaces_Tags(t *testing.T) { | ||
rName := acctest.RandString(5) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckVpcDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsNetworkInterfacesConfig_Tags(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_network_interfaces.test", "ids.#", "1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsNetworkInterfacesConfig_Base(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_vpc" "test" { | ||
cidr_block = "10.0.0.0/16" | ||
tags { | ||
Name = "terraform-testacc-eni-data-source-basic-%s" | ||
} | ||
} | ||
resource "aws_subnet" "test" { | ||
cidr_block = "10.0.0.0/24" | ||
availability_zone = "us-west-2a" | ||
vpc_id = "${aws_vpc.test.id}" | ||
tags { | ||
Name = "terraform-testacc-eni-data-source-basic-%s" | ||
} | ||
} | ||
resource "aws_network_interface" "test" { | ||
subnet_id = "${aws_subnet.test.id}" | ||
} | ||
resource "aws_network_interface" "test1" { | ||
subnet_id = "${aws_subnet.test.id}" | ||
tags { | ||
Name = "${aws_vpc.test.tags.Name}" | ||
} | ||
} | ||
`, rName, rName) | ||
} | ||
|
||
func testAccDataSourceAwsNetworkInterfacesConfig_Filter(rName string) string { | ||
return testAccDataSourceAwsNetworkInterfacesConfig_Base(rName) + ` | ||
data "aws_network_interfaces" "test" { | ||
filter { | ||
name = "subnet-id" | ||
values = ["${aws_network_interface.test.subnet_id}"] | ||
} | ||
} | ||
` | ||
} | ||
|
||
func testAccDataSourceAwsNetworkInterfacesConfig_Tags(rName string) string { | ||
return testAccDataSourceAwsNetworkInterfacesConfig_Base(rName) + ` | ||
data "aws_network_interfaces" "test" { | ||
tags { | ||
Name = "${aws_network_interface.test1.tags.Name}" | ||
} | ||
} | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_network_interfaces" | ||
sidebar_current: "docs-aws-datasource-network-interfaces" | ||
description: |- | ||
Provides a list of network interface ids | ||
--- | ||
|
||
# Data Source: aws_network_interfaces | ||
|
||
## Example Usage | ||
|
||
The following shows outputing all network interface ids in a region. | ||
|
||
```hcl | ||
data "aws_network_interfaces" "example" {} | ||
output "example" { | ||
value = "${data.aws_network_interfaces.example.ids}" | ||
} | ||
``` | ||
|
||
The following example retrieves a list of all network interface ids with a custom tag of `Name` set to a value of `test`. | ||
|
||
```hcl | ||
data "aws_network_interfaces" "example" { | ||
tags { | ||
Name = "test" | ||
} | ||
} | ||
output "example1" { | ||
value = "${data.aws_network_interfaces.example.ids}" | ||
} | ||
``` | ||
|
||
The following example retrieves a network interface ids which associated | ||
with specific subnet. | ||
|
||
```hcl | ||
data "aws_network_interfaces" "example" { | ||
filter { | ||
name = "subnet-id" | ||
values = ["${aws_subnet.test.id}"] | ||
} | ||
} | ||
output "example" { | ||
value = "${data.aws_network_interfaces.example.ids}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `tags` - (Optional) A mapping of tags, each pair of which must exactly match | ||
a pair on the desired network interfaces. | ||
|
||
* `filter` - (Optional) Custom filter block as described below. | ||
|
||
More complex filters can be expressed using one or more `filter` sub-blocks, | ||
which take the following arguments: | ||
|
||
* `name` - (Required) The name of the field to filter by, as defined by | ||
[the underlying AWS API](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeNetworkInterfaces.html). | ||
|
||
* `values` - (Required) Set of values that are accepted for the given field. | ||
|
||
## Attributes Reference | ||
|
||
* `ids` - A list of all the network interface ids found. This data source will fail if none are found. | ||
|