Skip to content

Commit 2d0cee3

Browse files
Fix: Error in count condition of HTTP-Api-Gateway (#60)
* fix: resolved a kms key error in http-api * fix: remove unnecessary comment * fix: resolve a tflint interpolation issue * fix: fixed variable default value * fix: updated a directory structure * fix: update a .github/workflow/tf-check.yml file * fix: Change the name of the example file. * fix: upadate a tf-check file --------- Co-authored-by: CloudDrove CI <84795582+clouddrove-ci@users.noreply.github.com>
1 parent 2957285 commit 2d0cee3

File tree

14 files changed

+560
-5
lines changed

14 files changed

+560
-5
lines changed

.github/workflows/tf-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
tf-checks-complete-example:
1010
uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master
1111
with:
12-
working_directory: './examples/complete/'
12+
working_directory: './examples/'
1313
tf-checks-basic-example:
1414
uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@master
1515
with:

examples/http-api-gateway/example.tf

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
####----------------------------------------------------------------------------------
2+
## PROVIDER
3+
####----------------------------------------------------------------------------------
4+
provider "aws" {
5+
region = local.region
6+
}
7+
8+
####----------------------------------------------------------------------------------
9+
## LOCALS
10+
####----------------------------------------------------------------------------------
11+
12+
locals {
13+
name = "api"
14+
environment = "test"
15+
region = "us-east-1"
16+
domain_name = "clouddrove.ca"
17+
hosted_zone_id = "Z0xxxxxxxxxxxxxxEP"
18+
}
19+
####----------------------------------------------------------------------------------
20+
## ACM
21+
####----------------------------------------------------------------------------------
22+
module "acm" {
23+
source = "clouddrove/acm/aws"
24+
version = "1.4.1"
25+
26+
name = local.name
27+
environment = local.environment
28+
enable_aws_certificate = true
29+
domain_name = local.domain_name
30+
subject_alternative_names = ["*.${local.domain_name}"]
31+
validation_method = "DNS"
32+
enable_dns_validation = false
33+
}
34+
35+
####----------------------------------------------------------------------------------
36+
## LAMBDA
37+
####----------------------------------------------------------------------------------
38+
module "lambda" {
39+
source = "clouddrove/lambda/aws"
40+
version = "1.3.1"
41+
42+
name = local.name
43+
environment = local.environment
44+
enable = true
45+
timeout = 60
46+
filename = "../lambda_packages/index.zip"
47+
handler = "index.lambda_handler"
48+
runtime = "python3.8"
49+
iam_actions = [
50+
"logs:CreateLogStream",
51+
"logs:CreateLogGroup",
52+
"logs:PutLogEvents"
53+
]
54+
names = [
55+
"python_layer"
56+
]
57+
compatible_runtimes = [
58+
["python3.8"]
59+
]
60+
statement_ids = [
61+
"AllowExecutionFromApiGateway"
62+
]
63+
actions = [
64+
"lambda:InvokeFunction"
65+
]
66+
principals = [
67+
"apigateway.amazonaws.com"
68+
]
69+
variables = {
70+
foo = "bar"
71+
}
72+
}
73+
74+
####----------------------------------------------------------------------------------
75+
## API GATEWAY
76+
####----------------------------------------------------------------------------------
77+
module "api_gateway" {
78+
source = "../../."
79+
80+
name = local.name
81+
environment = local.environment
82+
domain_name = "api.${local.domain_name}"
83+
domain_name_certificate_arn = module.acm.arn
84+
integration_uri = module.lambda.invoke_arn
85+
zone_id = local.hosted_zone_id
86+
auto_deploy = true
87+
stage_name = "$default"
88+
create_vpc_link_enabled = false
89+
create_http_api = true
90+
cors_configuration = {
91+
allow_credentials = true
92+
allow_methods = ["GET", "OPTIONS", "POST"]
93+
max_age = 5
94+
}
95+
integrations = {
96+
"ANY /" = {
97+
lambda_arn = module.lambda.arn
98+
payload_format_version = "2.0"
99+
timeout_milliseconds = 30000
100+
}
101+
"GET /some-route-with-authorizer" = {
102+
lambda_arn = module.lambda.arn
103+
payload_format_version = "1.0"
104+
authorizer_key = "cognito"
105+
}
106+
"POST /start-step-function" = {
107+
lambda_arn = module.lambda.arn
108+
payload_format_version = "1.0"
109+
authorizer_key = "cognito"
110+
}
111+
}
112+
}

examples/http-api-gateway/outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "api_id" {
2+
value = module.api_gateway.api_id
3+
description = "The API identifier."
4+
}
5+
6+
output "api_arn" {
7+
value = module.api_gateway.api_arn
8+
description = "The API arn."
9+
}
10+
11+
output "api_endpoint" {
12+
value = module.api_gateway.api_endpoint
13+
description = "The URI of the API, of the form {api-id}.execute-api.{region}.amazonaws.com."
14+
}
15+
16+
output "invoke_url" {
17+
value = module.api_gateway.invoke_url
18+
description = "URL to invoke the API pointing to the stage"
19+
}

examples/http-api-gateway/version.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Terraform version
2+
terraform {
3+
required_version = ">= 1.6.1"
4+
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = ">= 5.20.0"
9+
}
10+
}
11+
}

