Skip to content
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

Transition Dev environment Infrastructure to ECS #222

Merged
merged 72 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
f960900
adding terraform for ecs infrastrcuture that includes vpc and rds
shanice-skylight Dec 12, 2024
06206c8
added rds configurations
shanice-skylight Dec 13, 2024
3b9caa5
added github actions, trivy, tflint, and alb certificate
shanice-skylight Dec 17, 2024
1967b76
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Dec 17, 2024
ef3b2ab
added pull request trigger for testing purposes
shanice-skylight Dec 17, 2024
1123a7d
modified name of region variable
shanice-skylight Dec 17, 2024
aed86db
fixed linting and made region a secret
shanice-skylight Dec 17, 2024
2f6c23f
fixed configure aws secret
shanice-skylight Dec 17, 2024
12279e5
added dev as a workspace
shanice-skylight Dec 17, 2024
ba065b5
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Dec 17, 2024
6b84a31
removed pull request trigger and added workspace as string instead of…
shanice-skylight Dec 17, 2024
dfb885e
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Dec 17, 2024
fc1c82b
changed trigger to on push for testing
shanice-skylight Dec 17, 2024
a186e53
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Dec 17, 2024
7d6e0ef
added workspace value to env
shanice-skylight Dec 17, 2024
4e37bda
added workspace value to env
shanice-skylight Dec 17, 2024
f7a5632
removed cached path to rds submodule in .terraform directory
shanice-skylight Dec 17, 2024
a918ef1
added output for plan and removed env terraform_action
shanice-skylight Dec 18, 2024
2610129
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Dec 18, 2024
2eb2fc1
added -chdir to terraform plan command
shanice-skylight Dec 18, 2024
de2771c
modified chdir path
shanice-skylight Dec 18, 2024
48d4b48
fixed quotes in terraform command and removed extra space and backslash
shanice-skylight Dec 18, 2024
6150d59
modified chdir path
shanice-skylight Dec 18, 2024
a916196
modified working directory and removed -chidir
shanice-skylight Dec 18, 2024
2caa954
removed echo since dev.tfvars is already in the repo
shanice-skylight Dec 18, 2024
fe3738a
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Dec 18, 2024
8b36321
updated the aws role to match qc role name
shanice-skylight Dec 18, 2024
dfd2645
removed session name attribute
shanice-skylight Dec 18, 2024
a14f7d4
removed tls key and cert for testing
shanice-skylight Jan 2, 2025
b21cd23
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 2, 2025
2a4d01d
modified .terraform dir path
shanice-skylight Jan 3, 2025
6806b13
modified gitignore and updated hashicorp/setup-terraform to latest ve…
shanice-skylight Jan 3, 2025
ce19bf8
deleted .terraform.lock.hcl
shanice-skylight Jan 3, 2025
df43e63
Clean Terraform Cache
shanice-skylight Jan 3, 2025
db335a5
added references to custom certificate and key for alb
shanice-skylight Jan 3, 2025
a515da2
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 3, 2025
cefb3e9
removed provider attribute in cert resource and fixed lint
shanice-skylight Jan 3, 2025
838302d
testing possible fix for alb invalid count argument error
shanice-skylight Jan 3, 2025
a9c7ec9
updated target to include resource type and name
shanice-skylight Jan 3, 2025
3d520ac
added auto-approve to terraform apply command
shanice-skylight Jan 3, 2025
fa8296c
added dependency on cert in ecs module
shanice-skylight Jan 3, 2025
056500c
modified target apply command
shanice-skylight Jan 3, 2025
7e5b21c
removed dependency from ecs
shanice-skylight Jan 3, 2025
1aa9592
modified action trigger
shanice-skylight Jan 3, 2025
5231cbc
modified region for credentails
shanice-skylight Jan 3, 2025
b8b71f8
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 3, 2025
a94917b
update default values and terraform init
shanice-skylight Jan 3, 2025
ebce6e2
the tfplan is uploaded to artifacts and apply uses it to deploy resou…
shanice-skylight Jan 3, 2025
3f74a8a
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 3, 2025
b404284
modified path to artifact
shanice-skylight Jan 3, 2025
6ef6d28
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 3, 2025
734163e
added path for tfplan and updated module to latest
shanice-skylight Jan 3, 2025
174aefe
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 3, 2025
401d4c2
added Terraform apply as on push to branch
shanice-skylight Jan 3, 2025
a96293d
added working director to terraform apply
shanice-skylight Jan 3, 2025
7a0682a
removed extra quote
shanice-skylight Jan 3, 2025
8f252ba
combine terraform plan and apply into one workflow
shanice-skylight Jan 3, 2025
c6bc022
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 3, 2025
4734f84
removed var from apply command
shanice-skylight Jan 3, 2025
59bcad2
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 3, 2025
4c3798b
added debug code and removed -auto-approve
shanice-skylight Jan 3, 2025
4f354c3
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 3, 2025
90780f1
removed workflows used for testing and modified workflows triggers to…
shanice-skylight Jan 4, 2025
d9fbb5b
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] Jan 4, 2025
07ac598
made code review changes
shanice-skylight Jan 6, 2025
e58c03f
modified ad hoc plan name
shanice-skylight Jan 6, 2025
1563ec4
added replace to force new image and change order of commands for ter…
shanice-skylight Jan 6, 2025
eefdb83
Revert "modified ad hoc plan name"
shanice-skylight Jan 6, 2025
932e68f
removed .terraform directories, updated workflow to remove pr trigger…
shanice-skylight Jan 6, 2025
7e23a43
variables OWNER and PROJECT were not used so I removed them
shanice-skylight Jan 6, 2025
c13f0b1
variables OWNER and PROJECT were not used so I removed them from ad h…
shanice-skylight Jan 6, 2025
afbce17
Merge branch 'main' into shanice/transition_ecs_infra
shanice-skylight Jan 7, 2025
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
93 changes: 93 additions & 0 deletions .github/workflows/ecs_terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Terraform Plan & Terraform Apply
run-name: Terraform plan & apply ${{ inputs.workspace }} by @${{ github.actor }}

