diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 6c55220..90f4494 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -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' 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' + 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 @@ -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' + 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