Project: KICS (Provisioning / Security & Compliance)
File: b3a59b8e-94a3-403e-b6e2-527abaf12034.md

title: API Gateway Deployment Without API Gateway UsagePlan Associated hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: b3a59b8e-94a3-403e-b6e2-527abaf12034 Query name: API Gateway Deployment Without API Gateway UsagePlan Associated Platform: Terraform Severity: <span style="color:#edd57e">Low</span> Category: Observability URL: API Gateway Deployment should have API Gateway UsagePlan defined and associated.<br> ```tf title="Positive test num. 1 - tf file" hl_lines="1 9" resource "awsapigateway_deployment" "positive1" { restapiid = "some rest api id" stage_name = "some name" tags { project = "ProjectName" } } resource "awsapigateway_deployment" "positive2" { restapiid = "some rest api id" stage_name = "development" } resource "awsapigatewayusageplan" "positive3" { name = "my-usage-plan" description = "my description" product_code = "MYCODE" api_stages { api_id = "another id" stage = "development" } } ``` ```json title="Positive test num. 2 - json file" hl_lines="14 31" { "format_version": "0.2", "terraform_version": "1.0.5", "planned_values": { "root_module": { "resources": [ { "address": "awsapigateway_deployment.positive1", "mode": "managed", "type": "awsapigateway_deployment", "name": "positive1", "provider_name": "registry.terraform.io/hashicorp/aws", "schema_version": 0, "values": { "description": null, "restapiid": "some rest api id", "stage_description": null, "stage_name": "some name", "triggers": null, "variables": null }, "sensitive_values": {} }, { "address": "awsapigateway_deployment.positive2", "mode": "managed", "type": "awsapigateway_deployment", "name": "positive2", "provider_name": "registry.terraform.io/hashicorp/aws", "schema_version": 0, "values": { "description": null, "restapiid": "some rest api id", "stage_description": null, "stage_name": "development", "triggers": null, "variables": null }, "sensitive_values": {} }, { "address": "awsapigatewayusageplan.positive3", "mode": "managed", "type": "awsapigatewayusageplan", "name": "positive3", "provider_name": "registry.terraform.io/hashicorp/aws", "schema_version": 0, "values": { "api_stages": [ { "api_id": "another id", "stage": "development" } ], "description": "my description", "name": "my-usage-plan", "product_code": "MYCODE", "quota_settings": [], "tags": null, "throttle_settings": [] }, "sensitive_values": { "api_stages": [ {} ], "quota_settings": [], "tags_all": {}, "throttle_settings": [] } } ] } }, "resource_changes": [ { "address": "awsapigateway_deployment.positive1", "mode": "managed", "type": "awsapigateway_deployment", "name": "positive1", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": [ "create" ], "before": null, "after": { "description": null, "restapiid": "some rest api id", "stage_description": null, "stage_name": "some name", "triggers": null, "variables": null }, "after_unknown": { "created_date": true, "execution_arn": true, "id": true, "invoke_url": true }, "before_sensitive": false, "after_sensitive": {} } }, { "address": "awsapigateway_deployment.positive2", "mode": "managed", "type": "awsapigateway_deployment", "name": "positive2", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": [ "create" ], "before": null, "after": { "description": null, "restapiid": "some rest api id", "stage_description": null, "stage_name": "development", "triggers": null, "variables": null }, "after_unknown": { "created_date": true, "execution_arn": true, "id": true, "invoke_url": true }, "before_sensitive": false, "after_sensitive": {} } }, { "address": "awsapigatewayusageplan.positive3", "mode": "managed", "type": "awsapigatewayusageplan", "name": "positive3", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": [ "create" ], "before": null, "after": { "api_stages": [ { "api_id": "another id", "stage": "development" } ], "description": "my description", "name": "my-usage-plan", "product_code": "MYCODE", "quota_settings": [], "tags": null, "throttle_settings": [] }, "after_unknown": { "api_stages": [ {} ], "arn": true, "id": true, "quota_settings": [], "tags_all": true, "throttle_settings": [] }, "before_sensitive": false, "after_sensitive": { "api_stages": [ {} ], "quota_settings": [], "tags_all": {}, "throttle_settings": [] } } } ], "configuration": { "root_module": { "resources": [ { "address":

"mode": "managed", "type": "awsapigateway_deployment", "name": "positive1", "providerconfigkey": "aws", "expressions": { "restapiid": { "constant_value": "some rest api id" }, "stage_name": { "constant_value": "some name" } }, "schema_version": 0 }, { "address": "awsapigateway_deployment.positive2", "mode": "managed", "type": "awsapigateway_deployment", "name": "positive2", "providerconfigkey": "aws", "expressions": { "restapiid": { "constant_value": "some rest api id" }, "stage_name": { "constant_value": "development" } }, "schema_version": 0 }, { "address": "awsapigatewayusageplan.positive3", "mode": "managed", "type": "awsapigatewayusageplan", "name": "positive3", "providerconfigkey": "aws", "expressions": { "api_stages": [ { "api_id": { "constant_value": "another id" }, "stage": { "constant_value": "development" } } ], "description": { "constant_value": "my description" }, "name": { "constant_value": "my-usage-plan" }, "product_code": { "constant_value": "MYCODE" } }, "schema_version": 0 } ] } } } ``` ```tf title="Negative test num. 1 - tf file" resource "awsapigateway_deployment" "negative1" { restapiid = "restapi1" stage_name = "development" } resource "awsapigatewayusageplan" "negative2" { name = "my-usage-plan" description = "my description" product_code = "MYCODE" api_stages { apiid = "restapi_1" stage = "development" } api_stages { apiid = "restapi_2" stage = "development_2" } } ``` ```json title="Negative test num. 2 - json file" { "format_version": "0.2", "terraform_version": "1.0.5", "planned_values": { "root_module": { "resources": [ { "address": "awsapigateway_deployment.negative1", "mode": "managed", "type": "awsapigateway_deployment", "name": "negative1", "provider_name": "registry.terraform.io/hashicorp/aws", "schema_version": 0, "values": { "description": null, "restapiid": "restapi1", "stage_description": null, "stage_name": "development", "triggers": null, "variables": null }, "sensitive_values": {} }, { "address": "awsapigatewayusageplan.negative2", "mode": "managed", "type": "awsapigatewayusageplan", "name": "negative2", "provider_name": "registry.terraform.io/hashicorp/aws", "schema_version": 0, "values": { "api_stages": [ { "apiid": "restapi_1", "stage": "development" } ], "description": "my description", "name": "my-usage-plan", "product_code": "MYCODE", "quota_settings": [], "tags": null, "throttle_settings": [] }, "sensitive_values": { "api_stages": [ {} ], "quota_settings": [], "tags_all": {}, "throttle_settings": [] } } ] } }, "resource_changes": [ { "address": "awsapigateway_deployment.negative1", "mode": "managed", "type": "awsapigateway_deployment", "name": "negative1", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": [ "create" ], "before": null, "after": { "description": null, "restapiid": "restapi1", "stage_description": null, "stage_name": "development", "triggers": null, "variables": null }, "after_unknown": { "created_date": true, "execution_arn": true, "id": true, "invoke_url": true }, "before_sensitive": false, "after_sensitive": {} } }, { "address": "awsapigatewayusageplan.negative2", "mode": "managed", "type": "awsapigatewayusageplan", "name": "negative2", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": [ "create" ], "before": null, "after": { "api_stages": [ { "apiid": "restapi_1", "stage": "development" } ], "description": "my description", "name": "my-usage-plan", "product_code": "MYCODE", "quota_settings": [], "tags": null, "throttle_settings": [] }, "after_unknown": { "api_stages": [ {} ], "arn": true, "id": true, "quota_settings": [], "tags_all": true, "throttle_settings": [] }, "before_sensitive": false, "after_sensitive": { "api_stages": [ {} ], "quota_settings": [], "tags_all": {}, "throttle_settings": [] } } } ], "configuration": { "root_module": { "resources": [ { "address": "awsapigateway_deployment.negative1", "mode": "managed", "type": "awsapigateway_deployment", "name": "negative1", "providerconfigkey": "aws", "expressions": { "restapiid": { "constantvalue": "restapi_1" }, "stage_name": { "constant_value": "development" } }, "schema_version": 0 }, { "address": "awsapigatewayusageplan.negative2", "mode": "managed", "type": "awsapigatewayusageplan", "name": "negative2", "providerconfigkey": "aws", "expressions": { "api_stages": [ { "api_id": { "constantvalue": "restapi_1" }, "stage": { "constant_value": "development" } } ], "description": { "constant_value": "my description" }, "name": { "constant_value": "my-usage-plan" }, "product_code": { "constant_value": "MYCODE" } }, "schema_version": 0 } ] } } } ```