Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
feat(workflows): Schedule release workflow, use terraform-modules-vms…
Browse files Browse the repository at this point in the history
…eries-ci-workflows, execute Terratest for examples (plan for PR, deploy for release workflow) (#328)
  • Loading branch information
sebastianczech authored Jul 4, 2023
1 parent c8b55e0 commit f363172
Show file tree
Hide file tree
Showing 58 changed files with 1,190 additions and 199 deletions.
63 changes: 63 additions & 0 deletions .github/actions/plan_apply/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: 'TF plan/apply'
description: 'Runs Terraform plan and/or apply for a specified path.'
inputs:
tf_version:
description: 'TF version used.'
required: true
path:
description: 'Path to Terraform module.'
required: true
do_apply:
description: When set to true runs also apply
type: boolean
default: false
idempotence:
description: When set to true runs plan to on already applied configuration
type: boolean
default: true

runs:
using: "composite"
steps:

- name: setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: ${{ inputs.tf_version }}
# below settings is required for Terratest (details are in https://github.com/gruntwork-io/terratest/issues/706)
terraform_wrapper: false

- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ env.ASSUME_ROLE }}
role-session-name: gh-action-role-session
aws-region: ${{ env.AWS_REGION }}
# TODO: it's temporary solution until in repository settings -> secrets and variables -> variables
# there will be defined new repository variable AWS_REGION
env:
AWS_REGION : "us-east-1"

- name: test infrastructure
id: test
env:
TPATH: ${{ inputs.path }}
DO_APPLY: ${{ inputs.do_apply }}
shell: bash
run: |
echo "::group::TERRATEST"
cd "$GITHUB_WORKSPACE/$TPATH"
DO_APPLY=$DO_APPLY make test
echo "::endgroup::"
- name: destroy
id: destroy
if: always() && inputs.do_apply == 'true'
env:
TPATH: ${{ inputs.path }}
shell: bash
run: |
cd "$GITHUB_WORKSPACE/$TPATH"
echo "::group::TERRAFORM DESTROY"
make destroy
echo "::endgroup::"
108 changes: 0 additions & 108 deletions .github/workflows/ci.yml

This file was deleted.

31 changes: 0 additions & 31 deletions .github/workflows/oidc.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/pr_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PR CI
run-name: "CI pipeline for PR - (#${{ github.event.number }}) ${{ github.event.pull_request.title }}"

permissions:
contents: read
actions: read
id-token: write

on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review
branches: ['main']

jobs:
pr_ci_wrkflw:
name: Run CI
uses: PaloAltoNetworks/terraform-modules-vmseries-ci-workflows/.github/workflows/[email protected]
if: github.actor != 'dependabot[bot]'
secrets: inherit
with:
cloud: aws
tf_version: 1.2 1.3 1.4 1.5
do_apply: false
fail_fast: false
apply_timeout: 120
23 changes: 0 additions & 23 deletions .github/workflows/release.yml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/release_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release CI
run-name: "Continous Release"

permissions:
contents: write
issues: read
id-token: write

on:
workflow_dispatch:
schedule:
- cron: '0 1 * * 4' # this means every Thursday @1am UTC

jobs:
release_wrkflw:
name: Do release
uses: PaloAltoNetworks/terraform-modules-vmseries-ci-workflows/.github/workflows/[email protected]
if: github.actor != 'dependabot[bot]'
secrets: inherit
with:
cloud: aws
max_parallel: 10
do_apply: true
fail_fast: false
apply_timeout: 120
11 changes: 11 additions & 0 deletions examples/centralized_design/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
init:
@../../makefile.sh init

validate:
@../../makefile.sh validate

test:
@../../makefile.sh test

destroy:
@../../makefile.sh destroy
47 changes: 47 additions & 0 deletions examples/centralized_design/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package centralized_design

import (
"fmt"
"math/rand"
"os"
"testing"
"time"

"github.com/PaloAltoNetworks/terraform-aws-vmseries-modules/go/testskeleton"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/terraform"
)

func TestExampleCentralizedDesign(t *testing.T) {
// prepare random prefix
source := rand.NewSource(time.Now().UnixNano())
random := rand.New(source)
number := random.Intn(1000)
namePrefix := fmt.Sprintf("terra%d-", number)

// define options for Terraform
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: ".",
VarFiles: []string{"example.tfvars"},
Vars: map[string]interface{}{
"name_prefix": namePrefix,
"ssh_key_name": "test-ssh-key",
},
Logger: logger.Default,
Lock: true,
Upgrade: true,
SetVarsAfterVarFiles: true,
})

// prepare list of items to check
assertList := []testskeleton.AssertExpression{}

// if DO_APPLY is not empty and equal true, then Terraform apply is used, in other case only Terraform plan
if os.Getenv("DO_APPLY") == "true" {
// deploy test infrastructure and verify outputs and check if there are no planned changes after deployment
testskeleton.DeployInfraCheckOutputsVerifyChanges(t, terraformOptions, assertList)
} else {
// plan test infrastructure and verify outputs
testskeleton.PlanInfraCheckErrors(t, terraformOptions, assertList, "No errors are expected")
}
}
11 changes: 11 additions & 0 deletions examples/combined_design/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
init:
@../../makefile.sh init

validate:
@../../makefile.sh validate

test:
@../../makefile.sh test

destroy:
@../../makefile.sh destroy
Loading

0 comments on commit f363172

Please sign in to comment.