Skip to content

app-sre/er-base-terraform

Repository files navigation

Overview

External resources base image with Terraform. This image is not intended to be directly used as a final module, it should be used as a base for defining final Terraform based modules.

Using common images on modules using the same provider saves a ton of bandwith by reeducing the number of required layers.

Notes for Final modules

  • The Terraform entrypoint must be set in the ./module path.
  • entrypoint.sh runs a generate-tf-config call to generate the terraform config required to run the module. This script call must be implemented in the final module. It should generate the backend configuration and the variables file to be used by the module.
  • er-aws-kms is a good example to get started.
  • external-resources-io has helper methods to generate the configuration files (>=0.4.0).

Hook scripts

There are a predefined set of hooks that can be leveraged by final modules to run processes outside of the terraform normal runs. Hook scripts must be set under the ./hooks directory. Hooks have visibility over the ENV variables of th4e module, so they can act differently depenending if it's a DRY_RUN or if the ACTION is set to "Apply" or "Destroy".

Hooks

  • pre_run: First hook to run.

  • pre_init: Runs before terraform init and after generate-tf-config.

  • post_init: Runs after terraform init.

  • pre_plan: Runs before terraform plan.

  • post_plan: Runs after a terraform plan. Normally used for validating the terraform plan.

  • pre_apply: Runs before terraform apply.

  • post_apply: Runs at the end. Normally used to verify the process have finished succesfully (if needed).

  • post_run: Last hook.

Useful Exposed variables for hooks.

  • ACTION = Apply | Destroy
  • DRY_RUN = True | False
  • PLAN_FILE_JSON = <path>. The plan file path (JSON format).
  • OUTPUTS_FILE = <path>. The outputs generated by terraform output -json. This file is generated after the terraform apply.

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •