Giter VIP home page Giter VIP logo

hashitalks-terratest's Introduction

Demo for HashiTalks Africa Talk

Slides

The talk focuses on demoing a simple scenario

  • Create a docker image using Docker
  • Create an AMI with docker pre-installed using Packer
  • Create an instance with the AMI using Terraform
  • Provision the instance with a docker container

All these various steps are unit tested and an eventual integration and E2E test is used to check all the components work as needed.

All the tests are in the tests package.

What is Terratest

Terratest is a testing library in Go that checks that your terraform code works as expected.

To properly test your application, it's advisable to package your code into modules.

Terraform modules allow you resuse your TF code and configure different variables to your resources.

So this allows you to have isolations for testing a single resource independently without specifying a -target that's more of a hack to testing.

Folder Structures

> tree examples modules tests
examples
├── data.tf
├── main.tf
├── outputs.tf
├── terraform.tfstate
├── terraform.tfstate.backup
└── variables.tf
modules
├── aws
│   ├── ec2
│   │   ├── data.tf
│   │   ├── main.tf
│   │   ├── outputs.tf
│   │   └── variables.tf
│   └── security_group
│       ├── main.tf
│       ├── outputs.tf
│       └── variables.tf
├── docker
│   ├── Dockerfile
│   ├── main.go
│   └── README.md
└── packer
    ├── README.md
    └── builder.json
tests
├── aws_ec2_instance_test.go
├── aws_infra_integration_test.go
├── aws_security_group_module_test.go
├── docker_test.go
└── packer_build_test.go

12 directories, 33 files

Examples

All the code for the demo using the modules are here We use this to deploy the entire app.

Modules

All the modules we use in the examples are written here. We define a

  • Module for creating a security group and ec2 instance on AWS.
  • Module for the docker artifacts
  • Module for the packer artifacts

Tests

All the tests for the modules and the entire thing runninng together is found here You can run the tests by doing

cd tests
go test

hashitalks-terratest's People

Contributors

bakare-emmanuel avatar tiemma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.