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

Refactoring #91

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
97 changes: 89 additions & 8 deletions .github/workflows/terraform-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,71 @@ on:

env:
TF_WORKSPACE: gha
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}

jobs:
terraform:
name: 'Terraform Validate and plan'
test_storagerg_module:
name: 'Test and deploy 01_Storage_rg module with Terraform Validate and plan'
Copy link
Member

@msrn msrn Jan 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workflow now tests and deploys the storagerg module to Azure. Deployhono -module plan would fail because that module needs outputs of storagerg -module shares. Because of this storage_rg needs to be deployed.

runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'safe-to-test')

env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}

# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: ./01_storage_rg
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}

# Install the latest version of Terraform CLI. Enable wrapper for output
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: true

# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
id: init
run: terraform init

# Validate config files
- name: Terraform Validate
id: validate
run: terraform validate -no-color

# Checks that all Terraform configuration files adhere to a canonical format
- name: Terraform Format
id: fmt
run: terraform fmt -recursive -check -list=true
#continue-on-error: true

# Generates an execution plan for Terraform
- name: Terraform Plan
id: plan
run: terraform plan
#continue-on-error: true
- name: Terraform Apply
id: apply
run: terraform apply -auto-approve

test_deployhono_module:
name: 'Test 02_deploy_hono module with Terraform Validate and plan'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test deployHono module with validate and plan.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this workflow here
msrn#5
You can see output of checks here
https://github.com/msrn/smad-deploy-azure/actions/runs/1663019863

needs: test_storagerg_module
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'safe-to-test')

# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: ./02_deployHono
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
Expand Down Expand Up @@ -61,6 +108,40 @@ jobs:
id: plan
run: terraform plan
#continue-on-error: true

destroy_storagerg_module:
name: 'Destroy 01_Storage_rg module from Azure subscription'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destroy previously made storagerg

needs: test_deployhono_module
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'safe-to-test')

# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
working-directory: ./01_storage_rg
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}

# Install the latest version of Terraform CLI. Enable wrapper for output
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: true

# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
id: init
run: terraform init

- name: Terraform Destroy
id: destroy
run: terraform destroy -auto-approve


# TODO
# Make a better output
Expand Down