Skip to content

Render Terraform's Expressions and Functions locally without any hassle.

License

Notifications You must be signed in to change notification settings

unfor19/tfcoding

Repository files navigation

tfcoding

Push latest version to DockerHub Dockerhub pulls

tfcoding

Render Terraform's Expressions and Functions locally without any hassle.

This application runs in the background and watches for changes in the file tfcoding.tf, once this file is modified its Local Values are automatically rendered to the terminal's output (stdout).

This is especially useful for learning about Expressions and Functions that you are not familiar with, while avoiding the whole shebang of terraform init, plan and apply. The goal here is to "compile Terraform" locally to speed up the development (and learning) process.

Requirements

  • Docker

  • (Optional) Docker Compose

  • Windows

    • Windows Git Bash

    • Chocolatey Windows Package Manager

      IMPORTANT: Open a PowerShell terminal as Administrator

      Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    • Install requirements

      IMPORTANT: Open a PowerShell terminal as Administrator

      choco install -y make
  • macOS:

    • Homebrew macOS Package Manager
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • Install requirements
      brew install make

Quick Start

  1. Clone this repo
    git clone https://github.com/unfor19/tfcoding.git
  2. From now on your working direcotry should be tfcoding
    cd tfcoding
    
  3. Render examples/basic/tfcoding.tf - Make changes in that file, like checking new Terraform Expressions
    make run
    
  4. Clean resources - Removes tfcoding container
    make clean

Getting Started

This project uses localstack, which means you can provision the AWS core resources, see examples/mock-aws/.

  1. Clone this repo

    git clone https://github.com/unfor19/tfcoding.git
  2. From now on your working direcotry should be tfcoding

    cd tfcoding
    
  3. Render examples/mock-aws/tfcoding.tf - Make changes in that file, like changing the CIDR of subnets

    make up-aws
    
  4. Execute terraform destroy on changing tfcoding.tf, add the Local Value terraform_destroy = true. For example:

    // After "destroying" the infra, comment out this variable to execute `terraform apply`
    locals {
      terraform_destroy = true
    }
  5. Clean resources - Removes tfcoding and localstack containers

    make clean-all

Help Menu

make help

With Docker:

docker run --rm -it unfor19/tfcoding --help
Usage: bash entrypoint.sh -r basic/exmaples --watching -o private_subnets

	--src_dir_relative_path  |  -r    [REQUIRED]  Relative path to the dir that contains tfcoding.tf
	--single_value_output    |  -o    [all]       Render a single local variable
	--src_dir_root           |  -s    [/src]      Source root dir in container
	--logging                |  -l    [true]      Show logging messages
	--debug                  |  -d    [false]     Print verbose output
	--watching               |  -w    [FLAG]      Auto-render tfcoding.tf on change
	--mock_aws               |  -aws  [FLAG]      Use this flag for communicating with Localstack

Authors

Created and maintained by Meir Gabay

License

This project is licensed under the MIT License - see the LICENSE file for details