Skip to content

Commit 3381f48

Browse files
committed
added swagger for gateway
1 parent a84f5e0 commit 3381f48

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

main.tf

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ resource "aws_api_gateway_rest_api" "api" {
1010
}
1111

1212
resource "aws_api_gateway_deployment" "stage" {
13-
depends_on = [
14-
aws_api_gateway_integration.root_method_integration,
15-
aws_api_gateway_integration.integration
16-
]
17-
rest_api_id = "${aws_api_gateway_rest_api.api.id}"
13+
rest_api_id = aws_api_gateway_rest_api.api.id
1814
stage_name = var.env
15+
stage_description = md5(file(var.swagger-path))
1916
}
2017

2118
# Create only if root-resource is not empty
2219
resource "aws_api_gateway_method" "root_method" {
23-
count = "${var.root-resource == true ? 1 : 0}"
20+
count = var.root-resource == true ? 1 : 0
2421

2522
rest_api_id = aws_api_gateway_rest_api.api.id
2623
resource_id = aws_api_gateway_rest_api.api.root_resource_id
@@ -31,7 +28,7 @@ resource "aws_api_gateway_method" "root_method" {
3128
}
3229

3330
resource "aws_api_gateway_integration" "root_method_integration" {
34-
count = "${var.root-resource == true ? 1 : 0}"
31+
count = var.root-resource == true ? 1 : 0
3532

3633
rest_api_id = aws_api_gateway_rest_api.api.id
3734
resource_id = aws_api_gateway_rest_api.api.root_resource_id
@@ -42,26 +39,26 @@ resource "aws_api_gateway_integration" "root_method_integration" {
4239
}
4340

4441
resource "aws_api_gateway_resource" "resource" {
45-
count = "${length(var.method-paths)}"
46-
path_part = "${var.method-paths[count.index]}"
42+
count = length(var.method-paths)
43+
path_part = var.method-paths[count.index]
4744
parent_id = aws_api_gateway_rest_api.api.root_resource_id
4845
rest_api_id = aws_api_gateway_rest_api.api.id
4946
}
5047

5148
resource "aws_api_gateway_method" "method" {
52-
count = "${length(var.method-paths)}"
49+
count = length(var.method-paths)
5350
rest_api_id = aws_api_gateway_rest_api.api.id
54-
resource_id = "${aws_api_gateway_resource.resource[count.index].id}"
55-
http_method = "${var.method-types[count.index]}"
51+
resource_id = aws_api_gateway_resource.resource[count.index].id
52+
http_method = var.method-types[count.index]
5653
authorization = var.resource-authorization
5754
request_parameters = var.resource-request-params
5855
}
5956

6057
resource "aws_api_gateway_integration" "integration" {
61-
count = "${length(var.method-paths)}"
58+
count = length(var.method-paths)
6259
rest_api_id = aws_api_gateway_rest_api.api.id
63-
resource_id = "${aws_api_gateway_resource.resource[count.index].id}"
64-
http_method = "${aws_api_gateway_method.method[count.index].http_method}"
60+
resource_id = aws_api_gateway_resource.resource[count.index].id
61+
http_method = aws_api_gateway_method.method[count.index].http_method
6562
integration_http_method = "POST"
6663
type = "AWS_PROXY"
6764
uri = aws_lambda_function.lambda.invoke_arn
@@ -177,7 +174,7 @@ resource aws_lambda_function "lambda" {
177174
timeout = var.timeout
178175
vpc_config {
179176
security_group_ids = [
180-
"${aws_security_group.vpc_sec.id}"]
177+
aws_security_group.vpc_sec.id]
181178
subnet_ids = module.acs.private_subnet_ids
182179
}
183180
environment {

variables.tf

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ variable "account-id" {
4343
}
4444

4545
variable "method-paths" {
46-
type = list
46+
type = list(string)
4747
default = []
4848
}
4949

5050
variable "method-types" {
51-
type = list
51+
type = list(string)
5252
default = []
5353
}
5454

@@ -62,17 +62,17 @@ variable "root-resource-method" {
6262
}
6363

6464
variable "root-resource-request-params" {
65-
type = map
65+
type = map(string)
6666
default = {}
6767
}
6868

6969
variable "resource-request-params" {
70-
type = map
70+
type = map(string)
7171
default = {}
7272
}
7373

7474
variable "lambda-environment-variables" {
75-
type = map
75+
type = map(string)
7676
default = {}
7777
}
7878

@@ -86,6 +86,10 @@ variable "root-resource-authorization" {
8686
default = "NONE"
8787
}
8888

89+
variable "swagger-path" {
90+
type = string
91+
}
92+
8993
data "aws_ssm_parameter" "us-east-1-cert" {
9094
name = "/acs/acm/us-east-1/zone-cert-arn"
9195
}

0 commit comments

Comments
 (0)