subhamay-bhattacharyya / gh-action-reusable-aws-tf-wf

GitHub Reusable workflows for AWS with Terraform as IaC.
0 stars 0 forks source link

        

CI/CD Workflow Create and Deploy Stack

graph LR
    A[Git Push] -- Feature Branch ? --> B>Build & Package - Feature] --> C>Create Stack - Feature] --> D>Delete Stack - Feature] --> E>Create Release] -.-> L>Create PR]
    A[Git Push] -- Merge PR  --> F>Build & Package - Devl] --> G>Create Stack - Devl]
    A[Git Push] -- 1st Level Approval --> H>Build & Package - Test ] --> I>Create Stack - Test]
    A[Git Push] -- 1st & 2nd Level Approvals --> J>Build & Package - Prod] --> K>Create Stack - Prod]
    G>Create Stack - Devl] --> I>Create Stack - Test]
    I>Create Test Stack] --> K>Create Stack - Prod]

To use the pipeline in your repository create a create-stack.yaml file in .github/workflows

name: Parent CI-CD Workflow

on:
  push:

permissions:
  id-token: write       # This is required for aws oidc connection
  contents: read        # This is required for actions/checkout
  pull-requests: write  # This is required for gh bot to comment PR
  issues: write

jobs:
  cf-cicd:
    name: CI-CD
    uses: subhamay-bhattacharyya/gh-action-reusable-aws-tf-wf/.github/workflows/cf-cicd-create.yaml@main
    with:
      deploy-reviewer-test: <GitHub User Id for Test Environment>
      deploy-reviewer-prod: <GitHub User Id for Test Environment>
      pr-approver: <GitHub User for Pull Request>

Reusable nested workflows

graph TD
    A[user/repo/.github/workflows/create-workflow.yaml] -->B[.github/workflows/cf-cicd-create.yaml]
    B[.github/workflows/cf-cicd-create.yaml]--> C[.github/workflows/setup-repository.yaml]
    B[.github/workflows/cf-cicd-create.yaml] -->D[.github/workflows/cf-package.yaml]
    B[.github/workflows/cf-cicd-create.yaml] -->E[.github/workflows/cf-create.yaml]
    B[.github/workflows/cf-cicd-create.yaml] -->F[.github/workflows/cf-delete.yaml]
    B[.github/workflows/cf-cicd-create.yaml] -->G[.github/workflows/release.yaml]

CI/CD Workflow Delete Stack

graph LR
    A[Trigger Delete] --> B>Delete Development] -- 1st Level Approval --> C>Delete Test Stack] -- 1st & 2nd Level Approvals --> D>Delete Prod Stack]

To use the pipeline in your repository create a delete-stack.yaml file in .github/workflows

name: Parent CI-CD Workflow

on:
  push:

permissions:
  id-token: write                       # This is required for aws oidc connection
  contents: read                        # This is required for actions/checkout
  pull-requests: write                  # This is required for gh bot to comment PR
  issues: write

jobs:
  cf-cicd:
    name: CI-CD
    uses: subhamay-bhattacharyya/gh-action-reusable-aws-tf-wf/.github/workflows/cf-cicd-delete.yaml@main

Reusable nested workflows

graph TD
    A[user/repo/.github/workflows/delete-workflow.yaml] -->B[.github/workflows/cf-cicd-delete.yaml] -->C[.github/workflows/cf-delete.yaml]

Setting up the CI/CD Pipeline

Root
├─ Management
├─ Development
├─ Test
└─ Production

Lambda Name and Version Parameter



* Create three repository environments in GitHub (devl, test, prod)

* Create the following GitHub repository Secrets:

|Secret Name|Secret Value|
|-|-|
|AWS_REGION|```us-east-1```|
|DEVL_AWS_KMS_KEY_ARN|```arn:aws:kms:<AWS Region>:<Development Account Id>:key/<KMS Key Id in Development>```|
|TEST_AWS_KMS_KEY_ARN|```arn:aws:kms:<AWS Region>:<Test Account Id>:key/<KMS Key Id in Test>```|
|PROD_AWS_KMS_KEY_ARN|```arn:aws:kms:<AWS Region>:<Production Account Id>:key/<KMS Key Id in Production>```|
|DEVL_AWS_ROLE_ARN|```arn:aws:iam::<Development Account Id>:role/<OIDC IAM Role Name>```|
|TEST_AWS_ROLE_ARN|```arn:aws:iam::<Test Account Id>:role/<OIDC IAM Role Name>```|
|PROD_AWS_ROLE_ARN|```arn:aws:iam::<Production Account Id>:role/<OIDC IAM Role Name>```|
|DEVL_CODE_REPOSITORY_S3_BUCKET|```<Repository S3 Bucket in Development>```|
|TEST_CODE_REPOSITORY_S3_BUCKET|```<Repository S3 Bucket in Test>```|
|PROD_CODE_REPOSITORY_S3_BUCKET|```<Repository S3 Bucket in Production>```|

### Executing the CI/CD Pipeline

* Create Create a feature branch and push the code.
* The CI/CD pipeline will create a build and then will deploy the stack to devlopment.
* Once the Stage and Prod deployment are approved (If you have configured with protection rule ) the stack will be reployed in the respective environments