Terraform Modules in Bunnyshell

Terraform Modules in Bunnyshell are templates which can be used to create cloud-managed services (dependencies) for your application environments.

They provide governance, as you can only have the permission to modify certain input variables when attaching to an Environment ("lock" the instance size, for example, to limit costs).

Furthermore, they abstract all the configuration needed for a Terraform module and allow only relevant options to be configured.

👍

A Terraform Module can be attached to any number of Environments, and an Environment can have a Terraform Module attached more than once.

  1. To create Terraform Modules in Bunnyshell, click the Terraform Module icon on the left side of the interface.

  2. Click on Add Terraform module.

  3. Fill in the name and description.

  4. Select the repository, branch and path of the module
    In this case, we used the same repository demo-books, so you should select your forked repository.
    Then, select the branch terraform and set the Terraform directory path as /backend/_terraform.

📘

In general, you should use a permanent branch when you define your final modules.

  1. The module will now be validated

  2. Needed variables will be detected. In our case, we only have the bucket name, which needs to be defined. Click Define value.

3582
  1. Fill in the necessary fields as indicated below.
  • Type: Fixed value (String, Number, Bool)
  • Value: books-{{ env.unique }}

📘

This way, a uniquely-named bucket will be created for each Environment.

3582
  1. Next, environment variables need to be added (env vars with which Terraform will run). These are not related to Bunnyshell Environments. Click Add variable, as indicated below.
3582
  1. It's time to add the values required for cloud access.
    The needed variables are stated in the Terraform AWS Module Documentation.

    AWS_ACCESS_KEY_ID → replace-access-key
    AWS_SECRET_ACCESS_KEY → replace-secret
    AWS_REGION → us-west-1
    

You can choose the access key to be a secret, allowing it to be obfuscated.

3582
  1. The plan will now be tested for the module with the provided values.
3582
  1. Finally, the output values are detected. They will be used after attaching the Module to an Environment.
    You can also choose to exclude irrelevant output values, in order not to pollute the variable namespace - not the case here.
3582
  1. Click Add Terraform Module. And that's it: you have a Module which you can use in your Environments.
3582

🚧

Note

It is important that you make sure the Git source of the Terraform Module is not deleted, as Bunnyshell fetches the code from there before applying it.

Bunnyshell has implemented GitOps for Terraform Modules, meaning the module gets updated if you update it in Git.

The changes might be cascaded all the way to your Environments, but they will only be automatically applied if the setting is ON.

👍

Note

All variables (Environment Variables and Input Variables) are stored encrypted. The secret property only determines if it obfuscated in the UI and in logs.


📘

See more

For more details on the Terraform Modules, see the dedicated Terraform Modules documentation page.