This repository is a demo for AWS Staging environment. Supposed some situation like
- Need AWS Fargate Staging environment
- Each developer needs a unique Staging environment
- And each developer can deploy to their own Staging environment at their own timing
I solved this problem by using Terraform
, Terragrunt
and CI/CD.
Each Staging environment shares some resources.(VPC etc.)
I assume Terraform
, Terragrunt
is already installed, and created IAM user for it.
Fist of all, create backend.
% BUCKET_NAME=hoge_bucket
% aws s3 mb $BUCKET_NAME
Next, copy terraform/env.yaml.example
to terraform/env.yaml
.Then, set your bucket name and your application domain name.
It's time to deploy Terraform resources🚀.
Common resources mean literally common resources for all users, such as VPC, Subnet, Security Group, etc.
- move common resources Terraform directory
% cd terraform/common_resources
- apply
% terragrunt apply
This deploy creates just a plain box like under architecture.
Next, we put some application in this box.
User resources create resources for each user. There two way of deploying this resources. One is deploy by human, and the other is deploy by CI/CD. This section describes how to deploy by human.
- move user resources Terraform directory
% cd terraform/user_resources
- apply
% terragrunt apply
It's all done!
GitHub Actions is used for CI/CD. The staging deploy workflow triggered by workflow_dispatch. First time, Terraform create below resources.
- ECS
- Cluster
- Task Definition
- Service
- ALB
- listener
- target group
- Route53
- A record
Then http://<your github username>.<your domain>
id registered to Route53.
After that, update Task Definition, and restart Fargate.
And ALB Lister handle request to your own Fargate depend on host header (<your github username>.
) .
- This repository is just a demo, so it doesn't have any test.
- SSL certificate is not included in this repository.
- This repository doesn't have any resources for like
production
environment. (common_resources hasproduction
, but it's just a dummy.)