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

Master #1

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
2173d2e
changes
Aug 27, 2023
7604157
demobranch
Aug 27, 2023
c1a783c
delted foder
Aug 27, 2023
daf5dba
worksflows add
Aug 27, 2023
1976234
swork
abhishektyagi9 Aug 27, 2023
929d7b8
Update detailappdeploy.yml
abhishektyagi9 Aug 27, 2023
4b77d28
Update productpagedeploy.yml
abhishektyagi9 Aug 27, 2023
ebdeb7d
Update ratingsdeploy.yml
abhishektyagi9 Aug 27, 2023
ef6a127
Update reviewdeploy.yml
abhishektyagi9 Aug 27, 2023
6e5eb8e
Update productpage.py
abhishektyagi9 Aug 27, 2023
34530d3
Merge pull request #1 from abhishektyagi9/demo
abhishektyagi9 Aug 27, 2023
bcf745f
Delete blank.yml
abhishektyagi9 Aug 27, 2023
6b4e9f4
trigger commit
Aug 27, 2023
a64506f
Update image version in K8s Deployment manifests file
Aug 27, 2023
df1a607
triggerflow
Aug 27, 2023
5a6824b
Merge branch 'master' of https://github.com/abhishektyagi9/hub-and-sp…
Aug 27, 2023
29b1432
Update image version in K8s Deployment manifests file
Aug 27, 2023
a04a439
deatilpagechange
Aug 28, 2023
f29e95f
Merge branch 'master' of https://github.com/abhishektyagi9/hub-and-sp…
Aug 28, 2023
19b4fe1
replcacount change
Aug 28, 2023
bf80225
reviepage
Aug 28, 2023
d98c937
Update image version in K8s Deployment manifests file
Aug 28, 2023
2da05f0
cc
Aug 28, 2023
a10ac05
Update image version in K8s Deployment manifests file
Aug 28, 2023
f3934d0
rating app deploy
Aug 28, 2023
66f11ab
Merge branch 'master' of https://github.com/abhishektyagi9/hub-and-sp…
Aug 28, 2023
22c5cae
Update image version in K8s Deployment manifests file
Aug 28, 2023
c8203e7
readme file
Aug 28, 2023
488feb7
Merge branch 'master' of https://github.com/abhishektyagi9/hub-and-sp…
Aug 28, 2023
825af92
Update readme.md
abhishektyagi9 Aug 28, 2023
5eb34af
Update readme.md
abhishektyagi9 Aug 28, 2023
b68817c
Update readme.md
abhishektyagi9 Aug 28, 2023
8edf94e
Update readme.md
abhishektyagi9 Aug 28, 2023
82d5b20
imgae commit
Aug 28, 2023
22a35bd
Merge branch 'master' of https://github.com/abhishektyagi9/hub-and-sp…
Aug 28, 2023
57d9375
Update readme.md
abhishektyagi9 Aug 28, 2023
ebfb1f9
Update readme.md
abhishektyagi9 Aug 28, 2023
4a40312
commit new changes
Aug 28, 2023
75643e7
Merge branch 'master' of https://github.com/abhishektyagi9/hub-and-sp…
Aug 28, 2023
564be0f
changebook gateway
Aug 28, 2023
aaa0a6f
Update readme.md
abhishektyagi9 Aug 28, 2023
4207946
Update readme.md
abhishektyagi9 Aug 28, 2023
c272cb6
images checkin
Aug 28, 2023
674cad1
Update readme.md
abhishektyagi9 Aug 28, 2023
25498db
Update readme.md
abhishektyagi9 Aug 28, 2023
dfa5678
Update readme.md
abhishektyagi9 Aug 28, 2023
99cb72c
Update readme.md
abhishektyagi9 Aug 28, 2023
47a2961
Update readme.md
abhishektyagi9 Aug 28, 2023
2d65261
Update readme.md
abhishektyagi9 Aug 28, 2023
f050925
Update readme.md
abhishektyagi9 Aug 28, 2023
460144b
Update readme.md
abhishektyagi9 Aug 28, 2023
11463a8
hubspokemodelterraform
Aug 29, 2023
f1a69ba
Update scenario1.terraform.hub.yml
abhishektyagi9 Aug 29, 2023
ce7ce2e
Update scenario1.terraform.hub.yml
abhishektyagi9 Aug 29, 2023
f20b6de
Update readme.md
abhishektyagi9 Aug 29, 2023
72387d9
Update readme.md
abhishektyagi9 Aug 29, 2023
049ba11
Update readme.md
abhishektyagi9 Aug 29, 2023
919a3b5
Update readme.md
abhishektyagi9 Aug 29, 2023
2558ee1
Update readme.md
abhishektyagi9 Aug 29, 2023
d30e603
Update README.md
abhishektyagi9 Aug 29, 2023
0e7a224
commit
Aug 29, 2023
4322a8c
Merge branch 'master' of https://github.com/abhishektyagi9/hub-and-sp…
Aug 29, 2023
8afc0ae
Update image version in K8s Deployment manifests file
Aug 29, 2023
bd99b21
book demo stage and prod folder
Aug 29, 2023
2241adb
Merge branch 'master' of https://github.com/abhishektyagi9/hub-and-sp…
Aug 29, 2023
e9bf56a
Update readme.md
abhishektyagi9 Aug 29, 2023
099ad0c
repo during demo checkin
Aug 29, 2023
8d1f75d
Merge branch 'master' of https://github.com/abhishektyagi9/hub-and-sp…
Aug 29, 2023
138f0ec
Update image version in K8s Deployment manifests file
Aug 29, 2023
58213f4
Update readme.md
abhishektyagi9 Sep 20, 2023
9aeace6
Update readme.md
abhishektyagi9 Sep 20, 2023
197013a
Update readme.md
abhishektyagi9 Sep 20, 2023
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
91 changes: 91 additions & 0 deletions .github/actions/templates/tfApply/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: 'ApplyTerraform'
description: 'Apply Terraform'

