Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gh actions addition #9

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a2886dc
feat: added the workflow file
oneanupam Jun 12, 2024
90b4742
feat: renamed the tf-variables providers file
oneanupam Jun 12, 2024
a573788
feat: updated the working dir
oneanupam Jun 12, 2024
d7d3880
feat: added the sdk installation and auth stage
oneanupam Jun 12, 2024
02de73f
feat: removed quotes
oneanupam Jun 12, 2024
32a5aa7
feat: removed stage
oneanupam Jun 12, 2024
886b732
feat: removed the old required params for gcp auth stage
oneanupam Jun 12, 2024
109a66e
feat: removed the old required params for gcp auth stage
oneanupam Jun 12, 2024
0d197ac
feat: removed the old required params for gcp auth stage
oneanupam Jun 12, 2024
2baa321
feat: removed the old required params for gcp auth stage
oneanupam Jun 12, 2024
5e9e49b
feat: removed the old required params for gcp auth stage
oneanupam Jun 13, 2024
02d3988
feat: removed the old required params for gcp auth stage
oneanupam Jun 13, 2024
0cdabfc
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
3949499
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
c5ca39a
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
e82b4fa
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
8202eca
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
41d0c43
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
57a0405
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
310bd08
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
efe266d
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
dac9aee
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
db2ad78
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
d4cc975
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
c004638
feat: removed the old required params for gcp auth stage
oneanupam Jun 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions .github/workflows/gitops.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: GitOps Implementation
on:
pull_request:
branches:
- master
push:
branches:
- master
workflow_dispatch:
defaults:
run:
working-directory: ./tf-variables/
env:
TERRAFORM_VER: 1.8.0
TERRAFORM_DIR: "./tf-variables/"
CLOUDSDK_VER: 480.0.0
permissions:
pull-requests: write
jobs:
infrastructure-deployment:
name: Infrastructure Deployment
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
pull-requests: write
steps:
# Checkout the repository code
- name: Code checkout
id: code_checkout
uses: actions/checkout@v2

# Scan the repo for any sensitive information like secrets etc
- name: Secret Scanning
uses: trufflesecurity/trufflehog@main
with:
path: ./ # Code repository path
base: main # Start scanning from here (usually main branch).
head: HEAD # Scan commits until here (usually dev branch).

# Static code analysis using aqua security's tfsec
- name: Run tfsec scan
id: static_code_analysis
uses: aquasecurity/tfsec-action@v1.0.3
with:
working_directory: ${{ env.TERRAFORM_DIR }}

# Install the latest version of Google Cloud SDK
- id: cloud_sdk_installation
name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
with:
version: ${{ env.CLOUDSDK_VER }}

# Setup the authentication for the Google Cloud using WIF
- id: gcp_auth
name: Authenticate to GCP
uses: google-github-actions/auth@v0.3.1
with:
create_credentials_file: 'true'
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER_ID }}
service_account: ${{ secrets.SERVICE_ACCOUNT }}

# Install the specified version of Terraform CLI
- id: tf_installation
name: Terraform Installation
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VER }}

# Checks that Terraform configuration files adhere to a canonical format
- name: Terraform fmt
id: tf_fmt
run: terraform fmt -check
continue-on-error: true

# Initialize the Terraform working directory
- name: Terraform Init
id: tf_init
run: terraform init

# Validate the terraform configuration files
- name: Terraform Validate
id: tf_validate
run: terraform validate -no-color

# Generates an execution plan for Terraform
- name: Terraform Plan
id: tf_plan
run: terraform plan -no-color
continue-on-error: true

# Comments the terraform plan output on pull request
- id: comment_output
name: Comment Terraform Plan Output
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>

\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`

</details>

#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`

<details><summary>Show Plan</summary>

\`\`\`\n
${process.env.PLAN}
\`\`\`

</details>

*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})

# Executes the apply operation to deploy the actual infrastructure
- name: Terraform Apply
id: tf_apply
if: github.ref == 'refs/heads/"master"' && github.event_name == 'push'
run: terraform apply -auto-approve

- name: Notify success
if: success() # this step runs only if the previous steps succeeded.
run: echo "[SUCCESS] The build is successful without any errors."

- name: Notify failure
if: failure() # this step runs only if any of the previous steps failed.
run: |
echo "[FAILED] This job has been failed due to earlier errors."
echo "An eamil notification can be setup later sometime."
File renamed without changes.
Loading