Skip to main content

CLI Tool for deploying CloudFormation using a YAML based config file for stack and parameter settings.

Project description

CloudFormation Control

About The Project

Cloud Formation Control (cfnctl) is a commandline utility based of the AWS CLI Deploy features. On top of existing deployment capabilities it adds the ability to specify a configuration file to easily supply the following parameters to your CloudFormation deployment:

  • StackName
  • AwsRegion
  • StackParameters
  • StackTags

Supplying your CloudFormation template with a config containing the above parameters, and a set of commandline arguments or environment variables, it makes it easier to deploy CloudFormation templates both from your local development machine as well as a pipeline using the same pipelines and configurations.

Built With

This project is build using the following tools and frameworks:

Getting Started

In order to get started with developing and contributing to this project, follow the steps below.

Prerequisites

pipx (Optional)

This project is build and managed by poetry, the easiest way to install poetry in an isolated environment is using pipx.

python3 -m pip install --user pipx
python3 -m pipx ensurepath

Poetry

If you installed pipx, you can simply install poetry using the command below:

pipx install poetry

If you did not install pipx, see Poetry documentation for installation method for your system.

Installation

  1. Clone the repository
    git clone https://novonordiskit@dev.azure.com/novonordiskit/GITO-HS/_git/aws-cfnctl
    
  2. Change directory into the cloned repository
    cd aws-cfnctl
    
  3. Install dependencies into a virtual environment with poetry
    poetry install
    
  4. Activate virtual environment with poetry
    poetry shell
    

Usage

When installed somewhere on the system included in the systems PATH, the application can be called with cfnctl.
To see all available options for the CLI run:

cfnctl --help  

The cfnctl command has two primary subcommands:

  • cfnctl plan
  • cfnctl apply

cfnctl plan

cfnctl plan creates a new stack plan, or if the stack already exists, a change set plan for AWS CloudFormation. The resulting plan can then be used with cfnctl apply to execute the stack / change set and provision it in AWS.

If you wish to execute the plan immediately, set the --auto-apply commandline flag or use the CFNCTL_AUTO_APPLY = $TRUE.

The cfnctl plan command requires the following options:

  • --name "CloudFormation change set name."
  • --description "CloudFormation change set description."
  • --template "Relative or absolute filepath pointing to CloudFormation template file."
  • --config "Relative or absolute filepath pointing to CloudFormation template config file."
  • --output "Relative or absolute filepath for resulting change set file."

The following settings can be set optionally:

  • --export-stack "Export the Stack ID as an Azure DevOps pipeline variable with this name."
  • --export-changeset "Export the change set ID as an Azure DevOps pipeline variable with this name."
  • --export-outputs "Exports the stack output as Azure DevOps pipeline variables."
  • --auto-apply "If set to true, changeset will be created then executed"

cfnctl apply

cfnctl apply executes a stack plan, or if the stack already exists, executes a change set with AWS CloudFormation. The command requires a plan file created with the cfnctl plan command.

The cfnctl plan command requires the following options:

  • --name "CloudFormation change set name."
  • --description "CloudFormation change set description."
  • --template "Relative or absolute filepath pointing to CloudFormation template file."
  • --config "Relative or absolute filepath pointing to CloudFormation template config file."
  • --output "Relative or absolute filepath for incoming change set file."

The following settings can be set optionally:

  • --export-stack "Export the Stack ID as an Azure DevOps pipeline variable with this name."
  • --export-changeset "Export the change set ID as an Azure DevOps pipeline variable with this name."
  • --export-outputs "Exports the stack output as Azure DevOps pipeline variables."

Environment variables

Instead of using commandline parameters, it is possible to configure the cfnctl plan and cfnctl apply commands using environment variables.

PowerShell environment variables

Setting environment variables in PowerShell:

$env:CFNCTL_CHANGESET_NAME = "MyChangeSet"
$env:CFNCTL_CHANGESET_DESCRIPTION = "Change Set for my stack"
$env:CFNCTL_TEMPLATE_PATH = "my-cfn-template-file.yml"
$env:CFNCTL_STACK_CONFIG_PATH = "my-cfnctl-config-file.yml"
$env:CFNCTL_PLAN_OUTPUT_PATH = "cfn-output-file.yml"

# Optional
$env:CFNCTL_STACK_ID_EXPORT_VAR = "CFNCTL_STACK_ID"
$env:CFNCTL_CHANGESET_ID_EXPORT_VAR = "CFNCTL_CHANGESET_ID"
$env:CFNCTL_EXPORT_STACK_OUTPUT = $TRUE
$env:CFNCTL_AUTO_APPLY = $TRUE

You can validate the values is set correctly in your shell with:

Get-Item -Path Env:* | Where-Object {$_.name -like "CFNCTL_*"}

Bash environment variables

Setting Environment variables in Bash:

export CFNCTL_CHANGESET_NAME = "MyChangeSet"
export CFNCTL_CHANGESET_DESCRIPTION = "Change Set for my stack"
export CFNCTL_TEMPLATE_PATH = "my-cfn-template-file.yml"
export CFNCTL_STACK_CONFIG_PATH = "my-cfnctl-config-file.yml"
export CFNCTL_PLAN_OUTPUT_PATH = "cfn-output-file.yml"

# Optional
export CFNCTL_STACK_ID_EXPORT_VAR = "CFNCTL_STACK_ID"
export CFNCTL_CHANGESET_ID_EXPORT_VAR = "CFNCTL_CHANGESET_ID"
export CFNCTL_EXPORT_STACK_OUTPUT = true
export CFNCTL_AUTO_APPLY = true

You can validate the values is set correctly in your shell with:

env | grep 'CFNCTL_'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nn-cfnctl-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nn_cfnctl-0.1.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file nn-cfnctl-0.1.0.tar.gz.

File metadata

  • Download URL: nn-cfnctl-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.1 Windows/10

File hashes

Hashes for nn-cfnctl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6906f4fab09cbaa009995b7f02343eef4a303566e24a0c87c99335c07c4bbfb5
MD5 d8a3a411cfbde0c74772e92c3bd88088
BLAKE2b-256 892f884661ade3188674a847d7a571591d5c7727aa4796eb896d3f146a7e8e14

See more details on using hashes here.

File details

Details for the file nn_cfnctl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nn_cfnctl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.1 Windows/10

File hashes

Hashes for nn_cfnctl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 516c9e1f5ed067c28bb82dfac0ec9e3b657d7007881601d40cf683890a4c2892
MD5 1c0d334d285760089e582145589621dd
BLAKE2b-256 6a09d4e44f3ced8e73f662545b2936c3a65f4dedfb07aeb77266d4597591f78b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page