inputs:
destroy:
description: 'Destroy the infrastructure'
required: false
default: 'false'
modulePath:
description: 'Path to the Terraform module'
required: false
default: '.'
backendStateKey:
description: 'Key to the backend state file'
required: false
default: 'terraform.tfstate'
terraformVersion:
description: 'Terraform version to use'
required: false
default: '1.3.9'
backendResourceGroupName:
description: 'Resource group name for the backend state'
required: true
backendStorageAccountName:
description: 'Storage account name for the backend state'
required: true
backendStorageContainerName:
description: 'Storage container name for the backend state'
required: true
shell:
description: 'Shell to use for the action'
required: false
default: 'bash'
ARM_CLIENT_ID:
description: 'Azure client ID'
required: true
ARM_SUBSCRIPTION_ID:
description: 'Azure subscription ID'
required: true
ARM_TENANT_ID:
description: 'Azure tenant ID'
required: true


runs:
using: 'composite'
steps:
- name: Download a single artifact
id: download
uses: actions/download-artifact@v3
with:
name: ${{ github.run_id }}.tfplan
path: ${{ inputs.modulePath }}

- name: Setup Terraform
if: steps.download.outcome == 'success'
uses: hashicorp/setup-terraform@v2
with:
terraformVersion: ${{ inputs.terraformVersion }}

- name: Terraform Init
id: init
shell: ${{ inputs.shell }}
working-directory: ${{ inputs.modulePath }}
run: |
terraform init \
-backend-config="resource_group_name=${{ inputs.backendResourceGroupName }}" \
-backend-config="storage_account_name=${{ inputs.backendStorageAccountName }}" \
-backend-config="container_name=${{ inputs.backendStorageContainerName }}" \
-backend-config="key=${{ inputs.backendStateKey }}"
env:
ARM_CLIENT_ID: ${{ inputs.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ inputs.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ inputs.ARM_TENANT_ID }}
ARM_USE_OIDC: true

- name: Terraform Apply
id: apply
shell: ${{ inputs.shell }}
working-directory: ${{ inputs.modulePath }}
run: |
terraform apply \
-auto-approve \
-input=false \
-no-color \
tfplan
env:
ARM_CLIENT_ID: ${{ inputs.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ inputs.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ inputs.ARM_TENANT_ID }}
ARM_USE_OIDC: true
181 changes: 181 additions & 0 deletions .github/actions/templates/tfValidatePlan/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
name: 'ValidateAndPlanTerraform'
description: 'Validate and Plan Terraform'

inputs:
destroy:
description: 'Destroy the infrastructure'
required: false
default: 'false'
modulePath:
description: 'Path to the Terraform module'
required: false
default: '.'
tfvarPath:
description: 'Path to the Terraform variables file with respect to the modulePath'
required: false
default: 'terraform.tfvars'
backendStateKey:
description: 'Key to the backend state file'
required: false
default: 'terraform.tfstate'
terraformVersion:
description: 'Terraform version to use'
required: false
default: '1.3.9'
backendResourceGroupName:
description: 'Resource group name for the backend state'
required: true
backendStorageAccountName:
description: 'Storage account name for the backend state'
required: true
backendStorageContainerName:
description: 'Storage container name for the backend state'
required: true
shell:
description: 'Shell to use for the action'
required: false
default: 'bash'
ARM_CLIENT_ID:
description: 'Azure client ID'
required: true
ARM_SUBSCRIPTION_ID:
description: 'Azure subscription ID'
required: true
ARM_TENANT_ID:
description: 'Azure tenant ID'
required: true

runs:
using: 'composite'
steps:
- name: Terraform Init
id: init
shell: ${{ inputs.shell }}
working-directory: ${{ inputs.modulePath }}
run: |
terraform init \
-backend-config="resource_group_name=${{ inputs.backendResourceGroupName }}" \
-backend-config="storage_account_name=${{ inputs.backendStorageAccountName }}" \
-backend-config="container_name=${{ inputs.backendStorageContainerName }}" \
-backend-config="key=${{ inputs.backendStateKey }}"
env:
ARM_CLIENT_ID: ${{ inputs.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ inputs.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ inputs.ARM_TENANT_ID }}
ARM_USE_OIDC: true

