Skip to content

Commit

Permalink
data-source/aws_api_gateway_rest_api: Prevent error with VPC Endpoint…
Browse files Browse the repository at this point in the history
… configured APIs (hashicorp#12825)

Reference: hashicorp#12350
Reference: hashicorp#8223

Previously:

```
    TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds: testing.go:669: Step 0 error: errors during apply:

        Error: error setting endpoint_configuration: endpoint_configuration.0.vpc_endpoint_ids: '': source data must be an array or slice, got struct

          on /var/folders/w8/05f3x02n27x72g0mc2jy6_180000gp/T/tf-test660234204/main.tf line 62:
          (source code not available)
```

Output from acceptance testing:

```
--- PASS: TestAccDataSourceAwsApiGatewayRestApi_basic (18.71s)
--- PASS: TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds (151.75s)

--- PASS: TestAccAWSAPIGatewayRestApi_tags (66.14s)
--- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration (89.86s)
--- PASS: TestAccAWSAPIGatewayRestApi_disappears (118.54s)
--- PASS: TestAccAWSAPIGatewayRestApi_api_key_source (187.17s)
--- PASS: TestAccAWSAPIGatewayRestApi_openapi (239.32s)
--- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_VPCEndpoint (370.75s)
--- PASS: TestAccAWSAPIGatewayRestApi_policy (459.60s)
--- PASS: TestAccAWSAPIGatewayRestApi_basic (505.99s)
--- PASS: TestAccAWSAPIGatewayRestApi_EndpointConfiguration_Private (690.91s)
```
  • Loading branch information
bflad authored and adamdecaf committed May 28, 2020
1 parent 3a75b97 commit a7ddfe9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion aws/data_source_aws_api_gateway_rest_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func dataSourceAwsApiGatewayRestApi() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
},
"vpc_endpoint_ids": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down
47 changes: 38 additions & 9 deletions aws/data_source_aws_api_gateway_rest_api_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package aws

import (
"fmt"
"testing"

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

func TestAccDataSourceAwsApiGatewayRestApi(t *testing.T) {
func TestAccDataSourceAwsApiGatewayRestApi_basic(t *testing.T) {
rName := acctest.RandString(8)
dataSourceName := "data.aws_api_gateway_rest_api.test"
resourceName := "aws_api_gateway_rest_api.test"
Expand All @@ -17,7 +16,10 @@ func TestAccDataSourceAwsApiGatewayRestApi(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsApiGatewayRestApiConfig(rName),
Config: composeConfig(
testAccAWSAPIGatewayRestAPIConfig_Name(rName),
testAccDataSourceAwsApiGatewayRestApiConfigName(),
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
Expand All @@ -36,14 +38,41 @@ func TestAccDataSourceAwsApiGatewayRestApi(t *testing.T) {
})
}

func testAccDataSourceAwsApiGatewayRestApiConfig(r string) string {
return fmt.Sprintf(`
resource "aws_api_gateway_rest_api" "test" {
name = "%[1]s"
func TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds(t *testing.T) {
rName := acctest.RandString(8)
dataSourceName := "data.aws_api_gateway_rest_api.test"
resourceName := "aws_api_gateway_rest_api.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: composeConfig(
testAccAWSAPIGatewayRestAPIConfig_VPCEndpointConfiguration(rName),
testAccDataSourceAwsApiGatewayRestApiConfigName(),
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "root_resource_id", resourceName, "root_resource_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags", resourceName, "tags"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "policy", resourceName, "policy"),
resource.TestCheckResourceAttrPair(dataSourceName, "api_key_source", resourceName, "api_key_source"),
resource.TestCheckResourceAttrPair(dataSourceName, "minimum_compression_size", resourceName, "minimum_compression_size"),
resource.TestCheckResourceAttrPair(dataSourceName, "binary_media_types", resourceName, "binary_media_types"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint_configuration", resourceName, "endpoint_configuration"),
resource.TestCheckResourceAttrPair(dataSourceName, "execution_arn", resourceName, "execution_arn"),
),
},
},
})
}

func testAccDataSourceAwsApiGatewayRestApiConfigName() string {
return `
data "aws_api_gateway_rest_api" "test" {
name = "${aws_api_gateway_rest_api.test.name}"
name = aws_api_gateway_rest_api.test.name
}
`, r)
`
}
2 changes: 1 addition & 1 deletion aws/resource_aws_api_gateway_rest_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func flattenApiGatewayEndpointConfiguration(endpointConfiguration *apigateway.En
}

if len(endpointConfiguration.VpcEndpointIds) > 0 {
m["vpc_endpoint_ids"] = flattenStringSet(endpointConfiguration.VpcEndpointIds)
m["vpc_endpoint_ids"] = aws.StringValueSlice(endpointConfiguration.VpcEndpointIds)
}

return []interface{}{m}
Expand Down

0 comments on commit a7ddfe9

Please sign in to comment.