Coder Social home page Coder Social logo

cfgmgmtcmp-2019-iac-ci-cd's Introduction

Real World AWS Packer & Terraform and Inspec Pipeline

This is a working Jenkinsfile Multibranch Pipeline for building AWS AMI's images & deploying EC2 instances based on the AMI with terraform (in both a per-branch test stack, destroyed by the pipeline, and maintaining production from the master branch).

The pipeline uses 2 docker images to run jobs, most of the work is done in hashicorp-pipeline, which contains packer, terraform, aws cli & some other needed binaries (jq, perl), the other docker image used is chef/inspec, which is used to test the stack built during non-master pipeline executions.

Features

  • terraform fmt -check=true -diff=true used to check terraform config files
  • packer validate used to validate packer config files
  • base and application AMI's built and tagged with SHA1 of the base/base.json and app/app.json, to help prevent unnecessary AMI builds
  • Automatically configures terraform remote state (S3 & DynamoDB)
  • terraform workspaces used to store per-branch terraform state
  • parameterized terraform build using per-branch tfvars
  • chef/inspec used to validate AWS resources
  • terraform plan with stash of plan, human approval, terraform apply workflow for master/production changes

What next to use this in your own project

  • Add demo-aws-creds credential set (uses AWS Credentials plugin)
  • Update terraform to actually deploy an EC2 instance (for demo purposes, this only builds a VPC, so zero cost & quick cycle time for pipeline experimentation, trivial to add an EC2 instance)
  • Use AWS Auto Scaling group to replace running EC2 instances with EC2 instances built from the master branch app AMI
  • Use AMI tags to ensure app AMI matches the branch (Use the SHA1 of app/app.json to search for the AMI in terraform, requires some tfvars templating/injection)
  • Extend chef/inspec stage to test AWS EC2
  • Add a Selenium or other web test stage

If you want a simple dockerized Jenkins setup to host this, I used Jenkins 201, there's also example Job DSL here.

Further info

Some of the scripts in this pipeline (build.sh & common.sh) are based on an incomplete packer/AMI example from CircleCI.

aws ec2 deregister-image --image-id ami-4fa54026

HMM

cfgmgmtcmp-2019-iac-ci-cd's People

Contributors

simonmcc avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.