Skip to content

Commit

Permalink
:fix terraform.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwupark committed Feb 11, 2024
1 parent 3030690 commit 7c30edc
Showing 1 changed file with 11 additions and 38 deletions.
49 changes: 11 additions & 38 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ on:
workflow_dispatch:
inputs:
# Working directory input from user.
resource:
terraform_operation:
description: "Terraform operation: plan, apply, destroy"
required: true
default: "plan"
type: choice
description: Choose the resource
options:
- name_of_dir1
- name_of_dir2
# Terraform action you want to perform
action:
description: 'Terraform Action to Perform'
type: choice
options:
- Terraform_apply
- Terraform_destroy
- plan
- apply
- destroy

jobs:
Terraform_apply:
Expand Down Expand Up @@ -82,6 +78,8 @@ jobs:
CERTIFICATE_DOMAIN: ${{secrets.CERTIFICATE_DOMAIN}}
DNS: ${{secrets.DNS}}
GATEWAY_DNS: ${{secrets.GATEWAY_DNS}}
if: "${{ github.event.inputs.terraform_operation == 'plan' }}"


- name: Terraform Validate
id: validate
Expand Down Expand Up @@ -109,34 +107,9 @@ jobs:
CERTIFICATE_DOMAIN: ${{secrets.CERTIFICATE_DOMAIN}}
DNS: ${{secrets.DNS}}
GATEWAY_DNS: ${{secrets.GATEWAY_DNS}}


Terraform_destroy:
name: "Terraform_destroy"
if: ${{ github.event.inputs.action == 'Terraform_destroy' }}
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ github.event.inputs.resource }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Terraform Init
id: init
run: terraform init
if: "${{ github.event.inputs.terraform_operation == 'apply' }}"

- name: Terraform Destroy
id: destroy
working-directory: ${{ github.event.inputs.resource }}
run: terraform destroy -auto-approve
if: "${{ github.event.inputs.terraform_operation == 'destroy' }}"

0 comments on commit 7c30edc

Please sign in to comment.