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

r/api_gateway_method_settings: allow zero ttl #12651

Merged
merged 4 commits into from
Jul 31, 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: 18 additions & 5 deletions aws/resource_aws_api_gateway_method_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

func resourceAwsApiGatewayMethodSettings() *schema.Resource {
Expand Down Expand Up @@ -52,6 +53,11 @@ func resourceAwsApiGatewayMethodSettings() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"OFF",
"ERROR",
"INFO",
}, false),
},
"data_trace_enabled": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -91,6 +97,11 @@ func resourceAwsApiGatewayMethodSettings() *schema.Resource {
"unauthorized_cache_control_header_strategy": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
apigateway.UnauthorizedCacheControlHeaderStrategyFailWith403,
apigateway.UnauthorizedCacheControlHeaderStrategySucceedWithResponseHeader,
apigateway.UnauthorizedCacheControlHeaderStrategySucceedWithoutResponseHeader,
}, false),
Computed: true,
},
},
Expand Down Expand Up @@ -145,7 +156,7 @@ func resourceAwsApiGatewayMethodSettingsRead(d *schema.ResourceData, meta interf
}

if err := d.Set("settings", flattenAwsApiGatewayMethodSettings(settings)); err != nil {
return fmt.Errorf("error setting settings: %s", err)
return fmt.Errorf("error setting settings: %w", err)
}

return nil
Expand Down Expand Up @@ -201,13 +212,15 @@ func resourceAwsApiGatewayMethodSettingsUpdate(d *schema.ResourceData, meta inte
Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.caching_enabled").(bool))),
})
}
if d.HasChange("settings.0.cache_ttl_in_seconds") {

if v, ok := d.GetOkExists("settings.0.cache_ttl_in_seconds"); ok {
ops = append(ops, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpReplace),
Path: aws.String(prefix + "caching/ttlInSeconds"),
Value: aws.String(fmt.Sprintf("%d", d.Get("settings.0.cache_ttl_in_seconds").(int))),
Value: aws.String(fmt.Sprintf("%d", v.(int))),
})
}

if d.HasChange("settings.0.cache_data_encrypted") {
ops = append(ops, &apigateway.PatchOperation{
Op: aws.String(apigateway.OpReplace),
Expand Down Expand Up @@ -240,7 +253,7 @@ func resourceAwsApiGatewayMethodSettingsUpdate(d *schema.ResourceData, meta inte
log.Printf("[DEBUG] Updating API Gateway Stage: %s", input)
_, err := conn.UpdateStage(&input)
if err != nil {
return fmt.Errorf("Updating API Gateway Stage failed: %s", err)
return fmt.Errorf("updating API Gateway Stage failed: %w", err)
}

d.SetId(restApiId + "-" + stageName + "-" + methodPath)
Expand All @@ -265,7 +278,7 @@ func resourceAwsApiGatewayMethodSettingsDelete(d *schema.ResourceData, meta inte
log.Printf("[DEBUG] Updating API Gateway Stage: %s", input)
_, err := conn.UpdateStage(&input)
if err != nil {
return fmt.Errorf("Updating API Gateway Stage failed: %s", err)
return fmt.Errorf("updating API Gateway Stage failed: %w", err)
}

return nil
Expand Down
8 changes: 8 additions & 0 deletions aws/resource_aws_api_gateway_method_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ func TestAccAWSAPIGatewayMethodSettings_Settings_CacheTtlInSeconds(t *testing.T)
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGatewayMethodSettingsDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAPIGatewayMethodSettingsConfigSettingsCacheTtlInSeconds(rName, 0),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayMethodSettingsExists(resourceName, &stage1),
resource.TestCheckResourceAttr(resourceName, "settings.#", "1"),
resource.TestCheckResourceAttr(resourceName, "settings.0.cache_ttl_in_seconds", "0"),
),
},
{
Config: testAccAWSAPIGatewayMethodSettingsConfigSettingsCacheTtlInSeconds(rName, 1),
Check: resource.ComposeTestCheckFunc(
Expand Down