Skip to content

yukihiko-shinoda/docker-compose-terraform

Repository files navigation

Docker Compose Terraform

The develop environment for Terraform projects.

Advantage

Out of the box📦 for any Terraform project:

  • Supports any Terraform version🙆 by tfenv
  • Auto format on save by HashiCorp Terraform Extension
  • Implements efficient commands🚀 for:
    • Format and test code quickly
      • terraform fmt -recursive
      • terraform validate
      • TFLint (if .tflint.hcl exists in Terraform project)
    • Plan all environment (supports running as parallel)
    • Render differences report of all plans
  • Customizable by jinja in YAML configuration file🔧
    • The directory to run terraform command
    • The command to select environment and prepare to plan.
    • The command to plan

Out of the box for any Terraform project

Quickstart

Requirement

Setup

1. Clone or download this project

git clone https://github.com/yukihiko-shinoda/docker-compose-terraform.git

2. Clone or download your Terraform project into root directory of this project

cd docker-compose-terraform
git clone <repository of your Terraform project>

3. Open Visual Studio Code on root directory

code .

4. Reopen in Container

Run the Remote-Containers: Reopen in Container command from the Command Palette (F1) or quick actions Status bar item.

5. Create config.yml to customize for your Terraform project

Copy config.yml.dist to config.yml, then edit it.

Details is explained by comments in its file.

6. Create report.md.jinja to render report of plans

Copy report.md.jinja.dist to report.md.jinja, then edit it.

The differences of all plan is rendered at point of corresponding environment name which is defined into config.yml.

EX:

projects:
  terraform-project-a:
# ------------------------------
    environments:
      dev: {}
      prod: {}
## dev

```console
{{ dev }}
```

## prod

```console
{{ prod }}
```

Usage

Format and test code quickly

fmt-test <project directory name>

EX:

fmt-test terraform-project-a

Plan all environment

Note: If you are using Terraform Enterprise, it requires to login to Terraform Enterprise before run following commands.

pytest tests --prj <project name defined in YAML>

EX:

pytest tests --prj terraform-project-a

As parallel

pytest tests --prj <project name defined in YAML> -n <number of processes>

EX:

pytest tests --prj terraform-project-a -n 3

Render report differences of all plans

python report.py

Then, report will be render to ./report.md .