Package: tropoform
TropoformTropoform is a tool that provides aterraformlike interface for deploying
standalone AWS Cloud Formation stacks or stacks created
bytroposphere. Tropoform provides plan, apply, list,
output & destroy operations on cloudformation stacks.RequirementsPython3.6+InstallationTo install the latest version of tropoformpip install tropoform --user --upgradeFor development projects, it is advised to install in a pythonvirtual environmentOr you can install from sourcehttps://github.com/cloudshiftstrategies/tropoformUsageusetropoform -hfor help$ tropform -h
usage: tropoform [-h] [-v]
                    {apply,plan,destroy,list,output,parameters,reason} ...

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         get DEBUG logging

operation:
  {apply,plan,destroy,list,output,parameters,reason}
    apply               create or update stack
    plan                view change plan
    destroy             remove stack
    list                list stacks
    output              view stack outputs
    parameters          list parameters used in a stack
    reason              list reasons for failed stacksee detailed usage help for an operationtropoform apply -husage: tropoform.py apply [-h] (-m MODULE_NAME | -t TEMPLATE_FILE)
                          [-p PARAMETER_FILES] [-c CAPABILITIES] [-r REGION]
                          [--auto_approve]
                          stack_name

positional arguments:
  stack_name            The name of the cloud formation stack on which to
                        perform operation. If a module exists in the current
                        working directory that matches the stack_name and has
                        a get_template() method, module_name is not required

optional arguments:
  -h, --help            show this help message and exit
  -m MODULE_NAME, --module_name MODULE_NAME
                        The name of the python troposphere module that will
                        create the template. Module must have a get_template()
                        method that returns a valid troposphere.Template
                        object
  -t TEMPLATE_FILE, --template_file TEMPLATE_FILE
                        The path to a cloud formation template file.
  -p PARAMETER_FILES, --parameter_files PARAMETER_FILES
                        Comma separated yaml parameter files that will be
                        passed to cloud formation as parameters
  -c CAPABILITIES, --capabilities CAPABILITIES
                        Comma separated list of AWS capabilities. default:
                        CAPABILITY_NAMED_IAM
  -r REGION, --region REGION
                        The name of the AWS region to perform operations.
                        default is the env variable: AWS_DEFAULT_REGION
  --auto_approve        If set, user will not be prompted to approve changes.
                        default=FalseUsage ExampleCreate a cloud formation template using yaml or json formationORCreate a python module (script) usingtropospherethat has at least one method called get_template() which returns the un-rendered troposphere.
Template() object.In theexample.pyscript below, we create an IAM user inside the function get_template() and return
the completed template objectexample.pyfromtroposphereimportTemplatefromtroposphereimportiamdefget_template():template=Template()template.add_resource(iam.User("testIamUser",UserName="tropoform_test_user"))returntemplateConfigure your AWS credentialshttps://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-credentials.htmlso that you can make API / CLI calls.Test your credentials with an awscli command likeaws s3 lsor you can test the boto3 python apipython3 -c "import boto3; client = boto3.client('s3'); print(client.list_buckets())"Run atropoform planon the stack and see that one IAM User resource will be createdUsing a cloud formation template$ tropoform plan myStack -t example_cfn_template.yaml
STACK: myStack is not yet deployed
STACK: myStack creates 1
# ) action   logical_id                resource_type
 1) Create   testIamUser               AWS::IAM::UserOr using a troposphere module$ tropoform plan myStack -m example.py
STACK: myStack is not yet deployed
STACK: myStack creates 1
# ) action   logical_id                resource_type
 1) Create   testIamUser               AWS::IAM::UserUsetropofrom apply(create) the stackUsing a cloud formation template$ tropoform apply myStack -t example_template.json
STACK: myStack, Current Status: None
CREATING Stack: myStack with 1 resources
Are you sure? [yes|no] yes
STACK: myStack, Status: CREATE_IN_PROGRESS - 16:36:10
STACK: myStack, Status: CREATE_IN_PROGRESS - 16:36:25
STACK: myStack, Status: CREATE_COMPLETE - 16:36:41
STACK: myStack deployed 1 resources in 00:00:48
STACK OUTPUTS:Or using a troposphere module$ tropoform apply myStack -m example.py
STACK: myStack, Current Status: None
CREATING Stack: myStack with 1 resources
Are you sure? [yes|no] yes
STACK: myStack, Status: CREATE_IN_PROGRESS - 16:36:10
STACK: myStack, Status: CREATE_IN_PROGRESS - 16:36:25
STACK: myStack, Status: CREATE_COMPLETE - 16:36:41
STACK: myStack deployed 1 resources in 00:00:48
STACK OUTPUTS:Usetropoform listto see stacks that are applied. Notice it is in status CREATE_COMPLETE$ tropoform list
stack_name           stack_status         drift_status         stack_description
myStack              CREATE_COMPLETE      NOT_CHECKEDUpdate the example.template and add another resourceexample.pyfromtroposphereimportTemplatefromtroposphereimportiamdefget_template():template=Template()template.add_resource(iam.User("testIamUser",UserName="tropoform_test_user"))template.add_resource(iam.User("testIamUser2",UserName="tropoform_test_user2"))returntemplateand run a newtropoform plan. Notice that it will add one new resource.$ tropoform plan myStack -m example.py
STACK: myStack has 1 detected changes
# ) action   logical_id           resource_id               resource_type                  scope      Replace?
 1) Add      testIamUser2                                   AWS::IAM::User                 []tropoform applythe changes and then use atropoform listto verify$ tropoform apply myStack -m example.py
