gruntwork-io / boilerplate

A tool for generating files and folders ("boilerplate") from a set of templates
https://www.gruntwork.io
183 stars 16 forks source link

Add support for a shell helper #25

Closed brikis98 closed 7 years ago

brikis98 commented 7 years ago

This PR adds support for a new helper to boilerplate: shell CMD. This helper executes the specified shell CMD, rendering in the template whatever that CMD returned to stdout.

We can use this functionality to automate a lot more stuff from usage-patterns. For example, we could create a simple shell script called ec2-keypair.sh which uses the AWS CLI to create an EC2 key pair of a given name if it doesn’t already exist. Now, in some file in a boilerplate template, such as vars.tf, we can call the script as follows:

variable "ssh_keypair" {
  default = "{{ shell "ec2-keypair.sh" .KeyPairName .PathToSaveKeyPairFile }}"
}

The first time you run boilerplate to generate this template, it'll create the EC2 key pair of the name specified by the boilerplate variable .KeyPairName and save the private key on your hard drive to the path specified by .PathToSaveKeyPairFile. Every time you run it after that, it'll realize the key pair already exists and simply return its name.

brikis98 commented 7 years ago

@josh-padnick I'm really excited to try this change out, so I'm going to merge it in. Feedback welcome!