Skip to content
Simon Caplette edited this page Feb 14, 2017 · 26 revisions

Templates

awless writing operations to the cloud infrastructure relies on the concepts of templates. A template in awless describes a list of actions updating the cloud. For instance, this would be a one-liner template:

create instance subnet=subnet-356d517f image=ami-70edb016 type=t2.micro

This one line template contains an action create on an entity followed by a list of params.

Parameters can be either:

  • given directly through the command line as key=value arguments
  • filled transparently filled by your local config defaults (i.e: instance ami, instance type, etc...)
  • completed through dynamic CLI prompting for missing required arguments

Under the hood, an awless template is parsed with a parsing expression grammar in order to build an abstract syntax tree. Then the AST is traversed by a given cloud driver (i.e: AWS aws-sdk-go) to perform the action against the cloud

The awless CLI provides 2 ways of executing templates:

  1. awless run that takes as an argument the filepath of a template local file.

     $ awless run ~/templates/create_infra.txt
    
  2. template one-liner

     $ awless create instance name=my-instance
     $ awless delete subnet ...
     $ awless stop instance id=i-6fg5h4j
    

Template file and syntax

You can also load more complex templates combining multiple commands in a template file through the awless run command. For example, the following template file:

subnet = create subnet cidr={subnet.cidr} vpc={subnet.vpc}
create tags resource=$subnet Name={subnet.name}
update subnet id=$subnet public-vms=true
rtable = create routetable vpc={subnet.vpc}
attach routetable id=$rtable subnet=$subnet
route = create route cidr=0.0.0.0/0 gateway={vpc.gateway} table=$rtable

References

Templates have variable assignment syntax to store mainly references to newly created resource that can be referenced later.

Holes

Templates a simple {} syntax for value that will be filled in later by your predefined defaults or through CLI prompting.

One-liner template command

Here are some more examples of awless builtin template one-liners:

  • awless create allow to create a cloud resource (ex: instance, vpc, user, ssh keypair, routetable...)
  • awless delete allow to delete a cloud resource
  • awless update allow to update a cloud resource property after its creation
  • awless attach allow to attach a cloud resource (for example, a volume) to another (for example an instance)
  • awless detach allow to attach two attached cloud resources.
  • awless start allow to start a cloud resource (for example, an instance)
  • awless stop allow to stop a cloud resource (for example, an instance)
Clone this wiki locally