• Stars
    star
    160
  • Rank 234,703 (Top 5 %)
  • Language HCL
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple and idiomatic examples of various Terraform functions and features.

terraform-examples

A reference repository of Terraform with canonical and as-simple-as-possible demonstrations of Terraform functionality and features.

See here for a searchable front-end: https://containersolutions.github.io/terraform-examples/

Why?

At Container Solutions we find we regularly need chunks of Terraform to demonstrate something specific, such as:

  • A simple EC2 instance

  • A bespoke VPC

  • A Windows EC2 instance with an EBS volume

This might be to do a basic test of something, find an example to tinker with, or send to someone to get them going.

Usage

To help get started with these examples, there are scripts available in bin and in local folders.

Here's an example run:

$ git clone https://github.com/ContainerSolutions/terraform-examples
$ cd terraform-examples
$ cd aws/aws_vpc
$ ./run.sh
Input AWS_ACCESS_KEY_ID
KEY
Input AWS_SECRET_ACCESS_KEY
<secret>
...

If you want to skip the manual key/id inputs, then export them.

See bin/README.md for more information.

Where is...?

If you want to look for a specific example, try the index.

Sections

The code is generally divided up by provider, then resource, then whatever the example illustrates, eg local/null_resource/for_each, or aws/aws_instance/remote-exec/inline.

Other basic language features may be illustrated in their own folders, eg outputs/local_file/module.

Principles

The examples seek to be:

  • As simple as possible to illustrate the functionality

  • Self-contained (ie limited to one .tf file)

  • Clear (eg resource names are verbose and unambiguous)

Conventions

  • Naming examples:

    • simple - for minimal functionality demonstration
    • <functionality> - when demonstrating something more than minimal
    • directory structure: <provider>/<resource_type>/<example_name>
  • Where it makes sense, items that can be changed are prefaced with changeme_

  • In general, underscores are used in Terraform names over dashes

  • Naming Terraform resources, data, and variables:

    • use only lower case letters, numbers, and underscore
    • names should be unique between all examples (but across resources items only if a resource; data items only if data, etc)
    • prefixed with: changeme_<example_name>_
  • name = attribute within the resource:

    • use only lower case letters, numbers, and dash
    • same as resource name, but with: s/_/-/g
  • For help with automated testing

    • where possible, add some way to enable 'left-over' resources to be cleaned up, eg provider default_tags of cs_terraform_examples in AWS provider blocks
  • Add inline documentation for each Terraform code block

    • # Summary: – 1-line summary of what this example does
    • # Documentation: – add link to documentation before each block (terraform, provider, variable, resource, etc.)
    • # Explanation: – add only where some extra explanation is needed

Contributing

Contributions to terraform-examples project are welcome. You can find detailed information about contributing here.

GitHub Actions Workflow

On every commit/push, the following tests run on all branches:

  • A tflint on all files ending with tf

  • A terraform validate on all

  • A series of checks to test the code against standards

Using slash command /test, a maintainer can run Cloud Testing jobs. This includes:

  • All AWS provider examples are run against an AWS account

  • All GCP provider examples are run against a GCP account

  • All Linode provider examples are run against a Linode account

  • All DigitalOcean provider examples are run against a DigitalOcean account

  • All 'local' provider examples are run locally on the GitHub Actions runner

Cloud Environment tests are long and/or cost money and they won't work without the necessary auth information being set up correctly.

The auth information for the provider accounts are stored in secrets in the repository, accessible to the admin.

Slash commands can be used to approve/merge the PR, '/approve' or '/merge'.

The Flow:

  • PR is opened

  • Contributor commits/pushes on-demand and triggers the Statis Tests

  • Once ready, and maintainer runs the Full-CI, which includes Cloud Tests '/test'

  • If everything goes well, the maintainer uses the command '/approve' to mark as reviewed/approve

  • The last step, after everything is checked, '/merge' to perform the merge to the main branch

Note: All the slash commands are performed by Github Actions BOT with GITHUB_TOKEN

Forcing tests

You can force a test for a given provider (on main branch only) by adding a .forcetest file to the relevant folder.

For example, if you want to ensure that the aws tests run, then add an empty file in aws/.forcetest. On a successfully completed test run, these files are removed as part of the 'success commit' in the github action workflow.

## Maintainer Information

For information for maintainers of this repository at ContainerSolutions, see maintainers

Sources / Thanks To

