-
Notifications
You must be signed in to change notification settings - Fork 264
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
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 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 ways of executing templates:
-
awless run
that takes as an argument the filepath of a template local file.$ awless run ~/templates/create_infra.awless
-
template one-liner
$ awless create instance name=my-instance $ awless delete subnet ... $ awless stop instance id=i-6fg5h4j
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}
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
Templates have variable assignment syntax to store mainly references to newly created resource that can be referenced later using the $ syntax
Templates has simple {} syntax for value that will be filled in later by your predefined defaults or through CLI prompting.
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.
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