Giter Club home page Giter Club logo

aws-codecommit-codepipeline-avx-terraform's Introduction

What does this do?

This will create a end to end AWS pipeline deployment. The code will create the following:

  • S3 backend for aviatrix resources
  • CodeCommit repo to store aviatrix terraform code. The will also output the username, password and https git clone url to clone the repo to your local machine
  • Creation of a SG, private subnet, route table for codebuild. EIP for NAT gw.
  • CodeBuild projects for terraform plan and apply, creation and deletion of NAT gateway during deployment
  • CodePipeline (with manual approval to prevent auto-apply) to deploy avaitrix resources

Prerequisites

  • Aviatrix controller deployed and accounts onboarded
  • Docker hub account https://hub.docker.com/ (A docker image with terraform preinstalled will be used in the codebuild phase)
  • AWS secrets

For docker credentials and aviatrix controller credentials

  • Docker secrets

  • Once you create an account in docker hub, create a secret in AWS secrets manager with the username and password you used on docker hub

Secret for Docker

  • Obtain the arn of the secret you just created

  • Aviatrix controller secrets

  • Create a secret key AVIATRIX_CONTROLLER_IP with the name controller_ip. The value is the private IP of the controller.

These will be used as environment variables to login to the controller later during the build stage

Secret for controller_ip

  • Create a secret key AVIATRIX_PASSWORD with the name controller_password

Secret for controller_password

Variables

The following variables are required:

key value
tfstate_s3_bucket_name
tfstate_dynamod_db_table_name
tfstate_s3_bucket_region
codecommit_iam_group_name
codecommit_iam_user_name
codecommit_repository_name
codecommit_repository_description
pipeline_s3_bucket
dockerhub_credentials ARN of the secret created initially
sns_subscription_email_id
sns_topic_name
tfstate_filename
codebuild_az "eu-west-1a"
avtx_ctrl_vpc_id "vpc-082f55ce6f7636247"
codebuild_cidr_block "10.41.245.32/28"
subnet_id_for_NATgw Public subnet to deploy NAT gw
AviatrixSecurityGroupID "sg-0093029b7aabb3ca8"

How to use

Step 1

  • Download the code, fill out the variable values in terraform.tfvars and then do:
terraform init
terraform plan
terraform apply

Successful completion of the above step would also create a file called backend.tf under the directory use-for-tfstate

Step 2

git clone <output of repo_clone_url>

Use the username and password from the output values

Step 3

Copy the backend.tf file from the directory use-for-tfstate to the cloned repo. This will be used as the S3 backend for aviatrix resources

Step 4

Add code to the repo

Sample main.tf

module "aws_transit" {
  source  = "terraform-aviatrix-modules/mc-transit/aviatrix"
  version = "2.1.3"

  cloud         = "aws"
  region        = "eu-west-3"
  cidr          = "10.1.0.0/23"
  account       = "aws-acc"
}

Step 5

Push the code to the repo and the pipeline will automatically trigger in a few minutes. If everything is OK, the pipeline would stop just before the last stage (terraform apply -auto-approve) and would send an email to the user to manually approve the change

Step 6

After manual approval, the pipeline would proceed to deploy the resources and finish successfully

A completed pipeline would look like this:

Pipeline execution

PS: I reused the base code related to codebuild/pipeline from https://github.com/davoclock/aws-cicd-pipeline and modified it to use AWS codecommit as the source and use AWS secret manager to set environmental vars in the buildspec yml files. I added an approval stage to use SNS notifications to alert the user. I also added additional codebuild projects to create and delete NAT gateway and corresponding codepipeline stages during the workflow.

aws-codecommit-codepipeline-avx-terraform's People

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.