Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/provider: Switch Outposts acceptance testing to testAccPreCheckAWSOutpostsOutposts and aws_outposts_outposts data source #13822

Merged
merged 2 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions aws/data_source_aws_ec2_coip_pool_test.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
package aws

import (
"os"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceAwsEc2CoipPool_Filter(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_coip_pool.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand All @@ -37,19 +27,10 @@ func TestAccDataSourceAwsEc2CoipPool_Filter(t *testing.T) {
}

func TestAccDataSourceAwsEc2CoipPool_Id(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_coip_pool.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand Down
23 changes: 2 additions & 21 deletions aws/data_source_aws_ec2_coip_pools_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package aws

import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceAwsEc2CoipPools_basic(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_coip_pools.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand All @@ -34,19 +24,10 @@ func TestAccDataSourceAwsEc2CoipPools_basic(t *testing.T) {
}

func TestAccDataSourceAwsEc2CoipPools_Filter(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_coip_pools.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand Down
78 changes: 22 additions & 56 deletions aws/data_source_aws_ec2_local_gateway_route_table_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
package aws

import (
"fmt"
"os"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceAwsEc2LocalGatewayRouteTable_basic(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_local_gateway_route_table.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsEc2LocalGatewayRouteTableConfigLocalGatewayRouteTableId(),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(dataSourceName, "local_gateway_id", regexp.MustCompile(`^lgw-`)),
resource.TestMatchResourceAttr(dataSourceName, "local_gateway_route_table_id", regexp.MustCompile(`^lgw-rtb-`)),
resource.TestCheckResourceAttr(dataSourceName, "outpost_arn", outpostArn),
testAccMatchResourceAttrRegionalARN(dataSourceName, "outpost_arn", "outposts", regexp.MustCompile(`outpost/op-.+`)),
resource.TestCheckResourceAttr(dataSourceName, "state", "available"),
),
},
Expand All @@ -39,27 +28,18 @@ func TestAccDataSourceAwsEc2LocalGatewayRouteTable_basic(t *testing.T) {
}

func TestAccDataSourceAwsEc2LocalGatewayRouteTable_Filter(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_local_gateway_route_table.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsEc2LocalGatewayRouteTableConfigFilter(outpostArn),
Config: testAccDataSourceAwsEc2LocalGatewayRouteTableConfigFilter(),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(dataSourceName, "local_gateway_id", regexp.MustCompile(`^lgw-`)),
resource.TestMatchResourceAttr(dataSourceName, "local_gateway_route_table_id", regexp.MustCompile(`^lgw-rtb-`)),
resource.TestCheckResourceAttr(dataSourceName, "outpost_arn", outpostArn),
testAccMatchResourceAttrRegionalARN(dataSourceName, "outpost_arn", "outposts", regexp.MustCompile(`outpost/op-.+`)),
resource.TestCheckResourceAttr(dataSourceName, "state", "available"),
),
},
Expand All @@ -68,27 +48,18 @@ func TestAccDataSourceAwsEc2LocalGatewayRouteTable_Filter(t *testing.T) {
}

func TestAccDataSourceAwsEc2LocalGatewayRouteTable_LocalGatewayId(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_local_gateway_route_table.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsEc2LocalGatewayRouteTableConfigLocalGatewayId(),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(dataSourceName, "local_gateway_id", regexp.MustCompile(`^lgw-`)),
resource.TestMatchResourceAttr(dataSourceName, "local_gateway_route_table_id", regexp.MustCompile(`^lgw-rtb-`)),
resource.TestCheckResourceAttr(dataSourceName, "outpost_arn", outpostArn),
testAccMatchResourceAttrRegionalARN(dataSourceName, "outpost_arn", "outposts", regexp.MustCompile(`outpost/op-.+`)),
resource.TestCheckResourceAttr(dataSourceName, "state", "available"),
),
},
Expand All @@ -97,43 +68,36 @@ func TestAccDataSourceAwsEc2LocalGatewayRouteTable_LocalGatewayId(t *testing.T)
}

func TestAccDataSourceAwsEc2LocalGatewayRouteTable_OutpostArn(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_local_gateway_route_table.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsEc2LocalGatewayRouteTableConfigOutpostArn(outpostArn),
Config: testAccDataSourceAwsEc2LocalGatewayRouteTableConfigOutpostArn(),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(dataSourceName, "local_gateway_id", regexp.MustCompile(`^lgw-`)),
resource.TestMatchResourceAttr(dataSourceName, "local_gateway_route_table_id", regexp.MustCompile(`^lgw-rtb-`)),
resource.TestCheckResourceAttr(dataSourceName, "outpost_arn", outpostArn),
testAccMatchResourceAttrRegionalARN(dataSourceName, "outpost_arn", "outposts", regexp.MustCompile(`outpost/op-.+`)),
resource.TestCheckResourceAttr(dataSourceName, "state", "available"),
),
},
},
})
}

