Public Repository

Last pushed: 10 days ago
Short Description
Terraform runner container on Alpine 3.6
Full Description

marcelocorreia/terraform

Docker image with Hashicorp Terraform + AWS CLI + Goodies

Github https://github.com/marcelocorreia/docker-terraform

Packages

  • ca-certificates
  • update-ca-certificates
  • curl
  • unzip
  • bash
  • python
  • py-pip
  • openssh
  • git
  • make
  • tzdata
  • awscli (via PIP)
  • jq

INFO

Usage

$> docker run --rm -v $(pwd):/opt/workspace \
           marcelocorreia/terraform \
           terraform [--version] [--help] <command> [args]

Setting timezone

$> docker run --rm -v $(pwd):/opt/workspace \
        -e TZ=Australia/Sydney \
           marcelocorreia/terraform \
           terraform [--version] [--help] <command> [args]

Example

$> docker run --rm -v $(pwd):/opt/workspace \
           marcelocorreia/terraform \
           terraform $1 -var-file variables.tfvars \
           -var aws_access_key=${aws_access_key_id} \
           -var aws_secret_key=${aws_secret_access_key}

Makefile example

# VARS
TF_IMAGE?=marcelocorreia/terraform:latest
VARS_FILE?=variables.tfvars

# TF
tf-plan:
    $(call terraform, plan)
.PHONY: tf-plan

tf-apply:
    $(call terraform, apply)
.PHONY: tf-apply

tf-destroy:
    $(call terraform, destroy)
.PHONY: tf-destroy

tf-refresh:
    $(call terraform, refresh)
.PHONY: tf-refresh

tf-show:
    $(call terraform, show)
.PHONY: tf-show

tf-shell:
    @docker run --rm -it -v $(shell pwd):/opt/workspace \
            $(TF_IMAGE)\
            bash
.PHONY: tf-shell

tf-state-list:
    $(call terraform, state list)
.PHONY: tf-show

# DOCKER
tf-image-update:
    docker pull $(TF_IMAGE)
.PHONY: tf-image-update

# ROUTINES
define terraform
    @docker run --rm -v $(shell pwd):/opt/workspace \
        $(TF_IMAGE)\
        terraform $1 -var-file $(VARS_FILE) \
        -var aws_access_key=${aws_access_key_id} \
        -var aws_secret_key=${aws_secret_access_key}
endef

Check the Concourse CI Pipeline used to build this image

Concourse Build Configuration Example

platform: linux

image_resource:
  type: docker-image
  source:
    repository: marcelocorreia/terraform
    tag: 'latest'

inputs:
- name: terraform-repo

run:
  path: terraform
  args: 
  - plan
  - -var-file
  - variables.tfvars
Docker Pull Command
Owner
marcelocorreia

Comments (0)