Skip to content

Create terraform setup #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/deploy-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jobs:
env:
HUSKY: "0"

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.12.2


- name: Set up Node
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -102,6 +108,11 @@ jobs:
node-version: 22.x
cache: "yarn"

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.12.2

- name: Restore Yarn Cache
uses: actions/cache@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"rvest.vs-code-prettier-eslint",
"eamodio.gitlens",
"ms-vscode.makefile-tools",
"amazonwebservices.aws-toolkit-vscode"
"amazonwebservices.aws-toolkit-vscode",
"hashicorp.terraform"
]
}
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,17 @@ postdeploy:

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

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

invalidate_cloudfront:
Expand All @@ -114,13 +119,19 @@ invalidate_cloudfront:
install:
yarn -D
pip install cfn-lint
terraform -chdir=terraform/envs/qa init
terraform -chdir=terraform/envs/prod init

test_live_integration: install
yarn test:live

test_unit: install
yarn lint
cfn-lint cloudformation/**/*
terraform -chdir=terraform/envs/qa fmt -check
terraform -chdir=terraform/envs/prod fmt -check
terraform -chdir=terraform/envs/qa validate
terraform -chdir=terraform/envs/prod validate
yarn prettier
yarn test:unit

Expand Down
2 changes: 2 additions & 0 deletions cloudformation/logs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Parameters:
Resources:
AppApiLambdaLogGroup:
Type: AWS::Logs::LogGroup
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
LogGroupName:
Fn::Sub: /aws/lambda/${LambdaFunctionName}
Expand Down
82 changes: 82 additions & 0 deletions terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# OSX leaves these everywhere on SMB shares
._*

# OSX trash
.DS_Store

# Python
*.pyc

# Emacs save files
*~
\#*\#
.\#*

# Vim-related files
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist

### https://raw.github.com/github/gitignore/90f149de451a5433aebd94d02d11b0e28843a1af/Terraform.gitignore

# Local .terraform directories
**/.terraform*

# .tfstate files
*.tfstate
*.tfstate.*

# Local tfvars terraform.tfvars
**/*.tfvars

# tf lock file
**/.terraform.lock.hcl

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json
.idea/
.vscode/
# Kitchen files
**/inspec.lock
**.gem
**/.kitchen
**/.kitchen.local.yml
**/Gemfile.lock
# Plan files
**/tmp_plan
**/.tmp
**/tmp

test/fixtures/shared/terraform.tfvars

test/integration/gcloud/config.sh
test/integration/tmp

credentials.json

helpers/foundation-deployer/foundation-deployer
helpers/foundation-deployer/.steps.json

# File to populate env vars used by Docker test runs
.envrc

# Handle files generated on sed command by old (2013-) MacOS versions
*.tf-e

# Go multi-module workspace sum
go.work.sum
28 changes: 28 additions & 0 deletions terraform/envs/prod/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.92"
}
}

required_version = ">= 1.2"
}

provider "aws" {
region = "us-east-1"
default_tags {
tags = {
project = var.ProjectId
}
}
}

import {
to = aws_cloudwatch_log_group.main_app_logs
id = "/aws/lambda/${var.ProjectId}-lambda"
}
resource "aws_cloudwatch_log_group" "main_app_logs" {
name = "/aws/lambda/${var.ProjectId}-lambda"
retention_in_days = var.LogRetentionDays
}
10 changes: 10 additions & 0 deletions terraform/envs/prod/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "LogRetentionDays" {
type = number
default = 90
}

variable "ProjectId" {
type = string
default = "infra-core-api"
}

28 changes: 28 additions & 0 deletions terraform/envs/qa/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.92"
}
}

required_version = ">= 1.2"
}

provider "aws" {
region = "us-east-1"
default_tags {
tags = {
project = var.ProjectId
}
}
}

import {
to = aws_cloudwatch_log_group.main_app_logs
id = "/aws/lambda/${var.ProjectId}-lambda"
}
resource "aws_cloudwatch_log_group" "main_app_logs" {
name = "/aws/lambda/${var.ProjectId}-lambda"
retention_in_days = var.LogRetentionDays
}
9 changes: 9 additions & 0 deletions terraform/envs/qa/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "LogRetentionDays" {
type = number
default = 7
}

variable "ProjectId" {
type = string
default = "infra-core-api"
}
Loading