Skip to content

Automatically build and deploy AWS infrastructure-as-code (IaC) changes using AWS CodePipeline.

License

Notifications You must be signed in to change notification settings

robsable/aws-iac-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Setup an AWS IaC pipeline using AWS CodePipeline

This project uses AWS CodePipeline to automatically build and deploy AWS infrastructure-as-code (IaC) changes. Both Terraform and AWS CloudFormation are used to deploy resources in an AWS account, allowing you to compare and experiment with the approaches.

Resources deployed include:

  • S3 Bucket
  • SQS Queue w/ DLQ

AWS IaC Deployment Pipeline

📝 NOTE Follow these instructions to setup an IaC pipeline in your own AWS account.

Setup your GitHub.com repository

  1. Download the latest release of this project from GitHub.com and extract it on your local drive.

  2. Go to the S3 buckets list in the AWS Management Console.

    • Create a new S3 Bucket that will be used to store the current Terraform state for your resources
    • Or, note the name of an existing bucket to be used for this purpose
  3. Edit the aws-iac-pipeline/terraform/providers.tf file to set values for the S3 backend:

    • bucket - the name of your S3 bucket from the previous step
    • region - the AWS Region you're working in
  4. Edit the aws-iac-pipeline/terraform/variables.tf file to set values for the following:

    • aws_region - the AWS Region you're working in
    • app_name - a unique name of your choice
    • app_env - the environment you're working in (dev, test, or prod)
  5. Create a new private GitHub repository using the contents of the aws-iac-pipeline directory.

Connect AWS to GitHub.com

  1. Sign in to the AWS Management Console
  2. Open the Developer Tools Console
  3. Follow these instructions to create a connection to GitHub.com
  4. Once your connection is setup, note the Connection ID which you will need in a later step. The Connection ID is the 36 character string at the end of the Connection ARN.

Deploy the CodePipeline

  1. In the AWS Management Console we'll create a CloudFormation Stack to deploy our pipeline and associated resources.
  2. Specify a template by choosing Upload a template file and then the Choose file button.
  3. Select the aws-iac-pipeline/cloudformation/pipeline-setup.yml file from your local drive and choose Next.
  4. Specify stack details and choose Next.
    • Stack name - a unique name of your choice
    • AppName - a unique name of your choice
    • ConnectionID - the 36 character Connection ID you captured earlier
    • SourceRepo - full path to your GitHub.com repo (Example: some-user/my-repo)
  5. Choose Next again to accept default options.
  6. Scroll to the bottom of the page, acknowledge the checkbox, and choose Submit.

Review CodePipeline Execution History

  1. Navigate to the Pipelines list in the AWS Management Console.
  2. Find the pipeline named AppName-pipeline to see details and results

AWS CodePipeline

Code, Build, Deploy, Repeat

At this point you're ready to start adding your own IaC resources using CloudFormation and Terraform. Each time your code is checked in to your GitHub.com repostitory, an AWS CodePipeline will automatically be triggered.

Follow these same setup steps in different AWS accounts to setup IaC pipelines for each of your applications and environments.

Clean Up

  1. Delete build artifacts

    • Go to the S3 buckets list in the AWS Management Console.
    • Find the S3 bucket named <AppName>-<AWS_ACCOUNT_ID>-build-artifacts.
    • Select the bucket and choose and Empty to delete its contents.
  2. Destroy Terraform resources

    • Go to the CodeBuild projects list in the AWS Management Console.
    • Select your project from the list and choose View Details.
    • Choose the Edit button in the top right and scroll down to the Buildspec section.
    • Choose the Use a buildspec file option and enter cleanup.yml in the text field.
    • Scroll to the bottom and choose Update project.
    • Return to the Pipelines list, select your pipeline, and choose Release Change.
    • View the build results to confirm removal of Terraform resources.
  3. Delete CloudFormation stacks

    • Go to the CloudFormation stacks list in the AWS Management Console.
    • Delete the IaC pipeline example resources stack
    • Delete the Automated IaC build and release pipeline stack
  4. Delete GitHub.com connection

    • Go to the Connections list in the AWS Management Console.
    • Select the connection you created and choose Delete.

About

Automatically build and deploy AWS infrastructure-as-code (IaC) changes using AWS CodePipeline.

Topics

Resources

License

Stars

Watchers

Forks

Languages