File tree Expand file tree Collapse file tree
infrastructure/terraform/components/api Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,4 +3,8 @@ resource "aws_api_gateway_rest_api" "main" {
33 body = local. openapi_spec
44 description = " Suppliers API"
55 disable_execute_api_endpoint = var. disable_gateway_execute_endpoint
6+
7+ lifecycle {
8+ replace_triggered_by = [terraform_data . rest_api_security_policy ]
9+ }
610}
Original file line number Diff line number Diff line change 1- # Terraform does not yet support setting the securityPolicy on aws_api_gateway_rest_api
2- # directly. This terraform_data resource works around that by calling the AWS CLI
3- # to enforce TLS 1.2 on the REST API after it is created or replaced.
4- resource "terraform_data" "rest_api_tls_policy" {
5- triggers_replace = [aws_api_gateway_rest_api . main . id ]
1+ # AWS does not support updating the securityPolicy on an existing REST API from
2+ # TLS_1_0 to TLS_1_2 in-place. The policy must be set at creation time via the
3+ # x-amazon-apigateway-security-policy OpenAPI extension in the API body
4+ # (see spec.tmpl.json). This terraform_data resource forces recreation of the
5+ # aws_api_gateway_rest_api whenever the desired security policy changes, ensuring
6+ # the new API is always created with the correct TLS version.
7+ locals {
8+ rest_api_security_policy = " TLS_1_2"
9+ }
610
7- provisioner "local-exec" {
8- command = <<- EOT
9- aws apigateway update-rest-api \
10- --region ${ var . region } \
11- --rest-api-id ${ aws_api_gateway_rest_api . main . id } \
12- --patch-operations op=replace,path=/securityPolicy,value=TLS_1_2
13- EOT
14- }
11+ resource "terraform_data" "rest_api_security_policy" {
12+ input = local. rest_api_security_policy
1513}
Original file line number Diff line number Diff line change 77 openapi_spec = templatefile (" ${ path . module } /resources/spec.tmpl.json" , {
88 APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
99 AWS_REGION = var.region
10+ TLS_VERSION = local.rest_api_security_policy
1011 AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
1112 GET_LETTER_LAMBDA_ARN = module.get_letter.function_arn
1213 GET_LETTERS_LAMBDA_ARN = module.get_letters.function_arn
Original file line number Diff line number Diff line change 307307 }
308308 }
309309 }
310- }
310+ },
311+ "x-amazon-apigateway-security-policy" : " ${SECURITY_POLICY}"
311312}
You can’t perform that action at this time.
0 commit comments