STACK: myStack, Current Status: CREATE_COMPLETE
UPDATING Stack: myStack
Are you sure? [yes|no] yes
STACK: myStack, Status: UPDATE_IN_PROGRESS - 16:42:38
STACK: myStack, Status: UPDATE_IN_PROGRESS - 16:42:54
STACK: myStack, Status: UPDATE_COMPLETE - 16:43:09
STACK: myStack updated 2 resources in 00:00:48
STACK OUTPUTS:

$ tropoform list
stack_name           stack_status         drift_status         stack_description
myStack              UPDATE_COMPLETE      NOT_CHECKEDdestroythe stack when you are done with it$ tropoform destroy myStack
DELETING STACK: myStack with 2 resources
Are you sure? [yes|no] yes
STACK: myStack, Status: UPDATE_COMPLETE - 16:44:37
STACK: myStack deleted in 00:00:15Additional featuresParameter filesOften cloudformation templates will require parameters so that they can be easily
reusable. You can create yaml based files with key: value pairs and add them as
arguments to thetropoform planandtropoform applyoperationsexample_parms1.yamlParm1:Parameter 1Parm2:"2"example_parms2.yamlParm3:Parameter 3Parm4:"4"Using the parameter files in an apply$ tropoform apply myStack -m example.py -p example_parms1.yaml,example_parms2.yamlCapabilitiesCloud formation stacks may require acknowledgement that it will create resources of
certain types. The most common is CAPABILITIES_NAMED_IAM which authorizes cloud formation
to create IAM resources. This is included by default in tropoform. But if your stack
requires additional capabilities, you can include them with the-cargument. See more
information about capabilities in this documentation:https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_CreateStack.htmlUsing additional capabilities in an apply$ tropoform apply myStack -m example.py -c CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPANDRegionsBy default, troposphere will read the environment variable AWS_DEFAULT_REGION to determine
where to manage stacks. But if you want to specify a different region for an operation
pass the '-r' or '--region' argumentSpecifying a region in a list command$ tropoform list -r us-east-2Stack Names and Module NameIf the name you want to specify for your cloudformation stack is in the current
working directory and has the same name as the troposphere script, then you can omit
the module_name parameterExample of creating a cloud formation stack called "example" when "example.py" troposphere
script exists in the current working directory$ tropoform apply exampleExample of creating a cloud formation stack called "myStack" when "example.py" troposphere
script exists in some filesystem location$ tropoform apply myStack -m ../scripts/example.pyAuto ApproveSometimes when running tropoform in automated scripts, you dont want to be prompted to say
yes to confirm theapplyordestroyoperationExample--auto_approve$ tropoform apply example --auto_approveReason for failuresIf your cloudformation stack fails to apply for some reason, the cloudformation event(s)
that caused the will be printed.In the example below, we tried to attach a ManagedIamPolicy that is intentionally misspelled$ tropoform apply myStack -m example.py
STACK: myStack, Current Status: None
CREATING Stack: myStack with 1 resources
Are you sure? [yes|no] yes
STACK: myStack, Status: CREATE_IN_PROGRESS - 17:32:22
STACK: myStack, Status: CREATE_IN_PROGRESS - 17:32:38
STACK: myStack, Status: ROLLBACK_COMPLETE - 17:32:54
STACK: myStack not deployed and is in status ROLLBACK_COMPLETE
STACK myStack create/update FAILED due to the following stack events:
UTC time   ResourceStatus  ResourceType                        LogicalResourceId              ResourceStatusReason
22:32:47   CREATE_FAILED   AWS::IAM::User                      testIamUser                    Policy arn:aws:iam::aws:policy/AdministratorAcces does not exist or is not attachable.You can use thetropoform reasonoperation to look up the status of a failed stack$ tropoform reason myStack
STACK myStack create/update FAILED due to the following stack events:
UTC time   ResourceStatus  ResourceType                        LogicalResourceId              ResourceStatusReason
22:32:47   CREATE_FAILED   AWS::IAM::User                      testIamUser                    Policy arn:aws:iam::aws:policy/AdministratorAcces does not exist or is not attachable.ParametersIf your stack was deployed with parameters, you can check those paramaters with thetropoform parametersoperation$ tropoform parameters myStack
STACK: myStack Parameters: 
Parm1                = value1OutputsIf your stack specifies Output parameters, when the stack is done deploying, the outputs
will be printed.$ tropoform apply myStack -m example.py --auto_approve
STACK: myStack, Current Status: None
CREATING Stack: myStack with 1 resources
STACK: myStack, Status: CREATE_IN_PROGRESS - 17:40:44
STACK: myStack, Status: CREATE_IN_PROGRESS - 17:40:59
STACK: myStack, Status: CREATE_COMPLETE - 17:41:15
STACK: myStack deployed 1 resources in 00:00:48
STACK OUTPUTS:
userArn              = arn:aws:iam::357849880876:user/tropoform_test_userIf you want to access those outputs later, you can runtropoform output$ tropoform output myStack
STACK OUTPUTS:
userArn              = arn:aws:iam::357849880876:user/tropoform_test_userContributions welcome!Open issues and send pull requests via the github repohttps://github.com/cloudshiftstrategies/tropoform