Learn Terraform The Hard Way Slash Commands

Other Examples

Immutable Cluster Using Packer and Ansible on AWS

More Repositories

1

k8s-deployment-strategies

Kubernetes deployment strategies explained
Go
3,504
star
2

kubernetes-examples

Minimal self-contained examples of standard Kubernetes features and patterns in YAML
Shell
1,394
star
3

trow

Container Registry and Image Management for Kubernetes Clusters
Rust
808
star
4

minimesos

The experimentation and testing tool for Apache Mesos - NO LONGER MAINTANED!
Java
431
star
5

helm-monitor

Monitor K8S Helm release, rollback on metrics behavior (Prometheus, Elasticsearch, Sentry)
Go
409
star
6

helm-convert

Convert Helm charts into Kustomize compatible package
Go
215
star
7

externalsecret-operator

An operator to fetch secrets from cloud services and inject them in Kubernetes
Go
189
star
8

runbooks

A collection of step by step guides for fixing common tech problems.
HTML
129
star
9

ImageWolf

Fast Distribution of Docker Images on Clusters
Go
128
star
10

locust_exporter

A Locust metrics exporter for Prometheus
Go
108
star
11

terraform-mesos

Stuff for programming a Mesos cluster on the Google Cloud
Shell
98
star
12

prometheus-swarm-discovery

This is a POC for Prometheus service discovery on Docker Swarm
Go
76
star
13

registry-tooling

Install a secure Docker registry on any Kubernetes cluster with a single command
Shell
70
star
14

cd_demo

Demo for a full (almost) CD pipeline with git, jenkins, docker, mesos
Shell
65
star
15

prom-metrics-check

Python
64
star
16

tinkerbell-rpi4-workflow

Instructions and configuration files to create tinkerbell workflow for raspberry pi 4
Shell
50
star
17

cd-with-docker-tutorial

Continuous Integration and Delivery with Docker
Go
50
star
18

docker-cobbler

Cobbler in a Docker container
Makefile
49
star
19

mesos-starter

Java
46
star
20

docker-registry-proxy

Docker Registry 2.0 proxy with SSL and authentication
Shell
31
star
21

stackdriver-gke-custom-metrics

Example python code sending custom container metrics to Stackdriver Monitoring
Python
23
star
22

dcos-in-triton

Infrastructure setup for running DCOS in Joyent's Triton
Python
21
star
23

terraform-provider-cobbler

Terraform provider for Cobbler
Go
18
star
24

capabilities-blog

Code supporting capabilities blog
C
18
star
25

terraform-nomad

Terraform scripts for creating a Nomad cluster on Google Cloud.
HCL
16
star
26

zookeeper

Zookeeper with dynamic host reconfiguration
Shell
16
star
27

cloud-native-patterns

Cloud Native Patterns
HTML
14
star
28

learning-mesos-with-minimesos-workshop

13
star
29

mesos-hello-world

Very simple hello world mesos framework to demonstrate mini-mesos
Java
12
star
30

construct

Mesos framework for deploying a single task on all agents of the cluster
Python
11
star
31

mesosframework

Create a mesos framework with just an application.properties file!
Java
11
star
32

unifi-fargate

Deploy a Unifi Controller on AWS ECS Fargate using Terraform
HCL
11
star
33

pactbroker_exporter

A Pact Broker metrics exporter for Prometheus
Go
10
star
34

php-k8s

PHP on Kubernetes
PHP
9
star
35

delayed-jobs-operator

Go
9
star
36

terraform-provider-template

Skeleton for building a Terraform provider
Go
8
star
37

kubernetes-federation-demo

Demo setup for Kubernetes Cluster Federation
Go
8
star
38

redis-cluster-operator

A Kubernetes Operator for running Production Redis Clusters
Go
7
star
39

mesos-local

Mesos cluster in a container. Used by Mini-Mesos https://github.com/ContainerSolutions/mini-mesos
Groovy
7
star
40

k8shserver

Shell
7
star
41

cobblerclient

Cobbler Client written in Go
Go
7
star
42

kubadm-ansible

Ansible scripts to create & destroy a Kubernetes cluster using kubeadm
7
star
43

gitops-training-lab

Shell
7
star
44

timber

Timber - The Training Companion App
Python
7
star
45

dockerfiles

Dockerfile
6
star
46

kubernetes-demo

Go
6
star
47

