diff --git a/aws/data_source_aws_ec2_coip_pool_test.go b/aws/data_source_aws_ec2_coip_pool_test.go index 607882a7b7f..024d2da5579 100644 --- a/aws/data_source_aws_ec2_coip_pool_test.go +++ b/aws/data_source_aws_ec2_coip_pool_test.go @@ -1,7 +1,6 @@ package aws import ( - "os" "regexp" "testing" @@ -9,19 +8,10 @@ import ( ) 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{ { @@ -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{ { diff --git a/aws/data_source_aws_ec2_coip_pools_test.go b/aws/data_source_aws_ec2_coip_pools_test.go index 7263de157d5..d1e839a8f46 100644 --- a/aws/data_source_aws_ec2_coip_pools_test.go +++ b/aws/data_source_aws_ec2_coip_pools_test.go @@ -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{ { @@ -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{ { diff --git a/aws/data_source_aws_ec2_local_gateway_route_table_test.go b/aws/data_source_aws_ec2_local_gateway_route_table_test.go index a413f1cf582..6df7b4aaed6 100644 --- a/aws/data_source_aws_ec2_local_gateway_route_table_test.go +++ b/aws/data_source_aws_ec2_local_gateway_route_table_test.go @@ -1,8 +1,6 @@ package aws import ( - "fmt" - "os" "regexp" "testing" @@ -10,19 +8,10 @@ import ( ) 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{ { @@ -30,7 +19,7 @@ func TestAccDataSourceAwsEc2LocalGatewayRouteTable_basic(t *testing.T) { 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"), ), }, @@ -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"), ), }, @@ -68,19 +48,10 @@ 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{ { @@ -88,7 +59,7 @@ func TestAccDataSourceAwsEc2LocalGatewayRouteTable_LocalGatewayId(t *testing.T) 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"), ), }, @@ -97,27 +68,18 @@ 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"), ), }, @@ -125,15 +87,17 @@ func TestAccDataSourceAwsEc2LocalGatewayRouteTable_OutpostArn(t *testing.T) { }) } -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 { @@ -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) +` } diff --git a/aws/data_source_aws_ec2_local_gateway_route_tables_test.go b/aws/data_source_aws_ec2_local_gateway_route_tables_test.go index 8fabaf99170..61a5c48b914 100644 --- a/aws/data_source_aws_ec2_local_gateway_route_tables_test.go +++ b/aws/data_source_aws_ec2_local_gateway_route_tables_test.go @@ -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{ { @@ -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{ { diff --git a/aws/data_source_aws_ec2_local_gateway_test.go b/aws/data_source_aws_ec2_local_gateway_test.go index 972a8f0c9bd..782a8c36550 100644 --- a/aws/data_source_aws_ec2_local_gateway_test.go +++ b/aws/data_source_aws_ec2_local_gateway_test.go @@ -1,7 +1,6 @@ package aws import ( - "os" "regexp" "testing" @@ -9,26 +8,17 @@ import ( ) 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"), ), diff --git a/aws/data_source_aws_ec2_local_gateway_virtual_interface_group_test.go b/aws/data_source_aws_ec2_local_gateway_virtual_interface_group_test.go index ea3f5b62220..ac8540de20b 100644 --- a/aws/data_source_aws_ec2_local_gateway_virtual_interface_group_test.go +++ b/aws/data_source_aws_ec2_local_gateway_virtual_interface_group_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "os" "regexp" "testing" @@ -11,19 +10,10 @@ import ( ) func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroup_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_virtual_interface_group.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { @@ -39,19 +29,10 @@ func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroup_Filter(t *testing. } func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroup_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_virtual_interface_group.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { @@ -67,21 +48,12 @@ func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroup_LocalGatewayId(t * } func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroup_Tags(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.") - } - rName := acctest.RandomWithPrefix("tf-acc-test") sourceDataSourceName := "data.aws_ec2_local_gateway_virtual_interface_group.source" dataSourceName := "data.aws_ec2_local_gateway_virtual_interface_group.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { diff --git a/aws/data_source_aws_ec2_local_gateway_virtual_interface_groups_test.go b/aws/data_source_aws_ec2_local_gateway_virtual_interface_groups_test.go index f05e20fef12..b0954b34fb0 100644 --- a/aws/data_source_aws_ec2_local_gateway_virtual_interface_groups_test.go +++ b/aws/data_source_aws_ec2_local_gateway_virtual_interface_groups_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -10,19 +9,10 @@ import ( ) func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroups_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_virtual_interface_groups.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { @@ -37,19 +27,10 @@ func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroups_basic(t *testing. } func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroups_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_virtual_interface_groups.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { @@ -64,20 +45,11 @@ func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroups_Filter(t *testing } func TestAccDataSourceAwsEc2LocalGatewayVirtualInterfaceGroups_Tags(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.") - } - rName := acctest.RandomWithPrefix("tf-acc-test") dataSourceName := "data.aws_ec2_local_gateway_virtual_interface_groups.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { diff --git a/aws/data_source_aws_ec2_local_gateway_virtual_interface_test.go b/aws/data_source_aws_ec2_local_gateway_virtual_interface_test.go index 52eb33d718d..b5c2df158f5 100644 --- a/aws/data_source_aws_ec2_local_gateway_virtual_interface_test.go +++ b/aws/data_source_aws_ec2_local_gateway_virtual_interface_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "os" "regexp" "testing" @@ -11,19 +10,10 @@ import ( ) func TestAccDataSourceAwsEc2LocalGatewayVirtualInterface_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_virtual_interface.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { @@ -43,19 +33,10 @@ func TestAccDataSourceAwsEc2LocalGatewayVirtualInterface_Filter(t *testing.T) { } func TestAccDataSourceAwsEc2LocalGatewayVirtualInterface_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_local_gateway_virtual_interface.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { @@ -75,21 +56,12 @@ func TestAccDataSourceAwsEc2LocalGatewayVirtualInterface_Id(t *testing.T) { } func TestAccDataSourceAwsEc2LocalGatewayVirtualInterface_Tags(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.") - } - rName := acctest.RandomWithPrefix("tf-acc-test") sourceDataSourceName := "data.aws_ec2_local_gateway_virtual_interface.source" dataSourceName := "data.aws_ec2_local_gateway_virtual_interface.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { diff --git a/aws/data_source_aws_ec2_local_gateways_test.go b/aws/data_source_aws_ec2_local_gateways_test.go index 7e8079739c0..03722635972 100644 --- a/aws/data_source_aws_ec2_local_gateways_test.go +++ b/aws/data_source_aws_ec2_local_gateways_test.go @@ -1,26 +1,16 @@ package aws import ( - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccDataSourceAwsEc2LocalGateways_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_gateways.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { diff --git a/aws/data_source_aws_eip_test.go b/aws/data_source_aws_eip_test.go index bce7029ff1b..77028e3b314 100644 --- a/aws/data_source_aws_eip_test.go +++ b/aws/data_source_aws_eip_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -157,33 +156,15 @@ func TestAccDataSourceAwsEip_Instance(t *testing.T) { } func TestAccDataSourceAWSEIP_CustomerOwnedIpv4Pool(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.") - } - - // Local Gateway Route Table ID filtering in DescribeCoipPools is not currently working - poolId := os.Getenv("AWS_COIP_POOL_ID") - if poolId == "" { - t.Skip( - "Environment variable AWS_COIP_POOL_ID is not set. " + - "This environment variable must be set to the ID of " + - "a deployed Coip Pool to enable this test.") - } - dataSourceName := "data.aws_eip.test" resourceName := "aws_eip.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAWSEIPConfigCustomerOwnedIpv4Pool(poolId), + Config: testAccDataSourceAWSEIPConfigCustomerOwnedIpv4Pool(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair(resourceName, "customer_owned_ipv4_pool", dataSourceName, "customer_owned_ipv4_pool"), resource.TestCheckResourceAttrPair(resourceName, "customer_owned_ip", dataSourceName, "customer_owned_ip"), @@ -193,17 +174,19 @@ func TestAccDataSourceAWSEIP_CustomerOwnedIpv4Pool(t *testing.T) { }) } -func testAccDataSourceAWSEIPConfigCustomerOwnedIpv4Pool(customerOwnedIpv4Pool string) string { - return fmt.Sprintf(` +func testAccDataSourceAWSEIPConfigCustomerOwnedIpv4Pool() string { + return ` +data "aws_ec2_coip_pools" "test" {} + resource "aws_eip" "test" { - customer_owned_ipv4_pool = %[1]q + customer_owned_ipv4_pool = tolist(data.aws_ec2_coip_pools.test.pool_ids)[0] vpc = true } data "aws_eip" "test" { id = aws_eip.test.id } -`, customerOwnedIpv4Pool) +` } func testAccDataSourceAwsEipConfigFilter(rName string) string { diff --git a/aws/resource_aws_ebs_volume_test.go b/aws/resource_aws_ebs_volume_test.go index bb0bf6d7c52..130e6c6f98d 100644 --- a/aws/resource_aws_ebs_volume_test.go +++ b/aws/resource_aws_ebs_volume_test.go @@ -3,7 +3,6 @@ package aws import ( "fmt" "log" - "os" "regexp" "testing" @@ -343,27 +342,20 @@ func TestAccAWSEBSVolume_multiAttach(t *testing.T) { func TestAccAWSEBSVolume_outpost(t *testing.T) { var v ec2.Volume + outpostDataSourceName := "data.aws_outposts_outpost.test" resourceName := "aws_ebs_volume.test" - 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.") - } - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckVolumeDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsEbsVolumeConfigOutpost(outpostArn), + Config: testAccAwsEbsVolumeConfigOutpost(), Check: resource.ComposeTestCheckFunc( testAccCheckVolumeExists(resourceName, &v), - resource.TestCheckResourceAttr(resourceName, "outpost_arn", outpostArn), + resource.TestCheckResourceAttrPair(resourceName, "outpost_arn", outpostDataSourceName, "arn"), ), }, { @@ -757,19 +749,23 @@ resource "aws_ebs_volume" "test" { } ` -func testAccAwsEbsVolumeConfigOutpost(outpostArn string) string { - return fmt.Sprintf(` -data "aws_availability_zones" "available" {} +func testAccAwsEbsVolumeConfigOutpost() string { + return ` +data "aws_outposts_outposts" "test" {} + +data "aws_outposts_outpost" "test" { + id = tolist(data.aws_outposts_outposts.test.ids)[0] +} resource "aws_ebs_volume" "test" { - availability_zone = "${data.aws_availability_zones.available.names[0]}" - size = 1 - outpost_arn = "%s" + availability_zone = data.aws_outposts_outpost.test.availability_zone + size = 1 + outpost_arn = data.aws_outposts_outpost.test.arn tags = { Name = "tf-acc-volume-outpost" } } -`, outpostArn) +` } func testAccAwsEbsVolumeConfigMultiAttach(rName string) string { diff --git a/aws/resource_aws_ec2_local_gateway_route_table_vpc_association_test.go b/aws/resource_aws_ec2_local_gateway_route_table_vpc_association_test.go index 73c54247b55..80e2e8ca1e6 100644 --- a/aws/resource_aws_ec2_local_gateway_route_table_vpc_association_test.go +++ b/aws/resource_aws_ec2_local_gateway_route_table_vpc_association_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "os" "testing" "github.com/aws/aws-sdk-go/aws" @@ -13,27 +12,18 @@ import ( ) func TestAccAwsEc2LocalGatewayRouteTableVpcAssociation_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.") - } - rName := acctest.RandomWithPrefix("tf-acc-test") localGatewayRouteTableDataSourceName := "data.aws_ec2_local_gateway_route_table.test" resourceName := "aws_ec2_local_gateway_route_table_vpc_association.test" vpcResourceName := "aws_vpc.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfig(rName, outpostArn), + Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationExists(resourceName), resource.TestCheckResourceAttrPair(resourceName, "local_gateway_id", localGatewayRouteTableDataSourceName, "local_gateway_id"), @@ -52,25 +42,16 @@ func TestAccAwsEc2LocalGatewayRouteTableVpcAssociation_basic(t *testing.T) { } func TestAccAwsEc2LocalGatewayRouteTableVpcAssociation_disappears(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.") - } - rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_ec2_local_gateway_route_table_vpc_association.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfig(rName, outpostArn), + Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfig(rName), Check: resource.ComposeTestCheckFunc( testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationExists(resourceName), testAccCheckResourceDisappears(testAccProvider, resourceAwsEc2LocalGatewayRouteTableVpcAssociation(), resourceName), @@ -82,25 +63,16 @@ func TestAccAwsEc2LocalGatewayRouteTableVpcAssociation_disappears(t *testing.T) } func TestAccAwsEc2LocalGatewayRouteTableVpcAssociation_Tags(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.") - } - rName := acctest.RandomWithPrefix("tf-acc-test") resourceName := "aws_ec2_local_gateway_route_table_vpc_association.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationDestroy, Steps: []resource.TestStep{ { - Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags1(rName, outpostArn, "key1", "value1"), + Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags1(rName, "key1", "value1"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), @@ -113,7 +85,7 @@ func TestAccAwsEc2LocalGatewayRouteTableVpcAssociation_Tags(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags2(rName, outpostArn, "key1", "value1updated", "key2", "value2"), + Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags2(rName, "key1", "value1updated", "key2", "value2"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), @@ -122,7 +94,7 @@ func TestAccAwsEc2LocalGatewayRouteTableVpcAssociation_Tags(t *testing.T) { ), }, { - Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags1(rName, outpostArn, "key2", "value2"), + Config: testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags1(rName, "key2", "value2"), Check: resource.ComposeTestCheckFunc( testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationExists(resourceName), resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), @@ -141,7 +113,7 @@ func testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationExists(resourceName s } if rs.Primary.ID == "" { - return fmt.Errorf("No EC2 Fleet ID is set") + return fmt.Errorf("%s: missing resource ID", resourceName) } conn := testAccProvider.Meta().(*AWSClient).ec2conn @@ -186,10 +158,12 @@ func testAccCheckAwsEc2LocalGatewayRouteTableVpcAssociationDestroy(s *terraform. return nil } -func testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigBase(rName, outpostArn string) string { +func testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigBase(rName string) string { return fmt.Sprintf(` +data "aws_outposts_outposts" "test" {} + data "aws_ec2_local_gateway_route_table" "test" { - outpost_arn = %[2]q + outpost_arn = tolist(data.aws_outposts_outposts.test.arns)[0] } resource "aws_vpc" "test" { @@ -199,12 +173,12 @@ resource "aws_vpc" "test" { Name = %[1]q } } -`, rName, outpostArn) +`, rName) } -func testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfig(rName, outpostArn string) string { +func testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfig(rName string) string { return composeConfig( - testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigBase(rName, outpostArn), + testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigBase(rName), ` resource "aws_ec2_local_gateway_route_table_vpc_association" "test" { local_gateway_route_table_id = data.aws_ec2_local_gateway_route_table.test.id @@ -213,9 +187,9 @@ resource "aws_ec2_local_gateway_route_table_vpc_association" "test" { `) } -func testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags1(rName, outpostArn, tagKey1, tagValue1 string) string { +func testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags1(rName, tagKey1, tagValue1 string) string { return composeConfig( - testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigBase(rName, outpostArn), + testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigBase(rName), fmt.Sprintf(` resource "aws_ec2_local_gateway_route_table_vpc_association" "test" { local_gateway_route_table_id = data.aws_ec2_local_gateway_route_table.test.id @@ -228,9 +202,9 @@ resource "aws_ec2_local_gateway_route_table_vpc_association" "test" { `, tagKey1, tagValue1)) } -func testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags2(rName, outpostArn, tagKey1, tagValue1, tagKey2, tagValue2 string) string { +func testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigTags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { return composeConfig( - testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigBase(rName, outpostArn), + testAccAwsEc2LocalGatewayRouteTableVpcAssociationConfigBase(rName), fmt.Sprintf(` resource "aws_ec2_local_gateway_route_table_vpc_association" "test" { local_gateway_route_table_id = data.aws_ec2_local_gateway_route_table.test.id diff --git a/aws/resource_aws_ec2_local_gateway_route_test.go b/aws/resource_aws_ec2_local_gateway_route_test.go index 712ce7e4237..0f9eb632be4 100644 --- a/aws/resource_aws_ec2_local_gateway_route_test.go +++ b/aws/resource_aws_ec2_local_gateway_route_test.go @@ -2,7 +2,6 @@ package aws import ( "fmt" - "os" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -10,15 +9,6 @@ import ( ) func TestAccAWSEc2LocalGatewayRoute_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.") - } - rInt := randIntRange(0, 255) destinationCidrBlock := fmt.Sprintf("172.16.%d.0/24", rInt) localGatewayRouteTableDataSourceName := "data.aws_ec2_local_gateway_route_table.test" @@ -26,7 +16,7 @@ func TestAccAWSEc2LocalGatewayRoute_basic(t *testing.T) { resourceName := "aws_ec2_local_gateway_route.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSEc2LocalGatewayRouteDestroy, Steps: []resource.TestStep{ @@ -49,21 +39,12 @@ func TestAccAWSEc2LocalGatewayRoute_basic(t *testing.T) { } func TestAccAWSEc2LocalGatewayRoute_disappears(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.") - } - rInt := randIntRange(0, 255) destinationCidrBlock := fmt.Sprintf("172.16.%d.0/24", rInt) resourceName := "aws_ec2_local_gateway_route.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAWSEc2LocalGatewayRouteDestroy, Steps: []resource.TestStep{ diff --git a/aws/resource_aws_eip_test.go b/aws/resource_aws_eip_test.go index dadb43ffc0c..04fea445824 100644 --- a/aws/resource_aws_eip_test.go +++ b/aws/resource_aws_eip_test.go @@ -523,38 +523,20 @@ func testAccCheckAWSEIPDestroy(s *terraform.State) error { } func TestAccAWSEIP_CustomerOwnedIpv4Pool(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.") - } - - // Local Gateway Route Table ID filtering in DescribeCoipPools is not currently working - poolId := os.Getenv("AWS_COIP_POOL_ID") - if poolId == "" { - t.Skip( - "Environment variable AWS_COIP_POOL_ID is not set. " + - "This environment variable must be set to the ID of " + - "a deployed Coip Pool to enable this test.") - } - var conf ec2.Address resourceName := "aws_eip.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckAWSEIPDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSEIPConfigCustomerOwnedIpv4Pool(poolId), + Config: testAccAWSEIPConfigCustomerOwnedIpv4Pool(), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEIPExists(resourceName, &conf), - resource.TestCheckResourceAttr(resourceName, "customer_owned_ipv4_pool", poolId), + resource.TestMatchResourceAttr(resourceName, "customer_owned_ipv4_pool", regexp.MustCompile(`^ipv4pool-coip-.+$`)), resource.TestMatchResourceAttr(resourceName, "customer_owned_ip", regexp.MustCompile(`\d+\.\d+\.\d+\.\d+`)), ), }, @@ -1179,11 +1161,13 @@ resource "aws_eip" "test" { } ` -func testAccAWSEIPConfigCustomerOwnedIpv4Pool(customerOwnedIpv4Pool string) string { - return fmt.Sprintf(` +func testAccAWSEIPConfigCustomerOwnedIpv4Pool() string { + return ` +data "aws_ec2_coip_pools" "test" {} + resource "aws_eip" "test" { - customer_owned_ipv4_pool = %[1]q + customer_owned_ipv4_pool = tolist(data.aws_ec2_coip_pools.test.pool_ids)[0] vpc = true } -`, customerOwnedIpv4Pool) +` } diff --git a/aws/resource_aws_instance_test.go b/aws/resource_aws_instance_test.go index c7942d053e1..17b28e86148 100644 --- a/aws/resource_aws_instance_test.go +++ b/aws/resource_aws_instance_test.go @@ -820,30 +820,21 @@ func TestAccAWSInstance_vpc(t *testing.T) { func TestAccAWSInstance_outpost(t *testing.T) { var v ec2.Instance + outpostDataSourceName := "data.aws_outposts_outpost.test" resourceName := "aws_instance.test" - 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.") - } - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, IDRefreshName: resourceName, IDRefreshIgnore: []string{"associate_public_ip_address"}, Providers: testAccProviders, CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfigOutpost(outpostArn), + Config: testAccInstanceConfigOutpost(), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists( - resourceName, &v), - resource.TestCheckResourceAttr( - resourceName, "outpost_arn", outpostArn), + testAccCheckInstanceExists(resourceName, &v), + resource.TestCheckResourceAttrPair(resourceName, "outpost_arn", outpostDataSourceName, "arn"), ), }, { @@ -3473,26 +3464,18 @@ resource "aws_instance" "test" { `) } -func testAccInstanceConfigOutpost(outpostArn string) string { - return testAccLatestAmazonLinuxHvmEbsAmiConfig() + testAccAwsInstanceOutpostConfig(outpostArn) + fmt.Sprintf(` -resource "aws_instance" "test" { - ami = "${data.aws_ami.amzn-ami-minimal-hvm-ebs.id}" - instance_type = "m5.large" - subnet_id = "${aws_subnet.test.id}" +func testAccInstanceConfigOutpost() string { + return composeConfig( + testAccLatestAmazonLinuxHvmEbsAmiConfig(), + ` +data "aws_outposts_outposts" "test" {} - root_block_device { - volume_type = "gp2" - volume_size = 8 - } -} -`) +data "aws_outposts_outpost" "test" { + id = tolist(data.aws_outposts_outposts.test.ids)[0] } -func testAccAwsInstanceOutpostConfig(outpostArn string) string { - return fmt.Sprintf(` -data "aws_availability_zones" "current" { - # Exclude usw2-az4 (us-west-2d) as it has limited instance types. - blacklisted_zone_ids = ["usw2-az4"] +data "aws_outposts_outpost_instance_types" "test" { + arn = data.aws_outposts_outpost.test.arn } resource "aws_vpc" "test" { @@ -3500,12 +3483,23 @@ resource "aws_vpc" "test" { } resource "aws_subnet" "test" { - cidr_block = "10.1.1.0/24" - vpc_id = "${aws_vpc.test.id}" - availability_zone = "${data.aws_availability_zones.current.names[0]}" - outpost_arn = "%s" + availability_zone = data.aws_outposts_outpost.test.availability_zone + cidr_block = "10.1.1.0/24" + outpost_arn = data.aws_outposts_outpost.test.arn + vpc_id = aws_vpc.test.id } -`, outpostArn) + +resource "aws_instance" "test" { + ami = data.aws_ami.amzn-ami-minimal-hvm-ebs.id + instance_type = tolist(data.aws_outposts_outpost_instance_types.test.instance_types)[0] + subnet_id = aws_subnet.test.id + + root_block_device { + volume_type = "gp2" + volume_size = 8 + } +} +`) } func testAccInstanceConfigPlacementGroup(rName string) string { diff --git a/aws/resource_aws_subnet_test.go b/aws/resource_aws_subnet_test.go index ba90171670a..e843008e75f 100644 --- a/aws/resource_aws_subnet_test.go +++ b/aws/resource_aws_subnet_test.go @@ -3,7 +3,6 @@ package aws import ( "fmt" "log" - "os" "regexp" "testing" "time" @@ -299,29 +298,20 @@ func TestAccAWSSubnet_availabilityZoneId(t *testing.T) { func TestAccAWSSubnet_outpost(t *testing.T) { var v ec2.Subnet + outpostDataSourceName := "data.aws_outposts_outpost.test" resourceName := "aws_subnet.test" - 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.") - } - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, IDRefreshName: resourceName, Providers: testAccProviders, CheckDestroy: testAccCheckSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccSubnetConfigOutpost(outpostArn), + Config: testAccSubnetConfigOutpost(), Check: resource.ComposeTestCheckFunc( - testAccCheckSubnetExists( - resourceName, &v), - resource.TestCheckResourceAttr( - resourceName, "outpost_arn", outpostArn), + testAccCheckSubnetExists(resourceName, &v), + resource.TestCheckResourceAttrPair(resourceName, "outpost_arn", outpostDataSourceName, "arn"), ), }, { @@ -554,11 +544,12 @@ resource "aws_subnet" "test" { } ` -func testAccSubnetConfigOutpost(outpostArn string) string { - return fmt.Sprintf(` -data "aws_availability_zones" "current" { - # Exclude usw2-az4 (us-west-2d) as it has limited instance types. - blacklisted_zone_ids = ["usw2-az4"] +func testAccSubnetConfigOutpost() string { + return ` +data "aws_outposts_outposts" "test" {} + +data "aws_outposts_outpost" "test" { + id = tolist(data.aws_outposts_outposts.test.ids)[0] } resource "aws_vpc" "test" { @@ -569,13 +560,14 @@ resource "aws_vpc" "test" { } resource "aws_subnet" "test" { - cidr_block = "10.1.1.0/24" - vpc_id = "${aws_vpc.test.id}" - availability_zone = "${data.aws_availability_zones.current.names[0]}" - outpost_arn = "%s" + availability_zone = data.aws_outposts_outpost.test.availability_zone + cidr_block = "10.1.1.0/24" + outpost_arn = data.aws_outposts_outpost.test.arn + vpc_id = aws_vpc.test.id + tags = { Name = "tf-acc-subnet-outpost" } } -`, outpostArn) +` } diff --git a/docs/MAINTAINING.md b/docs/MAINTAINING.md index 37d9059fcf1..5a073b256fe 100644 --- a/docs/MAINTAINING.md +++ b/docs/MAINTAINING.md @@ -388,12 +388,10 @@ Environment variables (beyond standard AWS Go SDK ones) used by acceptance testi | `AWS_CODEBUILD_GITHUB_SOURCE_LOCATION` | GitHub source URL for CodeBuild testing. CodeBuild must have access to this repository via OAuth or Source Credentials. Defaults to `https://github.com/hashibot-test/aws-test.git`. | | `AWS_COGNITO_USER_POOL_DOMAIN_CERTIFICATE_ARN` | Amazon Resource Name of ACM Certificate in `us-east-1` for Cognito User Pool Domain Name testing. | | `AWS_COGNITO_USER_POOL_DOMAIN_ROOT_DOMAIN` | Root domain name to use with Cognito User Pool Domain testing. | -| `AWS_COIP_POOL_ID` | Identifier for EC2 Customer-Owned Pool related testing. Requires `AWS_OUTPOST_ARN`. | | `AWS_DEFAULT_REGION` | Primary AWS region for tests. Defaults to `us-west-2`. | | `AWS_EC2_EIP_PUBLIC_IPV4_POOL` | Identifier for EC2 Public IPv4 Pool for EC2 EIP testing. | | `AWS_GUARDDUTY_MEMBER_ACCOUNT_ID` | Identifier of AWS Account for GuardDuty Member testing. **DEPRECATED:** Should be replaced with standard alternate account handling for tests. | | `AWS_GUARDDUTY_MEMBER_EMAIL` | Email address for GuardDuty Member testing. **DEPRECATED:** It may be possible to use a placeholder email address instead. | -| `AWS_OUTPOST_ARN` | Amazon Resource Name of Outpost for Outposts related testing. | | `DX_CONNECTION_ID` | Identifier for Direct Connect Connection testing. | | `DX_VIRTUAL_INTERFACE_ID` | Identifier for Direct Connect Virtual Interface testing. | | `EC2_SECURITY_GROUP_RULES_PER_GROUP_LIMIT` | EC2 Quota for Rules per Security Group. Defaults to 50. **DEPRECATED:** Can be augmented or replaced with Service Quotas lookup. |