Terraform #43
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'Terraform' | |
on: | |
workflow_dispatch: | |
inputs: | |
choice: | |
type: choice | |
description: Do you wish to create or destroy the infrastructure? | |
options: | |
- create | |
- destroy | |
jobs: | |
terraform: | |
name: Terraform | |
runs-on: ubuntu-latest | |
environment: PROD | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: debug | |
run: | | |
echo "choice is ${{ github.event.inputs.choice }}" | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v1 | |
with: | |
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }} | |
- name: Terraform Initialize | |
run: | | |
terraform init -backend-config="access_key=${{ secrets.AWS_ACCESS_KEY_ID }}" \ | |
-backend-config="secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }}" \ | |
-backend-config="bucket=${{ secrets.BUCKET }}" \ | |
-backend-config="key=${{ secrets.KEY }}" \ | |
-backend-config="region=${{ secrets.REGION }}" \ | |
-backend-config="endpoint=${{ secrets.ENDPOINT }}" | |
- name: Terraform Plan Apply | |
if: contains(github.event.inputs.choice, 'create') | |
run: | | |
terraform plan -var "user_name=${{ secrets.USER_NAME }}" \ | |
-var "password=${{ secrets.PASSWORD }}" \ | |
-var "tenant_name=${{ secrets.TENANT_NAME }}" \ | |
-var "tenant_id=${{ secrets.TENANT_ID }}" \ | |
-var "auth_url=${{ secrets.AUTH_URL }}" \ | |
-var "public_key=${{ secrets.PUBLIC_KEY }}" \ | |
-var "remote_ip_prefix=${{ secrets.REMOTE_IP_PREFIX }}" \ | |
-var "region=${{ secrets.REGION }}" \ | |
-out tfplan | |
- name: Terraform Plan Destroy | |
if: contains(github.event.inputs.choice, 'destroy') | |
run: | | |
terraform plan -destroy -var "user_name=${{ secrets.USER_NAME }}" \ | |
-var "password=${{ secrets.PASSWORD }}" \ | |
-var "tenant_name=${{ secrets.TENANT_NAME }}" \ | |
-var "tenant_id=${{ secrets.TENANT_ID }}" \ | |
-var "auth_url=${{ secrets.AUTH_URL }}" \ | |
-var "public_key=${{ secrets.PUBLIC_KEY }}" \ | |
-var "remote_ip_prefix=${{ secrets.REMOTE_IP_PREFIX }}" \ | |
-var "region=${{ secrets.REGION }}" \ | |
-out tfplan | |
- name: Terraform Apply | |
if: contains(github.event.inputs.choice, 'create') | |
run: | | |
chmod +x ./setup.sh | |
terraform apply tfplan | |
- name: Terraform Destroy | |
if: contains(github.event.inputs.choice, 'destroy') | |
run: | | |
terraform apply -destroy tfplan |