examples/lambda_packages/index.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import json
2+
def lambda_handler(event, context):
3+
print('Lambda function with Python!|')
4+
return {
5+
'statusCode': 200,
6+
'body': json.dumps('Hello from Lambda!')
7+
}

examples/lambda_packages/index.zip

335 Bytes
Binary file not shown.
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
####----------------------------------------------------------------------------------
2+
## PROVIDER
3+
####----------------------------------------------------------------------------------
4+
5+
provider "aws" {
6+
region = local.region
7+
}
8+
####----------------------------------------------------------------------------------
9+
## LOCALS
10+
####----------------------------------------------------------------------------------
11+
12+
locals {
13+
name = "api"
14+
environment = "test"
15+
region = "us-east-1"
16+
domain_name = "clouddrove.ca"
17+
hosted_zone_id = "Z015XXXXXXXXXXXXXXIEP"
18+
}
19+
####----------------------------------------------------------------------------------
20+
## ACM
21+
####----------------------------------------------------------------------------------
22+
23+
module "acm" {
24+
source = "clouddrove/acm/aws"
25+
version = "1.4.1"
26+
27+
name = local.name
28+
environment = local.environment
29+
enable_aws_certificate = true
30+
domain_name = local.domain_name
31+
subject_alternative_names = ["*.${local.domain_name}"]
32+
validation_method = "DNS"
33+
enable_dns_validation = false
34+
}
35+
36+
####----------------------------------------------------------------------------------
37+
## LAMBDA
38+
####----------------------------------------------------------------------------------
39+
40+
module "lambda" {
41+
source = "clouddrove/lambda/aws"
42+
version = "1.3.1"
43+
44+
name = local.name
45+
environment = local.environment
46+
enable = true
47+
timeout = 60
48+
filename = "../lambda_packages/index.zip"
49+
handler = "index.lambda_handler"
50+
runtime = "python3.8"
51+
iam_actions = [
52+
"logs:CreateLogStream",
53+
"logs:CreateLogGroup",
54+
"logs:PutLogEvents"
55+
]
56+
names = [
57+
"python_layer"
58+
]
59+
compatible_runtimes = [
60+
["python3.8"]
61+
]
62+
statement_ids = [
63+
"AllowExecutionFromApiGateway"
64+
]
65+
actions = [
66+
"lambda:InvokeFunction"
67+
]
68+
principals = [
69+
"apigateway.amazonaws.com"
70+
]
71+
variables = {
72+
foo = "bar"
73+
}
74+
}
75+
76+
77+
####----------------------------------------------------------------------------------
78+
## VPC
79+
####----------------------------------------------------------------------------------
80+
81+
module "vpc" {
82+
source = "clouddrove/vpc/aws"
83+
version = "2.0.0"
84+
85+
name = "${local.name}-rest-api-private"
86+
environment = local.environment
87+
enable = true
88+
cidr_block = "10.0.0.0/16"
89+
90+
}
91+
92+
####----------------------------------------------------------------------------------
93+
## SUBNETS
94+
####----------------------------------------------------------------------------------
95+
#tfsec:ignore:aws-ec2-no-excessive-port-access
96+
#tfsec:ignore:aws-ec2-no-public-ingress-acl
97+
module "subnets" {
98+
source = "clouddrove/subnet/aws"
99+
version = "2.0.1"
100+
101+
name = "${local.name}-rest-api-private"
102+
environment = local.environment
103+
104+
nat_gateway_enabled = true
105+
single_nat_gateway = true
106+
availability_zones = ["${local.region}a", "${local.region}b", "${local.region}c"]
107+
vpc_id = module.vpc.vpc_id
108+
type = "public-private"
109+
igw_id = module.vpc.igw_id
110+
cidr_block = module.vpc.vpc_cidr_block
111+
ipv6_cidr_block = module.vpc.ipv6_cidr_block
112+
enable_ipv6 = true
113+
private_inbound_acl_rules = [
114+
{
115+
rule_number = 100
116+
rule_action = "allow"
117+
from_port = 0
118+
to_port = 0
119+
protocol = "-1"
120+
cidr_block = module.vpc.vpc_cidr_block
121+
}
122+
]
123+
private_outbound_acl_rules = [
124+
{
125+
rule_number = 100
126+
rule_action = "allow"
127+
from_port = 0
128+
to_port = 0
129+
protocol = "-1"
130+
cidr_block = module.vpc.vpc_cidr_block
131+
}
132+
]
133+
public_inbound_acl_rules = [
134+
{
135+
rule_number = 100
136+
rule_action = "allow"
137+
from_port = 0
138+
to_port = 0
139+
protocol = "-1"
140+
cidr_block = "0.0.0.0/0"
141+
}
142+
]
143+
public_outbound_acl_rules = [
144+
{
145+
rule_number = 100
146+
rule_action = "allow"
147+
from_port = 0
148+
to_port = 0
149+
protocol = "-1"
150+
cidr_block = "0.0.0.0/0"
151+
}
152+
]
153+
154+
}
155+
156+
####----------------------------------------------------------------------------------
157+
## SECURITY GROUP
158+
####----------------------------------------------------------------------------------
159+
160+
module "security_group" {
161+
source = "clouddrove/security-group/aws"
162+
version = "2.0.0"
163+
164+
name = "${local.name}-rest-api-private"
165+
environment = local.environment
166+
167+
vpc_id = module.vpc.vpc_id
168+
new_sg_ingress_rules_with_cidr_blocks = [
169+
{
170+
rule_count = 1
171+
from_port = 0
172+
protocol = "-1"
173+
to_port = 0
174+
cidr_blocks = [module.vpc.vpc_cidr_block]
175+
description = "Allow all traffic from ${local.environment} VPC."
176+
}
177+
]
178+
new_sg_egress_rules_with_cidr_blocks = [
179+
{
180+
rule_count = 1
181+
from_port = 0
182+
protocol = "-1"
183+
to_port = 0
184+
cidr_blocks = [module.vpc.vpc_cidr_block]
185+
description = "Allow all outbound traffic."
186+
}
187+
]
188+
}
189+
190+
191+
####----------------------------------------------------------------------------------
192+
## REST API PRIVATE
193+
####----------------------------------------------------------------------------------
194+
195+
module "rest_api_private" {
196+
source = "../../."
197+
198+
name = "${local.name}-rest-api-private"
199+
environment = local.environment
200+
enabled = true
201+
create_rest_api = true
202+
rest_api_endpoint_type = "PRIVATE"
203+
rest_api_description = "Private REST API for ${module.lambda.name} lambda function"
204+
integration_uri = module.lambda.invoke_arn
205+
rest_api_stage_name = "default"
206+
auto_deploy = true
207+
rest_api_base_path = "test"
208+
domain_name = "api.${local.domain_name}"
209+
zone_id = local.hosted_zone_id
210+
211+
# -- VPC Endpoint configuration
212+
vpc_id = module.vpc.vpc_id
213+
subnet_ids = module.subnets.private_subnet_id
214+
security_group_ids = [module.security_group.security_group_id]
215+
service_name = "com.amazonaws.${local.region}.execute-api"
216+
vpc_endpoint_type = "Interface"
217+
private_dns_enabled = true
218+
domain_name_certificate_arn = module.acm.arn
219+
220+
#---access log----
221+
enable_access_logs = true
222+
retention_in_days = 7
223+
}
224+
225+

0 commit comments

Comments
 (0)