on:
pull_request:
branches:
- "**"
shanice-skylight marked this conversation as resolved.
Show resolved Hide resolved
merge_group:
types:
- checks_requested
push:
branches:
- main
workflow_dispatch:
inputs:
workspace:
description: "The workspace to terraform against"
required: true
type: string
default: "dev"

concurrency:
group: ${{ github.event.inputs.workspace }}-terraform
cancel-in-progress: false

permissions:
id-token: write
contents: read

env:
workspace: dev

jobs:
terraform:
name: Run Terraform
runs-on: ubuntu-latest
defaults:
run:
shell: bash
# this may need to be updated if you change the directory you are working with
# ./terraform/implementation/dev || ./terraform/implementation/prod for example
# this practice is recommended to keep the terraform code organized while reducing the risk of conflicts
working-directory: ./terraform/implementation/ecs
steps:
- name: Check Out Changes
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: "1.9.8"

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Terraform
env:
BUCKET: ${{ secrets.TFSTATE_BUCKET }}
DYNAMODB_TABLE: ${{ secrets.TFSTATE_DYNAMODB_TABLE }}
OWNER: ${{ vars.OWNER }}
PROJECT: ${{ vars.PROJECT }}
shanice-skylight marked this conversation as resolved.
Show resolved Hide resolved
REGION: ${{ vars.region }}
WORKSPACE: ${{ env.workspace }}
UMLS_API_KEY: ${{ secrets.UMLS_API_KEY }}
ERSD_API_KEY: ${{ secrets.ERSD_API_KEY}}
TLS_CERT: ${{ secrets.TLS_CERT}}
TLS_KEY: ${{ secrets.TLS_KEY}}
shell: bash
run: |
rm -rf .terraform .terraform.lock.hcl
terraform init \
-var-file="$WORKSPACE.tfvars" \
-backend-config "bucket=$BUCKET" \
-backend-config "dynamodb_table=$DYNAMODB_TABLE" \
-backend-config "region=$REGION" \
|| (echo "terraform init failed, exiting..." && exit 1)
terraform workspace select "$WORKSPACE"
terraform apply -auto-approve -target=aws_acm_certificate.cloudflare_cert \
-var-file="$WORKSPACE.tfvars" \
-var "umls_api_key=${UMLS_API_KEY}" \
-var "ersd_api_key=${ERSD_API_KEY}" \
-var "qc_tls_key=${TLS_KEY}" \
-var "qc_tls_cert=${TLS_CERT}"
terraform plan -out=tfplan \
-var-file="$WORKSPACE.tfvars" \
-var "umls_api_key=${UMLS_API_KEY}" \
-var "ersd_api_key=${ERSD_API_KEY}" \
-var "qc_tls_key=${TLS_KEY}" \
-var "qc_tls_cert=${TLS_CERT}"
terraform apply tfplan
84 changes: 84 additions & 0 deletions .github/workflows/terraform_plan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Ad-hoc Terraform Plan
run-name: Terraform plan ${{ inputs.workspace }} by @${{ github.actor }}

on:
workflow_dispatch:
inputs:
workspace:
description: "The workspace to terraform against"
required: true
type: string
default: "dev"

concurrency:
group: ${{ github.event.inputs.workspace }}-terraform
cancel-in-progress: false

permissions:
id-token: write
contents: read

env:
workspace: dev

