IMPORTANT: This example only works with Terrascript releases up to 0.4.1.
This example is loosely based on an example from chapter 4 of the book Terraform: Up and Running by Yevgenij Brikman. The original code can be found in the book's Github repository.
This Terrascript adaption makes the following changes.
- The
webserver-cluster
Terraform module is implemented as a Python function which accepts the inputs as arguments and returns some resources as a tuple. - The
user_data
of thelaunch_configuration
is rendered with Python'sformat()
method instead of Terraform'stemplate_file
data source. For more advanced scenarios one could even use Jinja2. - All code is contained in a single file. General purpose modules/functions should probably go into a separate Python module.
- The backend database has been omitted.
The file main.tf.json was created by running main.py.