|
1 | 1 | # AWS DevSecOps Pipeline - Terraform |
2 | 2 |
|
3 | | -# Steps |
| 3 | + |
| 4 | + |
4 | 5 |
|
5 | | -1. Setup Terraform Cloud and create API Key |
6 | | -1. Save key as a token on your local machine and in your repository settings within GitHub |
7 | | -1. Create your GitHub OAUTH Token and save it as an environment variable within Terraform Cloud. |
| 6 | +## Overview |
| 7 | + |
| 8 | +This project provides an automated DevSecOps pipeline for deploying infrastructure using Terraform, AWS, and Snyk for vulnerability scanning. The pipeline is designed to streamline infrastructure management while ensuring security through continuous integration and deployment practices. |
| 9 | + |
| 10 | +## Requirements |
| 11 | + |
| 12 | +- **Terraform** (latest stable version) |
| 13 | +- **Terraform Cloud** account |
| 14 | +- **Snyk** account for vulnerability scanning |
| 15 | +- **AWS** account with appropriate permissions |
| 16 | + |
| 17 | +## Setup Instructions |
| 18 | + |
| 19 | +### 1. **Terraform Cloud Setup** |
| 20 | + |
| 21 | +- Create an account on Terraform Cloud and generate an API key. |
| 22 | +- Store the API key as a token on your local machine. |
| 23 | +- In your GitHub repository settings, add the API token for Terraform Cloud. |
| 24 | + |
| 25 | +### 2. **Configure Terraform** |
| 26 | + |
| 27 | +- Clone or download this repository. |
| 28 | +- Update the `terraform-apply.yml` file with your organization name. |
| 29 | +- Modify the `provider.tf` file to include your correct Terraform Cloud workspace name (do not use "DSB"). |
| 30 | +- Move into the `terraform` directory, and enter in the following commands: |
| 31 | + |
| 32 | +```bash |
| 33 | +terraform init |
| 34 | +terraform plan |
| 35 | +``` |
| 36 | + |
| 37 | +### 3. **Configure Snyk** |
| 38 | + |
| 39 | +- Create an account on [Snyk](https://www.snyk.io/) and generate an API Token. |
| 40 | +- Follow the Snyk CLI [documentation](https://docs.snyk.io/snyk-cli/configure-the-snyk-cli) to configure your CLI. |
| 41 | +- Save your Snyk organization ID as an environment variable in Terraform Cloud as a protected `Workspace Variable`: |
| 42 | + |
| 43 | +### 4. **Environment Variables** |
| 44 | + |
| 45 | +Set up the following environment variables within your Terraform Cloud workspace or locally: |
| 46 | + |
| 47 | +- `SNYK_TOKEN`: Your Snyk API token. |
| 48 | +- `SNYK_ORG_ID`: Your Snyk organization ID. |
| 49 | + |
| 50 | +### 5. **Terraform Initialization and Apply** |
| 51 | + |
| 52 | +Run the following commands to initialize Terraform, plan the deployment, and apply the changes: |
| 53 | + |
| 54 | +```bash |
| 55 | +terraform apply |
| 56 | +``` |
| 57 | + |
| 58 | +### 6. **Verify AWS Changes** |
| 59 | + |
| 60 | +Log in to the AWS Console and verify the changes made by Terraform: |
| 61 | + |
| 62 | +- Navigate to the AWS [Codesuite Settings](https://us-east-1.console.aws.amazon.com/codesuite/settings/connections?region=us-east-1&connections-meta=eyJmIjp7InRleHQiOiIifSwicyI6e30sIm4iOjIwLCJpIjowfQ#). |
| 63 | +- Update the pending connection to make it active. |
| 64 | + |
| 65 | +### 7. **Next Steps** |
| 66 | + |
| 67 | +Once the pipeline is set up and verified, you can move to the next codebase for further configurations or deployments. |
| 68 | + |
| 69 | +## Modules |
| 70 | + |
| 71 | +The `modules` directory contains reusable Terraform modules designed for different parts of the infrastructure. Below is a brief overview of each module: |
| 72 | + |
| 73 | +### 1. **S3 Module** |
| 74 | + |
| 75 | +This module is responsible for provisioning and managing AWS S3 buckets. It defines the main configurations for creating S3 buckets, specifying variables such as bucket name and region. |
| 76 | + |
| 77 | +- **Files**: |
| 78 | + - `main.tf`: S3 bucket creation and configuration. |
| 79 | + - `variables.tf`: Variables such as bucket name, region, etc. |
| 80 | + - `outputs.tf`: Outputs for the S3 bucket, such as the bucket name or ARN. |
| 81 | + |
| 82 | +### 2. **CodePipeline Module** |
| 83 | + |
| 84 | +The CodePipeline module automates the setup of an AWS CodePipeline for continuous integration and deployment. It includes configuration for stages, actions, and integration with other AWS services like ECR and Secrets Manager. |
| 85 | + |
| 86 | +- **Files**: |
| 87 | + - `main.tf`: Defines the pipeline, stages, and actions. |
| 88 | + - `ecr.tf`: Configures ECR (Elastic Container Registry) to store Docker images. |
| 89 | + - `buildspecs`: Contains build instructions for CodeBuild. |
| 90 | + - `secrets.tf`: Configures secrets management for the pipeline. |
| 91 | + - `configmap.tf`: Configures Kubernetes ConfigMaps for integration with EKS (if applicable). |
| 92 | + - `variables.tf`: Defines variables specific to the pipeline. |
| 93 | + - `provider.tf`: Specifies AWS provider details. |
| 94 | + |
| 95 | +### 3. **EKS Module** |
| 96 | + |
| 97 | +This module provisions an EKS (Elastic Kubernetes Service) cluster, including the configuration for node groups and cluster resources. |
| 98 | + |
| 99 | +- **Files**: |
| 100 | + - `main.tf`: Defines the EKS cluster, node groups, and related resources. |
| 101 | + - `variables.tf`: Variables such as cluster name, region, and node configurations. |
| 102 | + - `outputs.tf`: Outputs like the EKS cluster name or endpoint. |
0 commit comments