A CLI tool for scaffolding out new AWS ECS/Fargate applications based on Terraform templates and Fargate CLI
fargate-create ==============
A CLI tool for scaffolding out new AWS ECS/Fargate applications based on terraform-ecs-fargate and Fargate CLI.
Why?
The main design goal of this project is to create an easy and maintainable Fargate experience by separating infrastructure related concerns and application related concerns using tools that are optimized for each.
Installation
You can install the CLI with a curl utility script (macos/linux) or by downloading the binary from the releases page. Once installed you'll get the fargate-create command.
curl -s fargate-create.get.turnerlabs.io | sh
Pre-Release
If you'd like to install the latest prerelease, use this command:
curl -s fargate-create.get.turnerlabs.io | RELEASE=develop sh
Usage
Assuming you have a project with a [Dockerfile]()...
Specify your template's input parameters in terraform.tfvars (or terraform.json). The default web application template's input looks something like this. Note: any Terraform template can be used</code></pre>hcl
app/env to scaffold
app = "my-app" environment = "dev"
internal = "true" container_port = "8080" replicas = "1" health_check = "/health" region = "us-east-1" aws_profile = "default" vpc = "vpc-123" private_subnets = "subnet-123,subnet-456" public_subnets = "subnet-789,subnet-012" tags = { application = "my-app" environment = "dev" } <pre><code class="lang-"></code></pre>shell $ fargate-create scaffolding my-app dev Looking up AWS Account ID using profile: default downloading terraform template git@github.com:turnerlabs/terraform-ecs-fargate installing terraform template
done <pre><code class="lang-">Now you have all the files you need to spin up something in Fargate. Note that the Terraform files can be edited or customized. You can also use your own Terraform template using the
--template flag.
Infrastructure: provision using Terraform</code></pre>shell cd iac/base terraform init && terraform apply cd ../env/dev terraform init && terraform apply <pre><code class="lang-">Application: build/push using Docker and deploy using Fargate CLI</code></pre>shell docker-compose build login=$(aws ecr get-login --no-include-email) && eval "$login" docker-compose push fargate service deploy -f docker-compose.yml <pre><code class="lang-">To scaffold out additional environnments, simply change the
environment input parameter in terraform.tfvars and re-run</code></pre>shell $ fargate-create scaffolding my-app prod Looking up AWS Account ID using profile: default downloading terraform template git@github.com:turnerlabs/terraform-ecs-fargate installing terraform template iac/base already exists, ignoring
done <pre><code class="lang-">And then bring up the new environment (no need to apply base again since it's shared):</code></pre>shell cd ../prod terraform init && terraform apply <pre><code class="lang-">You'll end up with a directory structure that looks something like this:</code></pre> . |__iac | |__base | |__env | | |__dev | | |__prod <pre><code class="lang-">As changes are made to the various upstream templates over time, the
upgrade command can be used to keep installed versions up to date.</code></pre>bash fargate-create upgrade <pre><code class="lang-">### Stacks
The following stacks are popular configurations that can be used with
fargate-create
- Web Application (ALB - HTTP or HTTPS)
- Web Application (ALB - HTTPS/DNS)
- Web API Gateway
- Scheduled Task
- Background Worker (service)
- Network Application (NLB)
- Airflow
Help</code></pre>
Scaffold out new AWS ECS/Fargate applications based on Terraform templates and Fargate CLI
Usage: fargate-create [flags] fargate-create [command]
Examples:
Scaffold an environment using the latest default template
fargate-create
Do not prompt for options
fargate-create -y
Use a template stored in github
fargate-create -t git@github.com:turnerlabs/terraform-ecs-fargate?ref=v0.4.3
Scaffold out files for various build systems
fargate-create build circleciv2
keep your template up to date
fargate-create upgrade
Use a template stored in s3
AWSACCESSKEY=xyz AWSSECRETKEY=xyz AWS_REGION=us-east-1 \
fargate-create -t s3::https://s3.amazonaws.com/my-bucket/my-template
Use a template stored in your file system
fargate-create -t ~/my-template
Use a specific input file
fargate-create -f app.tfvars
Use a JSON input file
fargate-create -f app.json
Available Commands: build Scaffold out artifacts for various build systems help Help about any command upgrade Keep a terraform template up to date
Flags: -f, --file string file specifying Terraform input variables, in either HCL or JSON format (default "terraform.tfvars") -h, --help help for fargate-create -d, --target-dir string target directory where code is outputted (default "iac") -t, --template string URL of a compatible Terraform template (default "git@github.com:turnerlabs/terraform-ecs-fargate") -v, --verbose Verbose output --version version for fargate-create -y, --yes don't ask questions and use defaults <pre><code class="lang-">### CI/CD
Using this technique, it's easy to codegen CI/CD pipelines for many popular build tools. The
build command supports this.</code></pre>shell $ fargate-create build <provider> <pre><code class="lang-">The following providers are supported:
Extensibility
fargate-create can scaffold out any Terraform template (specified by --template) that meets the following requirements:
base and env/dev directory structure
a env/dev/main.tf with an s3 remote state backend
app and environment input variables
Your template can be downloaded from a variety of locations using a variety of protocols. The following are supported:
- Local files (
~/my-template)
Git ( git@github.com:my-org/my-template)
Amazon S3 ( s3::https://s3.amazonaws.com/my-bucket/my-template)
HTTP ( http://server/my-template/)
Optionally:
- add a
fargate-create.yml (example here) to your template to drive custom configuration, prompting for defaults, etc.
An example of an extended template:</code></pre>shell
$ fargate-create -f my-scheduledtask.tfvars -t git@github.com:turnerlabs/terraform-ecs-fargate-scheduled-task
``