REciNK Component for Terraform
This is a REciNK component for Terraform.
Prerequisites
- Git >= v1.x
- Node.js >= v6.x
- NPM >= v3.x
- REciNK
Use nvm to install and manage different versions of Node.js; Ideally, use v8+ for faster performance
Installation
npm install -g recink-terraform
npm install -g recink-comment
Only necessary when GitHub commenting support needed
Note that the component is installed automatically when running
recink component add terraform
Configuration
.recink.yml
configuration:
$: preprocess: '$.terraform.vars.sample': 'eval' '$.comment.providers.github.0.token': 'eval' terraform: version: '0.11.0' # Terraform version that will be downloaded and installed locally (default "0.11.0") cache: true # Enable state/plans/backups caching if cache component enabled (default "true") resource: '.resource' # Resource relative path to the module root directory (default ".resource") binary: './bin/terraform' # Path to Terraform binary (default "./bin/terraform") init: true # Initialize Terraform setup (default "true") plan: true # Terraform validate .tf and make a provision plan (default "true") apply: false # Terraform provision infrastructure (default "false") destroy: false # Terraform destroy infrastructure provisioned in previous step (default "false") vars: # Terraform variables (@see https://www.terraform.io/docs/configuration/variables.html) sample: 'process.env.SAMPLE_VAR' var-files: # Terraform variables files (@see https://www.terraform.io/docs/configuration/variables.html#variable-files) - foo.tfvars - bar.tfvars comment: providers: # Supported providers: github github: - token: 'process.env.GITHUB_TOKEN'
.travis.yml
configuration:
script: 'recink run terraform -c comment' before_install: # other before_install scripts... - 'npm install -g recink-terraform' - 'npm install -g recink-comment'
Add the SAMPLE_VAR
and GITHUB_TOKEN
to .travis.yml
:
recink travis encrypt -x 'SAMPLE_VAR="sample value"' -x 'GITHUB_TOKEN=xxxxxxx'
If you are using Travis Pro read this guide to properly encrypt the environment variable
Per module settings
You can control the recink-terraform
behavior using per module
configuration feature as simple as shown in the example below:
example_prepare: root: './prepare' # Module root folder containing "main.tf" file inside example_module: root: './example' # Module root folder containing "main.tf" file inside terraform: run-after: # Other Terraform modules to run before dispatching "example_module" - example_prepare dependencies: # Global dependencies that should be considered when mathing changeset - '../../global-modules' vars: # Local module variables and global overwrites sample: 'overwrite default value!' new_one: 'define a new variable here.' var-files: # Terraform variables files (pay attention to the order) - foo.tfvars - bar.tfvars
terraform.dependencies
key is available as local module configuration option only and matches the changed files affecting the module that allows Terraform commands to be launched on global modules changes.
run-after
key is available as local module configuration option only and allows running desired Terraform modules after other modules dispatched (e.g. runexample_prepare
before startingexample_module
)
Usage
SAMPLE_VAR="sample value" GITHUB_TOKEN=xxxxxxx recink run terraform -c comment
Running example project
The following example will create 2 AWS VPCs with a peering connection between them:
AWS_DEFAULT_REGION='${region}' AWS_ACCESS_KEY_ID='${access-key-id}' AWS_SECRET_ACCESS_KEY='${secret-access-key}' recink run terraform example/
Note that
example/
directory is relative to therecink-terraform
module root.
How it works
REciNK and is listening for modules configured in .recink.yml
(@see example) having a ${module.root}/main.tf
file inside and triggering the configured operations (e.g. terraform init
, terraform plan
, terraform apply
and terraform destroy
).
Gotchas
- If
recink-comment
is neither installed or configured the reporter will fall back tologger.info()
and output the message in console