func testAccDataSourceAwsEc2LocalGatewayRouteTableConfigFilter(outpostArn string) string {
return fmt.Sprintf(`
func testAccDataSourceAwsEc2LocalGatewayRouteTableConfigFilter() string {
return `
data "aws_outposts_outposts" "test" {}

data "aws_ec2_local_gateway_route_table" "test" {
filter {
name = "outpost-arn"
values = [%[1]q]
values = [tolist(data.aws_outposts_outposts.test.arns)[0]]
}
}
`, outpostArn)
`
}

func testAccDataSourceAwsEc2LocalGatewayRouteTableConfigLocalGatewayId() string {
Expand All @@ -156,10 +120,12 @@ data "aws_ec2_local_gateway_route_table" "test" {
`
}

func testAccDataSourceAwsEc2LocalGatewayRouteTableConfigOutpostArn(outpostArn string) string {
return fmt.Sprintf(`
func testAccDataSourceAwsEc2LocalGatewayRouteTableConfigOutpostArn() string {
return `
data "aws_outposts_outposts" "test" {}

data "aws_ec2_local_gateway_route_table" "test" {
outpost_arn = %[1]q
outpost_arn = tolist(data.aws_outposts_outposts.test.arns)[0]
}
`, outpostArn)
`
}
23 changes: 2 additions & 21 deletions aws/data_source_aws_ec2_local_gateway_route_tables_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
package aws

import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceAwsEc2LocalGatewayRouteTables_basic(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_local_gateway_route_tables.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand All @@ -34,19 +24,10 @@ func TestAccDataSourceAwsEc2LocalGatewayRouteTables_basic(t *testing.T) {
}

func TestAccDataSourceAwsEc2LocalGatewayRouteTables_Filter(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_local_gateway_route_tables.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Expand Down
14 changes: 2 additions & 12 deletions aws/data_source_aws_ec2_local_gateway_test.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
package aws

import (
"os"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceAwsEc2LocalGateway_basic(t *testing.T) {
// Hide Outposts testing behind consistent environment variable
outpostArn := os.Getenv("AWS_OUTPOST_ARN")
if outpostArn == "" {
t.Skip(
"Environment variable AWS_OUTPOST_ARN is not set. " +
"This environment variable must be set to the ARN of " +
"a deployed Outpost to enable this test.")
}

dataSourceName := "data.aws_ec2_local_gateway.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsEc2LocalGatewayConfigId(),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(dataSourceName, "id", regexp.MustCompile(`^lgw-`)),
resource.TestCheckResourceAttr(dataSourceName, "outpost_arn", outpostArn),
testAccMatchResourceAttrRegionalARN(dataSourceName, "outpost_arn", "outposts", regexp.MustCompile(`outpost/op-.+`)),
testAccCheckResourceAttrAccountID(dataSourceName, "owner_id"),
resource.TestCheckResourceAttr(dataSourceName, "state", "available"),
),
Expand Down
Loading