Skip to content
Simon Caplette edited this page Apr 13, 2018 · 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 interacting with the cloud. Here his a one-liner template for instance:

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

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

Parameters can be either:

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

Here would be an example of deploying an infrastructure using awless templates:

Under the hood, an awless template is parsed with a parsing expression grammar in order to build an abstract syntax tree.

The template AST is then traversed, verified and dry-run(ed) against a given cloud driver (i.e: AWS aws-sdk-go) so that scripted actions against the cloud can be performed.

The awless CLI provides 2 main ways of executing templates:

  1. awless run which takes as an argument the path of a local or remote template file.

     $ awless run ~/templates/create_infra.awless
     $ awless run https://raw.githubusercontent.com/wallix/awless-templates/...
    
  2. template one-liners through built-in CLI action verbs

     $ 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:

stop instance id=@my-instance
subnet = create subnet cidr={subnet.cidr} vpc={subnet.vpc} 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 using the $ syntax

Holes

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

Aliases

When using the @ syntax in templates you reference a resource by its name instead of a cryptic id. Behind the scene, awless will resolve the id and use during execution.

Lists

Lists allow to feed list values to param. List are represented through [...]. This can be a list of references, holes or aliases.

create instance securitygroup=[$secgroup, @mysecgroup, {secgroup.from.external}] image=...

One-liner template command

Using the awless CLI help you can get all the information on the execution of the builtin one-liners:

$ awless
$ awless -h                  # show all known template commands
$ awless create              # show create help and on which resources it applies
$ awless stop                # show stop help and on which resources it applies
$ awless start instance -h   # show params info for this command
Clone this wiki locally