Attaching a Terraform Module to an Environment

To attach a Terraform Module to an environment, you only need to follow the steps below:

1. Go to the Environments page and click on the desired environment.

2. Click the button and select Terraform Module.

3. Select the Terraform Module you wish to attach to the environment.

If you haven't yet configured a module, you can do it now by clicking +Add new terraform module. Detailed instructions on how to do this are available here.

At this step, two additional features can be activated:

  • Auto-sync: turn on this option to automatically update the Terraform module every time a change is implemented, be it user configuration or Git commits.

  • Auto-attach to Ephemeral Environments: turn on this option to automatically attach the Terraform module to future ephemeral environments.

Click the Continue button.

4. Next, Bunnyshell will identify the Terraform variables that have been defined as configurable at the module level. These variables must be configured before the module is attached to the environment.

Click Continue.

Bunnyshell will then test the Terraform plan, previewing the changes that are to be implemented by the module.

5. In this next step, you can map Terraform output values to your environment components. This will help you connect your applications to your infrastructure.

Mapping Output Values

Output values can be mapped to variables from your components (apps, services etc) deployed in Kubernetes.

Mapping output values is not a mandatory step, but it can help you integrate Terraform with your services. It is not only useful for random output values, but also for those with static values, since you will no longer need to manage them both in config and in Terraform. You simply create a mapping and when a Terraform module is applied the new value is automatically injected in the app.

When selecting the Terraform output value, the drop-down menu will only display the output values you chose to include when you added the Terraform module.

In the Resource Type drop-down menu you can select the way in which Bunnyshell injects an output value. Choose one of the two options:

  • Environment. In this case, the value will be injected in all the services inside that environment. This feature comes in handy, for example, if your environment includes a number of services that use the same database and share one or more variables.

  • Environment Components. In this case, the value will be injected in just one service inside the environment. So, for example, if you want to name a variable password, but another service has a variable with the same name, this feature can help you avoid a situation where there are two variables named password inside the same environment.

The same output value can be mapped several times, with different names, in different variables from different services.

Mapped output values will override any variable with the same name on any level (project, environment or component).

Bunnyshell now checks if all the variables provided are in order and makes sure there no errors that could affect the module. This is the final and most important check performed. If everything is in order, the attachment will be functional.

Click Continue.

6. Bunnyshell now creates an execution plan, which lets you preview the changes the Terraform module plans to make to your infrastructure.

Should you wish to make further changes, click Back to return to the previous screen.

When everything is properly configured, click Attach Terraform Module.

Bunnyshell will automatically apply the attached Terraform module the next time the environment is deployed.

Alternatively, you can click on the module's Options button and select Apply. The module will be applied the next time the environment is deployed.

Last updated

Was this helpful?