Terraform != CloudFormation
Terraform and CloudFormation are both infrastructure-as-code (IaC) tools. CloudFormation is developed by AWS and only manages AWS resources. Terraform is developed by HashiCorp and can manage resources across a wide range of cloud vendors. - https://www.toptal.com/terraform/terraform-vs-cloudformation
AWS CloudFormation terms
Template file
This is the definition file that describes the resources you want to create, it can be yml
or json
. I have created some example template files.
Stack
xxx
Changeset
xxx
Example: Lightsail Containers
A simple lightsail containers example created though cloud formation. The Container Service
and its Container Service Deployment
is created with the deployment template but the images running in the container are pre-built (I did it on my PC) and then pushed to Docker Hub.
- Clone the
app
andproxy
source code used in the post AWS Lightsail.
1 | git clone https://github.com/carlpaton/LightsailDemo |
- Create repositories at docker hub or what ever registry you are using. I used these names:
1 | carlpaton/containerservice43.proxy-image |
- Build, tag and push the images
1 | docker build -t app-image ./app/ |
- Clone the
template
source code
1 | cd.. |
- Ensure the template has the correct images under
ContainerServiceDeployment
->Containers
->Image
(note containers is an array)
1 | - ContainerName: proxy |
- Create the stack through the CLI, –profile carlos is local on my machine. This can also be done though the Console
1 | aws --profile carlos cloudformation create-stack --stack-name stackservice43 --template-body file://containerservice43.yml |
The user group will need the the following permissions added under IAM
1 | AWSCloudFormationFullAccess |
- This will create the Cloudformation stack
stackservice43
which will create the Lightsail container servicecontainerservice43
Boom - infrastructure as code :D