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

resource/aws_api_gateway_rest_api: Fix disable_execute_api_endpoint and endpoint_configuration vpc_endpoint_ids handling with OpenAPI specification import (body argument) #17209

Merged
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
5 changes: 3 additions & 2 deletions aws/data_source_aws_api_gateway_rest_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds(
Steps: []resource.TestStep{
{
Config: composeConfig(
testAccAWSAPIGatewayRestAPIConfig_VPCEndpointConfiguration(rName),
testAccAWSAPIGatewayRestAPIConfigEndpointConfigurationVpcEndpointIds1(rName),
testAccDataSourceAwsApiGatewayRestApiConfigName(),
),
Check: resource.ComposeTestCheckFunc(
Expand All @@ -61,7 +61,8 @@ func TestAccDataSourceAwsApiGatewayRestApi_EndpointConfiguration_VpcEndpointIds(
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, "endpoint_configuration.#", resourceName, "endpoint_configuration.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "endpoint_configuration.0.vpc_endpoint_ids.#", resourceName, "endpoint_configuration.0.vpc_endpoint_ids.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "execution_arn", resourceName, "execution_arn"),
),
},
Expand Down
67 changes: 66 additions & 1 deletion aws/resource_aws_api_gateway_rest_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func resourceAwsApiGatewayRestApi() *schema.Resource {
"disable_execute_api_endpoint": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Computed: true,
},

"parameters": {
Expand Down Expand Up @@ -122,6 +122,7 @@ func resourceAwsApiGatewayRestApi() *schema.Resource {
"vpc_endpoint_ids": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -250,6 +251,38 @@ func resourceAwsApiGatewayRestApiCreate(d *schema.ResourceData, meta interface{}
})
}

if v, ok := d.GetOk("disable_execute_api_endpoint"); ok && v.(bool) != aws.BoolValue(output.DisableExecuteApiEndpoint) {
updateInput.PatchOperations = append(updateInput.PatchOperations, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpReplace),
Path: aws.String("/disableExecuteApiEndpoint"),
Value: aws.String(strconv.FormatBool(v.(bool))),
})
}

if v, ok := d.GetOk("endpoint_configuration"); ok {
endpointConfiguration := expandApiGatewayEndpointConfiguration(v.([]interface{}))

if endpointConfiguration != nil && len(endpointConfiguration.VpcEndpointIds) > 0 {
if output.EndpointConfiguration != nil {
for _, elem := range output.EndpointConfiguration.VpcEndpointIds {
updateInput.PatchOperations = append(updateInput.PatchOperations, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpRemove),
Path: aws.String("/endpointConfiguration/vpcEndpointIds"),
Value: elem,
})
}
}

for _, elem := range endpointConfiguration.VpcEndpointIds {
updateInput.PatchOperations = append(updateInput.PatchOperations, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpAdd),
Path: aws.String("/endpointConfiguration/vpcEndpointIds"),
Value: elem,
})
}
}
}

if v := d.Get("minimum_compression_size").(int); v > -1 && int64(v) != aws.Int64Value(output.MinimumCompressionSize) {
updateInput.PatchOperations = append(updateInput.PatchOperations, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpReplace),
Expand Down Expand Up @@ -577,6 +610,38 @@ func resourceAwsApiGatewayRestApiUpdate(d *schema.ResourceData, meta interface{}
})
}

if v, ok := d.GetOk("disable_execute_api_endpoint"); ok && v.(bool) != aws.BoolValue(output.DisableExecuteApiEndpoint) {
updateInput.PatchOperations = append(updateInput.PatchOperations, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpReplace),
Path: aws.String("/disableExecuteApiEndpoint"),
Value: aws.String(strconv.FormatBool(v.(bool))),
})
}

if v, ok := d.GetOk("endpoint_configuration"); ok {
endpointConfiguration := expandApiGatewayEndpointConfiguration(v.([]interface{}))

if endpointConfiguration != nil && len(endpointConfiguration.VpcEndpointIds) > 0 {
if output.EndpointConfiguration != nil {
for _, elem := range output.EndpointConfiguration.VpcEndpointIds {
updateInput.PatchOperations = append(updateInput.PatchOperations, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpRemove),
Path: aws.String("/endpointConfiguration/vpcEndpointIds"),
Value: elem,
})
}
}

for _, elem := range endpointConfiguration.VpcEndpointIds {
updateInput.PatchOperations = append(updateInput.PatchOperations, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpAdd),
Path: aws.String("/endpointConfiguration/vpcEndpointIds"),
Value: elem,
})
}
}
}

if v := d.Get("minimum_compression_size").(int); v > -1 && int64(v) != aws.Int64Value(output.MinimumCompressionSize) {
updateInput.PatchOperations = append(updateInput.PatchOperations, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpReplace),
Expand Down
Loading