minimesos-docker

minimesos Docker images
Shell
6
star
48

keda-kafka

This repo contains everything to create a demo where you can scale Kafka consumers depending on the queue size on a Kafka Topic from scratch.
Shell
6
star
49

k8sbhw

Kubernetes beyond hello world
Go
5
star
50

reveal-md

A CS themed version of Reveal-MD running on Alpine in a Docker Container
CSS
5
star
51

bootstrap-habitat-supervisors-on-k8s

Bootstrap habitat supervisors on top of kubernetes
Ruby
5
star
52

argus-gephi-connector

Argus with Gephi integrated together to get real-time visualisation of infrastructure
Python
5
star
53

helm-charts

A barebone Helm Chart repository
Smarty
5
star
54

habitat-redis-ha-cluster-on-k8s

Run a self organizing HA redis cluster on top of k8s.
Shell
5
star
55

go-validation-admission-controller

Demo implemention of a validation admission controller webhook
Go
5
star
56

dcos-ansible-packet

Ansible playbook for installing DC/OS on Packet cloud
Python
4
star
57

node-hack

A vulnerable nodejs application for hollywood-style hacking demos
JavaScript
4
star
58

bookinfo

Go
4
star
59

go-example-webserver

Example Go Webserver for training purposes
Groovy
4
star
60

ws-production-grade-kubernetes

Materials for the Production Grade Kubernetes workshop
Go
4
star
61

goto-prometheus

HTML
4
star
62

lean-go-containers

Example code for the blog post on building lean go containers using Docker multi-stage builds, which went stable in docker 17.06.
Go
4
star
63

kong-demo

A repo that will demonstrate some of the functionality of the kong ingress
Makefile
4
star
64

ha-redis-kubernetes

Manual Redis HA in Kubernetes with Zero Downtime updates and upgrades
Python
4
star
65

ws-kubernetes-essentials-app

HTML
3
star
66

saferun

run binaries with encrypted environment variables
Go
3
star
67

minimesos.org

minimesos.org
HTML
3
star
68

operator-workshop

Go
3
star
69

minimesos-mdns

Service for publishing minimesos containers via mdns
JavaScript
3
star
70

nixpkgs-overlay

Overlay for fun and profit
Nix
3
star
71

minimesos-maven-plugin

A Maven plugin for minimesos. Control your minimesos cluster from Maven
Java
3
star
72

k8s-federation-demo

demo app to demonstrate Kubernetes cluster federation
JavaScript
3
star
73

loki-grafana-promtail-k8s

3
star
74

codeship-docker-compose-examples

HTML
2
star
75

pres-prereq-to-docker

JavaScript
2
star
76

API-Excercise

The Container Solutions API Exercise Version 2.0
Python
2
star
77

jMeter-docker

dockerised jMeter
Shell
2
star
78

distributed-secrets

Go
2
star
79

kubernetes-cheatsheet

Cheatsheet with useful Kubernetes commands or tools
2
star
80

marathon-haproxy-subdomain-bridge

Go
2
star
81

kubernetes-deployment-tools

Docker image with a series of tools intended at Kubernetes deployments
Dockerfile
2
star
82

warsaw-workshop

repository to share with workshop participants
2
star
83

maturity-matrix

Maturity Matrix
JavaScript
2
star
84

template-spring-boot

Template for a Spring boot project
Java
2
star
85

space-oddity

Drone project
JavaScript
2
star
86

avazacli

Generated avaza API client
Python
2
star
87

external-secrets-charm

Python
2
star
88

ws-k8s-foundation-sample-app

HTML
2
star
89

gcp-billing-csv

DB to store billing csv data from GCP in Postgres so it can be queried using SQL
Shell
2
star
90

toolset

CSS
1
star
91

google-cloud-cli

Container image with tools for interacting with the Google Cloud and Kubernetes
Makefile
1
star
92

kuberviz

Semantically visualize your Kubernetes cluster
JavaScript
1
star
93

geoserver

HTML
1
star
94

python-application-operator

Python
1
star
95

sandbox-weave-net-minimesos

Experiment to run Weave Net inside minimesos
Shell
1
star
96

libmesos

1
star
97

node-openshift-sample

JavaScript
1
star
98

WheelOfFortune

Python
1
star
99

techterrarium

A controlled environment for nurturing and observing tech experiments.
1
star
100

go-utils

Utils library for Go
Go
1
star