This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workflows): Schedule release workflow, use terraform-modules-vms…
…eries-ci-workflows, execute Terratest for examples (plan for PR, deploy for release workflow) (#328)
- Loading branch information
1 parent
c8b55e0
commit f363172
Showing
58 changed files
with
1,190 additions
and
199 deletions.
There are no files selected for viewing
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
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::" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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 |
This file was deleted.
Oops, something went wrong.
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
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 |
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
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 |
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
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") | ||
} | ||
} |
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
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 |
Oops, something went wrong.