Skip to content

Commit bd5e8e3

Browse files
authored
Create terraform setup (#219)
1 parent 4549938 commit bd5e8e3

File tree

9 files changed

+183
-1
lines changed

9 files changed

+183
-1
lines changed

.github/workflows/deploy-qa.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ jobs:
2020
env:
2121
HUSKY: "0"
2222

23+
- name: Setup Terraform
24+
uses: hashicorp/setup-terraform@v2
25+
with:
26+
terraform_version: 1.12.2
27+
28+
2329
- name: Set up Node
2430
uses: actions/setup-node@v4
2531
with:
@@ -102,6 +108,11 @@ jobs:
102108
node-version: 22.x
103109
cache: "yarn"
104110

111+
- name: Setup Terraform
112+
uses: hashicorp/setup-terraform@v2
113+
with:
114+
terraform_version: 1.12.2
115+
105116
- name: Restore Yarn Cache
106117
uses: actions/cache@v4
107118
with:

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"rvest.vs-code-prettier-eslint",
55
"eamodio.gitlens",
66
"ms-vscode.makefile-tools",
7-
"amazonwebservices.aws-toolkit-vscode"
7+
"amazonwebservices.aws-toolkit-vscode",
8+
"hashicorp.terraform"
89
]
910
}

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,17 @@ postdeploy:
9090

9191
deploy_prod: check_account_prod
9292
@echo "Deploying CloudFormation stack..."
93+
terraform -chdir=terraform/envs/prod apply -auto-approve
94+
terraform -chdir=terraform/envs/prod init
9395
sam deploy $(common_params) --parameter-overrides $(run_env)=prod $(set_application_prefix)=$(application_key) $(set_application_name)="$(application_name)" S3BucketPrefix="$(s3_bucket_prefix)"
9496
make postdeploy
9597

9698
deploy_dev: check_account_dev
9799
@echo "Deploying CloudFormation stack..."
98100
sam deploy $(common_params) --parameter-overrides $(run_env)=dev $(set_application_prefix)=$(application_key) $(set_application_name)="$(application_name)" S3BucketPrefix="$(s3_bucket_prefix)"
101+
@echo "Deploying Terraform..."
102+
terraform -chdir=terraform/envs/qa init
103+
terraform -chdir=terraform/envs/qa apply -auto-approve
99104
make postdeploy
100105

101106
invalidate_cloudfront:
@@ -114,13 +119,19 @@ invalidate_cloudfront:
114119
install:
115120
yarn -D
116121
pip install cfn-lint
122+
terraform -chdir=terraform/envs/qa init
123+
terraform -chdir=terraform/envs/prod init
117124

118125
test_live_integration: install
119126
yarn test:live
120127

121128
test_unit: install
122129
yarn lint
123130
cfn-lint cloudformation/**/*
131+
terraform -chdir=terraform/envs/qa fmt -check
132+
terraform -chdir=terraform/envs/prod fmt -check
133+
terraform -chdir=terraform/envs/qa validate
134+
terraform -chdir=terraform/envs/prod validate
124135
yarn prettier
125136
yarn test:unit
126137

cloudformation/logs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Parameters:
1010
Resources:
1111
AppApiLambdaLogGroup:
1212
Type: AWS::Logs::LogGroup
13+
DeletionPolicy: Retain
14+
UpdateReplacePolicy: Retain
1315
Properties:
1416
LogGroupName:
1517
Fn::Sub: /aws/lambda/${LambdaFunctionName}

terraform/.gitignore

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# OSX leaves these everywhere on SMB shares
2+
._*
3+
4+
# OSX trash
5+
.DS_Store
6+
7+
# Python
8+
*.pyc
9+
10+
# Emacs save files
11+
*~
12+
\#*\#
13+
.\#*
14+
15+
# Vim-related files
16+
[._]*.s[a-w][a-z]
17+
[._]s[a-w][a-z]
18+
*.un~
19+
Session.vim
20+
.netrwhist
21+
22+
### https://raw.github.com/github/gitignore/90f149de451a5433aebd94d02d11b0e28843a1af/Terraform.gitignore
23+
24+
# Local .terraform directories
25+
**/.terraform*
26+
27+
# .tfstate files
28+
*.tfstate
29+
*.tfstate.*
30+
31+
# Local tfvars terraform.tfvars
32+
**/*.tfvars
33+
34+
# tf lock file
35+
**/.terraform.lock.hcl
36+
37+
# Crash log files
38+
crash.log
39+
40+
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
41+
# .tfvars files are managed as part of configuration and so should be included in
42+
# version control.
43+
#
44+
# example.tfvars
45+
46+
# Ignore override files as they are usually used to override resources locally and so
47+
# are not checked in
48+
override.tf
49+
override.tf.json
50+
*_override.tf
51+
*_override.tf.json
52+
.idea/
53+
.vscode/
54+
# Kitchen files
55+
**/inspec.lock
56+
**.gem
57+
**/.kitchen
58+
**/.kitchen.local.yml
59+
**/Gemfile.lock
60+
# Plan files
61+
**/tmp_plan
62+
**/.tmp
63+
**/tmp
64+
65+
test/fixtures/shared/terraform.tfvars
66+
67+
test/integration/gcloud/config.sh
68+
test/integration/tmp
69+
70+
credentials.json
71+
72+
helpers/foundation-deployer/foundation-deployer
73+
helpers/foundation-deployer/.steps.json
74+
75+
# File to populate env vars used by Docker test runs
76+
.envrc
77+
78+
# Handle files generated on sed command by old (2013-) MacOS versions
79+
*.tf-e
80+
81+
# Go multi-module workspace sum
82+
go.work.sum

terraform/envs/prod/main.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5.92"
6+
}
7+
}
8+
9+
required_version = ">= 1.2"
10+
}
11+
12+
provider "aws" {
13+
region = "us-east-1"
14+
default_tags {
15+
tags = {
16+
project = var.ProjectId
17+
}
18+
}
19+
}
20+
21+
import {
22+
to = aws_cloudwatch_log_group.main_app_logs
23+
id = "/aws/lambda/${var.ProjectId}-lambda"
24+
}
25+
resource "aws_cloudwatch_log_group" "main_app_logs" {
26+
name = "/aws/lambda/${var.ProjectId}-lambda"
27+
retention_in_days = var.LogRetentionDays
28+
}

terraform/envs/prod/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
variable "LogRetentionDays" {
2+
type = number
3+
default = 90
4+
}
5+
6+
variable "ProjectId" {
7+
type = string
8+
default = "infra-core-api"
9+
}
10+

terraform/envs/qa/main.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5.92"
6+
}
7+
}
8+
9+
required_version = ">= 1.2"
10+
}
11+
12+
provider "aws" {
13+
region = "us-east-1"
14+
default_tags {
15+
tags = {
16+
project = var.ProjectId
17+
}
18+
}
19+
}
20+
21+
import {
22+
to = aws_cloudwatch_log_group.main_app_logs
23+
id = "/aws/lambda/${var.ProjectId}-lambda"
24+
}
25+
resource "aws_cloudwatch_log_group" "main_app_logs" {
26+
name = "/aws/lambda/${var.ProjectId}-lambda"
27+
retention_in_days = var.LogRetentionDays
28+
}

terraform/envs/qa/variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
variable "LogRetentionDays" {
2+
type = number
3+
default = 7
4+
}
5+
6+
variable "ProjectId" {
7+
type = string
8+
default = "infra-core-api"
9+
}

0 commit comments

Comments
 (0)