jobs:
terraform:
name: Run Terraform
runs-on: ubuntu-latest
defaults:
run:
shell: bash
# this may need to be updated if you change the directory you are working with
# ./terraform/implementation/dev || ./terraform/implementation/prod for example
# this practice is recommended to keep the terraform code organized while reducing the risk of conflicts
working-directory: ./terraform/implementation/ecs
steps:
- name: Check Out Changes
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/[email protected]
with:
terraform_version: "1.9.8"

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Terraform
env:
# ACTION: ${{ env.terraform_action }}
BUCKET: ${{ secrets.TFSTATE_BUCKET }}
DYNAMODB_TABLE: ${{ secrets.TFSTATE_DYNAMODB_TABLE }}
OWNER: ${{ vars.OWNER }}
PROJECT: ${{ vars.PROJECT }}
REGION: ${{ vars.region }}
WORKSPACE: ${{ env.workspace }}
UMLS_API_KEY: ${{ secrets.UMLS_API_KEY }}
ERSD_API_KEY: ${{ secrets.ERSD_API_KEY}}
TLS_CERT: ${{ secrets.TLS_CERT}}
TLS_KEY: ${{ secrets.TLS_KEY}}
shell: bash
run: |
rm -rf .terraform .terraform.lock.hcl
terraform init \
-var-file="$WORKSPACE.tfvars" \
-backend-config "bucket=$BUCKET" \
-backend-config "dynamodb_table=$DYNAMODB_TABLE" \
-backend-config "region=$REGION" \
|| (echo "terraform init failed, exiting..." && exit 1)
terraform workspace select "$WORKSPACE"
terraform apply -auto-approve -target=aws_acm_certificate.cloudflare_cert \
-var-file="$WORKSPACE.tfvars" \
-var "umls_api_key=${UMLS_API_KEY}" \
-var "ersd_api_key=${ERSD_API_KEY}" \
-var "qc_tls_key=${TLS_KEY}" \
-var "qc_tls_cert=${TLS_CERT}"
terraform plan -out=tfplan \
-var-file="$WORKSPACE.tfvars" \
-var "umls_api_key=${UMLS_API_KEY}" \
-var "ersd_api_key=${ERSD_API_KEY}" \
-var "qc_tls_key=${TLS_KEY}" \
-var "qc_tls_cert=${TLS_CERT}"
55 changes: 55 additions & 0 deletions .github/workflows/tflint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Terraform Linting
on:
pull_request:
branches:
- "**"
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tflint:
runs-on: ubuntu-latest

strategy:
matrix:
dirs:
[
terraform/modules/oidc,
terraform/modules/tfstate,
terraform/implementation/setup,
terraform/implementation/ecs,
]

steps:
- uses: actions/checkout@v4
name: Checkout source code

- uses: actions/cache@v4
name: Cache plugin dir
with:
path: ~/.tflint.d/plugins
key: ${{ matrix.dirs }}-tflint-${{ hashFiles('.tflint.hcl') }}

- uses: terraform-linters/setup-tflint@v4
name: Setup TFLint
with:
tflint_version: v0.52.0

- name: Show version
run: tflint --version

- name: Init TFLint
run: tflint --init
# If rate limiting becomes an issue, setup a GitHub token and enable it as an environment variable
# env:
# https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting
# GITHUB_TOKEN: ${{ github.token }}

- name: Run TFLint
working-directory: ${{ github.workspace }}/${{matrix.dirs}}
run: tflint -f compact
33 changes: 33 additions & 0 deletions .github/workflows/trivy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Trivy Security Scan

on:
pull_request:
branches:
- "**"
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
trivy:
name: trivy
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
scan-type: "fs"
scan-ref: "terraform/modules/"
scanners: "vuln,secret,config"
ignore-unfixed: false
exit-code: "1"
format: "table"
severity: "CRITICAL,HIGH"
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ build/

.env
.local.env

tmp_remote_image_*

# Local .terraform directories
**/.terraform/*
.terraform/modules/ecs
terraform/implementation/ecs/.terraform/*
1 change: 1 addition & 0 deletions terraform/.terraform/environment
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev
shanice-skylight marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions terraform/implementation/ecs/.terraform/environment
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"ecs","Source":"registry.terraform.io/CDCgov/dibbs-ecr-viewer/aws","Version":"0.3.0","Dir":".terraform/modules/ecs"},{"Key":"rds","Source":"registry.terraform.io/terraform-aws-modules/rds/aws","Version":"6.10.0","Dir":".terraform/modules/rds"},{"Key":"rds.db_instance","Source":"./modules/db_instance","Dir":".terraform/modules/rds/modules/db_instance"},{"Key":"rds.db_instance_role_association","Source":"./modules/db_instance_role_association","Dir":".terraform/modules/rds/modules/db_instance_role_association"},{"Key":"rds.db_option_group","Source":"./modules/db_option_group","Dir":".terraform/modules/rds/modules/db_option_group"},{"Key":"rds.db_parameter_group","Source":"./modules/db_parameter_group","Dir":".terraform/modules/rds/modules/db_parameter_group"},{"Key":"rds.db_subnet_group","Source":"./modules/db_subnet_group","Dir":".terraform/modules/rds/modules/db_subnet_group"},{"Key":"vpc","Source":"registry.terraform.io/terraform-aws-modules/vpc/aws","Version":"5.16.0","Dir":".terraform/modules/vpc"}]}
shanice-skylight marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions terraform/implementation/ecs/.terraform/modules/vpc
Submodule vpc added at 9ffd9c
Loading
Loading