-
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
-
CLI 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:
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
The file contains variables to store newly created resource to be referenced later. It also has holes to be filled in later on by your defaults or CLI prompting
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)