cfctl is a command line tool which helps to facilitate and manage AWS CloudFormation stack lifecycle.
It supports a simple and highly flexible repository structure for organising Cloudformation templates, parameters and environments.
The reason for creating this tool you can read in medium
- No tool lock-in. You can switch back to using awscli without much hassle and vice versa.
- Supports parameter files in YAML format and provides many useful functions for parameter file templating.
- Provide file ecryption facility for secrets used in parameter templates and automatically decrypt them during deployment.
- Configuration over convention. Provide high flexibility to suit different needs in directory structures for manage templates, paramters and environment specific files.
- Auto stack order sorting during deployment based on dependancy.
- Auto detect circular dependency amongst deploying stacks.
- Automatically uploading nested stacks during deployment and return those stack urls for referencing.
- Dynamically retrieving stack outputs for stacks that referencing them.
- Download the desired version base on your OS from the releases page
- Move it to the executables folder. For example for linux amd64:
chmod +x cfctl-linux-amd64 && sudo mv cfctl-linux-amd64 /usr/local/bin/cfctl
cfctl piggybacks your existing AWSCLI credential setting. If you don't have one, there are a few options:
- Use awscli environment variables
or
- Create two files:
~/.aws/credentials
and~/.aws/config
as per instruction.
As a minimum, your IAM user must have permission to create S3 bucket. In addition, you will need permissions for AWS resources that your Cloudformation requires.
BASH
source <(cfctl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first.
echo "source <(cfctl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.
You can also use a shorthand alias for cfctl that also works with completion:
alias cf=cfctl
complete -F __start_cfctl cf
ZSH
source <(cfctl completion zsh) # setup autocomplete in zsh into the current shell
echo "if [ $commands[cfctl] ]; then source <(cfctl completion zsh); fi" >> ~/.zshrc # add autocomplete permanently to your zsh shell
- Create a sample repository by running below command. The Command will create a default repository structure (which you can change it to your liking).
$ cfctl init
$
$ tree cfctl-sample
cfctl-sample
├── deploy
│ └── sample
│ ├── environments
│ │ └── default
│ │ └── var.yaml
│ ├── parameters
│ │ └── s3.yaml
│ └── stacks.yaml
└── templates
└── s3-encrypted.yaml
- Deploy example stack which creates a new s3 bucket.
$ cd cfctl-sample/deploy/sample
$ cfctl stack deploy
- Clean up
$ cfctl stack delete --all