From 2b506748069fbc3cbfa20b22d207d989dd06a5e9 Mon Sep 17 00:00:00 2001 From: Manu Chandrasekhar Date: Mon, 10 Jun 2024 18:53:27 -0400 Subject: [PATCH] docs: added examples for awscc_apigateway_gateway_response --- docs/resources/apigateway_gateway_response.md | 35 ++++++++++++++++++- .../apigateway_gateway_response_401.tf | 13 +++++++ .../apigateway_gateway_response_404.tf | 10 ++++++ .../apigateway_gateway_response.md.tmpl | 32 +++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 examples/resources/awscc_apigateway_gateway_response/apigateway_gateway_response_401.tf create mode 100644 examples/resources/awscc_apigateway_gateway_response/apigateway_gateway_response_404.tf create mode 100644 templates/resources/apigateway_gateway_response.md.tmpl diff --git a/docs/resources/apigateway_gateway_response.md b/docs/resources/apigateway_gateway_response.md index 6f1b546a3..149cbd9fe 100644 --- a/docs/resources/apigateway_gateway_response.md +++ b/docs/resources/apigateway_gateway_response.md @@ -1,5 +1,4 @@ --- -# generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "awscc_apigateway_gateway_response Resource - terraform-provider-awscc" subcategory: "" description: |- @@ -10,7 +9,41 @@ description: |- The ``AWS::ApiGateway::GatewayResponse`` resource creates a gateway response for your API. For more information, see [API Gateway Responses](https://docs.aws.amazon.com/apigateway/latest/developerguide/customize-gateway-responses.html#api-gateway-gatewayResponse-definition) in the *API Gateway Developer Guide*. +## Example Usage +### 404 Response +The following example returns a 404 status code for resource not found instead of missing authentication token for a CORS request (applicable to unsecured/unrestricted APIs). + +```terraform +resource "awscc_apigateway_gateway_response" "example" { + rest_api_id = awscc_apigateway_rest_api.example.id + status_code = "404" + response_type = "MISSING_AUTHENTICATION_TOKEN" + + response_parameters = { + "gatewayresponse.header.Access-Control-Allow-Origin" = "'*'" + "gatewayresponse.header.Access-Control-Allow-Headers" = "'*'" + } +} +``` + +### 401 Response + +```terraform +resource "awscc_apigateway_gateway_response" "example" { + rest_api_id = awscc_apigateway_rest_api.example.id + status_code = "401" + response_type = "UNAUTHORIZED" + + response_templates = { + "application/json" = "{\"message\":$context.error.messageString}" + } + + response_parameters = { + "gatewayresponse.header.Authorization" = "'Basic'" + } +} +``` ## Schema diff --git a/examples/resources/awscc_apigateway_gateway_response/apigateway_gateway_response_401.tf b/examples/resources/awscc_apigateway_gateway_response/apigateway_gateway_response_401.tf new file mode 100644 index 000000000..aa145b1bf --- /dev/null +++ b/examples/resources/awscc_apigateway_gateway_response/apigateway_gateway_response_401.tf @@ -0,0 +1,13 @@ +resource "awscc_apigateway_gateway_response" "example" { + rest_api_id = awscc_apigateway_rest_api.example.id + status_code = "401" + response_type = "UNAUTHORIZED" + + response_templates = { + "application/json" = "{\"message\":$context.error.messageString}" + } + + response_parameters = { + "gatewayresponse.header.Authorization" = "'Basic'" + } +} diff --git a/examples/resources/awscc_apigateway_gateway_response/apigateway_gateway_response_404.tf b/examples/resources/awscc_apigateway_gateway_response/apigateway_gateway_response_404.tf new file mode 100644 index 000000000..685e18cd9 --- /dev/null +++ b/examples/resources/awscc_apigateway_gateway_response/apigateway_gateway_response_404.tf @@ -0,0 +1,10 @@ +resource "awscc_apigateway_gateway_response" "example" { + rest_api_id = awscc_apigateway_rest_api.example.id + status_code = "404" + response_type = "MISSING_AUTHENTICATION_TOKEN" + + response_parameters = { + "gatewayresponse.header.Access-Control-Allow-Origin" = "'*'" + "gatewayresponse.header.Access-Control-Allow-Headers" = "'*'" + } +} diff --git a/templates/resources/apigateway_gateway_response.md.tmpl b/templates/resources/apigateway_gateway_response.md.tmpl new file mode 100644 index 000000000..7365ed980 --- /dev/null +++ b/templates/resources/apigateway_gateway_response.md.tmpl @@ -0,0 +1,32 @@ +--- +page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" +subcategory: "" +description: |- +{{ .Description | plainmarkdown | trimspace | prefixlines " " }} +--- + +# {{.Name}} ({{.Type}}) + +{{ .Description | trimspace }} + +## Example Usage + +### 404 Response +The following example returns a 404 status code for resource not found instead of missing authentication token for a CORS request (applicable to unsecured/unrestricted APIs). + +{{ tffile (printf "examples/resources/%s/apigateway_gateway_response_404.tf" .Name)}} + +### 401 Response + +{{ tffile (printf "examples/resources/%s/apigateway_gateway_response_401.tf" .Name)}} + +{{ .SchemaMarkdown | trimspace }} +{{- if .HasImport }} + +## Import + +Import is supported using the following syntax: + +{{ codefile "shell" .ImportFile }} + +{{- end }}