-
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 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:
-
awless run
that takes as an argument the filepath of a template local file.$ awless run ~/templates/create_infra.txt
-
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-liner.
$ awless
$ awless -h # display all known template commands
$ awless create # display help for create and on which resources it applies
$ awless stop # display help for stop and on which resources it applies
$ awless start instance -h # display required and extra paramaters for this command