- name: Terraform Validate
id: validate
shell: ${{ inputs.shell }}
working-directory: ${{ inputs.modulePath }}
run: |
terraform validate -no-color
echo stdout=$(terraform validate -no-color)

- name: tfsec
uses: aquasecurity/[email protected]
with:
tfsec_args: --soft-fail
github_token: ${{ github.token }}

- name: Terraform Plan
id: plan
shell: ${{ inputs.shell }}
working-directory: ${{ inputs.modulePath }}
continue-on-error: true
run: |
if [ "${{ github.event.inputs.destroy }}" = "true" ]; then
terraform plan \
-destroy \
-input=false \
-out=tfplan \
-no-color \
-var-file="${{ inputs.tfvarPath }}"
else
terraform plan \
-input=false \
-out=tfplan \
-no-color \
-var-file="${{ inputs.tfvarPath }}"
fi

terraform show -no-color tfplan > ${GITHUB_WORKSPACE}/plan.out
env:
ARM_CLIENT_ID: ${{ inputs.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ inputs.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ inputs.ARM_TENANT_ID }}
ARM_USE_OIDC: true

- name: 'Upload TFPlan Artifact'
if: steps.plan.outcome == 'success'
uses: actions/upload-artifact@v3
with:
name: ${{ github.run_id }}.tfplan
path: ${{ inputs.modulePath }}/tfplan
retention-days: 5

- name: Post Plan to GitHub PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request' && steps.plan.outcome == 'success'
with:
script: |
const run_url = process.env.GITHUB_SERVER_URL + '/' + process.env.GITHUB_REPOSITORY + '/actions/runs/' + process.env.GITHUB_RUN_ID
const run_link = '<a href="' + run_url + '">Actions</a>.'
const fs = require('fs')
const plan_file = fs.readFileSync('plan.out', 'utf8')
const plan = plan_file.length > 65000 ? plan_file.toString().substring(0, 65000) + " ..." : plan_file
const truncated_message = plan_file.length > 65000 ? "Output is too long and was truncated. You can read full Plan in " + run_link + "<br /><br />" : ""
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
${plan}
\`\`\`

</details>
${truncated_message}

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

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

- name: Post Plan Failure
if: github.event_name == 'pull_request' && steps.plan.outcome == 'failure'
uses: actions/github-script@v6
with:
script: |
const output = `#### Terraform Plan failed
<details><summary>Plan Error Output</summary>

\`\`\`\n
${{ steps.plan.outputs.stderr }}
\`\`\`

*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ inputs.modulePath }}\`, Workflow: \`${{ github.workflow }}\`*`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
- name: Exit if plan failed
shell: ${{ inputs.shell }}
if: steps.plan.outcome == 'failure'
run: exit 1
97 changes: 97 additions & 0 deletions .github/workflows/.template.terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: '.Template - Terraform Deployment'

on:
workflow_call:
inputs:
terraformVersion:
type: string
description: 'Terraform version'
required: true
default: '1.3.9'
modulePath:
type: string
description: 'Path to the Terraform module'
required: true
default: 'scenarios/secure-baseline-ase/terraform'
backendStateKey:
type: string
description: 'Name of the state file'
required: true
tfvarPath:
type: string
description: 'Path to the Terraform variables'
required: true
destroy:
type: boolean
description: 'Destroy resources?'
default: false

jobs:
terraform-validate-and-plan:
name: 'Validate and Plan'
timeout-minutes: 360
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@main

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ inputs.terraform_version }}

# Log into Azure via OIDC
- uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION }}

- name: 'ValidateAndPlan'
id: validate-plan
uses: ./.github/actions/templates/tfValidatePlan
with:
terraformVersion: ${{ inputs.terraformVersion }}
modulePath: ${{ inputs.modulePath }}
tfvarPath: ${{ inputs.tfvarPath }}
backendStateKey: ${{ inputs.backendStateKey }}
destroy: ${{ github.event.inputs.destroy }}
backendResourceGroupName: ${{ secrets.AZURE_TF_STATE_RESOURCE_GROUP_NAME }}
backendStorageAccountName: ${{ secrets.AZURE_TF_STATE_STORAGE_ACCOUNT_NAME }}
backendStorageContainerName: ${{ secrets.AZURE_TF_STATE_STORAGE_CONTAINER_NAME }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}

terraform-apply:
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
environment: 'Production'
name: 'Deploy'
needs: terraform-validate-and-plan
timeout-minutes: 360
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@main

# Log into Azure via OIDC
- uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION }}

- name: 'ApplyTerraform'
id: apply
uses: ./.github/actions/templates/tfApply
with:
terraformVersion: ${{ inputs.terraformVersion }}
modulePath: ${{ inputs.modulePath }}
backendStateKey: ${{ inputs.backendStateKey }}
destroy: ${{ github.event.inputs.destroy }}
backendResourceGroupName: ${{ secrets.AZURE_TF_STATE_RESOURCE_GROUP_NAME }}
backendStorageAccountName: ${{ secrets.AZURE_TF_STATE_STORAGE_ACCOUNT_NAME }}
backendStorageContainerName: ${{ secrets.AZURE_TF_STATE_STORAGE_CONTAINER_NAME }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
Loading