Skip to content

Commit

Permalink
Merge pull request #1 from sumanmanna134/actions
Browse files Browse the repository at this point in the history
add github actions for terrform and destroy infra
  • Loading branch information
sumanmanna134 authored Jul 26, 2024
2 parents 6445d5b + 47dd23e commit 0d738f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/destroyinfra.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Destroy Infrastructure

on:
workflow_dispatch:

jobs:
destroy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: '1.8.3' # Replace with desired Terraform version

- name: Destroy Infrastructure
run: |
terraform init
terraform destroy --var-file="./tfvars/terraform.tfvars" -auto-approve
40 changes: 29 additions & 11 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,54 @@
# This is a basic workflow to help you get started with Actions

name: CI
name: Terraform

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
branches: ['main']
pull_request:
branches: [ "main" ]
branches: ['main']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
terraform:
# The type of runner that the job will run on
runs-on: ubuntu-latest
env:
ARM_CLIENT_ID: ${{secrets.AZURE_AD_CLIENT_ID}}
ARM_CLIENT_SECRET: ${{secrets.AZURE_AD_CLIENT_SECRET}}
ARM_SUBSCRIPTION_ID: ${{secrets.AZURE_SUBSCRIPTION_ID}}
ARM_TENANT_ID: ${{secrets.AZURE_AD_TENANT_ID}}
defaults:
run:
shell: bash

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, world!
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: '1.8.3'
- name: Terraform fmt
id: fmt
run: terraform fmt -check

# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
- name: Terraform init
id: init
run: terraform init
- name: Terraform plan
id: plan
run: terraform plan --var-file="./tfvars/terraform.tfvars" -out azinfra.tfplan -no-color
- name: Terraform apply
id: apply
if: github.ref == 'refs/heads/"main"' && github.event_name == 'push'
run: terraform apply azinfra.tfplan -auto-approve

0 comments on commit 0d738f7

Please sign in to comment.