Continuous Integration (CI)

Build and Package

Terraform is interpretive and doesn’t need to be compiled, so why have a build process?

Validation

While Terraform does not have a compiler, it does have the option to validate the syntax of a plan, so this is used as the CI process to “fail fast”, to find syntax errors before attempting to execute against an environment.

[terraform.ps1] ---------- start ----------
[terraform.ps1]   operation      : validate
[terraform.ps1]   desiredVersion : 

terraform validate   
Success! The configuration is valid.

Decouple for Source Control

The output of the CI process is a portable, re-usable, release package (release.ps1). This can be used to perform Terraform application from the users desktop against their Visual Studio Pro or Test subscription in azure, using the same mechanism the pipeline will use.

To further verify the release package, it is executed in PLAN mode, which ensures the plan can be executed and provides a what-if analysis.

[terraform.ps1] ---------- start ----------
[terraform.ps1]   operation      : plan
[terraform.ps1]   desiredVersion : 

terraform plan   
Running plan in the remote backend. Output will stream here. Pressing Ctrl-C
will stop streaming the logs, but will not stop the plan running remotely.

Preparing the remote plan...

To view this run in a browser, visit:
https://app.terraform.io/app/schsnz/doe-sandpit/runs/run-5fsY2cdKsqVfBVXX

Waiting for the plan to start...

Plan: 3 to add, 0 to change, 0 to destroy.