Using Terraform Modules in Environments

Users can attach Terraform Modules to Environments in Bunnyshell by configuring input variables and mapping outputs to variables.

circle-check

1. Let's create another Environment with the same repository, demo-books-terraformarrow-up-right.

2. Next, let's add the Terraform Module we created earlier.

3. You will be able to select the previously added one, and choose:

  • Whether it will update itself every time new commits that change the module are added in Git;

  • Whether the module will also be automatically attached to any Ephemeral environments.

In this case, let's switch both options to ON.

4. Next, if any variables need to be defined at the Environment level, you are prompted to do so. When we added the Terraform Module, we enforced the bucket name from there, so anyone using it cannot override its value.

5. Next, you are able to define mappings. Essentially, you can take Terraform Outputs and dump them into Environment Variables or Component Variables, so other applications or services will be able to use their value.

circle-exclamation

You should map the outputs of the module as follows: - s3_bucket_name will be "exported" to Environment components -> backend -> AWS_S3_BUCKET_NAME - s3_bucket_region will be "exported" to Environment components -> backend -> AWS_S3_BUCKET_REGION

6. The Terraform plan is tested once more, with all the new configurations you provided, and the plan is also outputted.

7. Lastly, click Attach Terraform Module. You will be able to see it in the Terraform Modules listing of the Environment.

8. Now we also need to grant access to the backend application for the bucket, so it can upload images there.

For this, you need to replace the AWS_S3_ACCESS_KEY_ID and AWS_S3_ACCESS_KEY_SECRET in the Application variables of the backend app.

Debugging

You will be able to debug Terraform apply in the same Event logs of the Environment.

Last updated

Was this helpful?