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

feat(workflows): Schedule release workflow, use terraform-modules-vmseries-ci-workflows, execute Terratest for examples (plan for PR, deploy for release workflow) #328

Merged
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
984d084
New actions with OIDC, workflows for PR and Release
sebastianczech Jun 26, 2023
a4250df
Move tests/internal/testskeleton and tests/internal/helpers into go d…
sebastianczech Jun 26, 2023
6bfaca5
Add makefile script used in examples and moules
sebastianczech Jun 26, 2023
e662f4e
Add Makefile for every example and module
sebastianczech Jun 26, 2023
2707d08
Use fixed CI workflow
sebastianczech Jun 26, 2023
b8a0c43
Temporary define AWS_REGION and env for GitHub action
sebastianczech Jun 26, 2023
b69733f
Temporary define AWS_REGION and env for GitHub action
sebastianczech Jun 26, 2023
925cd1a
Remove IDEMPOTENCE from .github/actions/plan_apply/action.yml
sebastianczech Jun 26, 2023
75b4c53
Remove UUID
sebastianczech Jun 26, 2023
cd2aa84
Change version of erraform-modules-vmseries-ci-workflows in .github/w…
sebastianczech Jun 26, 2023
28c30d2
Change version of erraform-modules-vmseries-ci-workflows in .github/w…
sebastianczech Jun 26, 2023
c0df66a
Add TF 1.5 to .github/workflows/pr_ci.yml
sebastianczech Jun 26, 2023
49ca0c4
Use TF version 1.2 1.3 1.4 1.5 for Release CI
sebastianczech Jun 27, 2023
20916e7
Simplify GitHub action to have only 1 step to test infra, without pla…
sebastianczech Jun 27, 2023
1f6ae4d
Simplify GitHub action to have only 1 step to test infra, without pla…
sebastianczech Jun 27, 2023
15e1471
Do apply for release CI workflow
sebastianczech Jun 27, 2023
91a65b4
Fix standalone vmseries tests and change name of tests for all examples
sebastianczech Jun 28, 2023
727b92a
Change EBS KMS key alias for standalone VM-Series example
sebastianczech Jun 28, 2023
bc47e0a
Fix issues found in examples while running tests
sebastianczech Jun 28, 2023
e19dca4
Use aws-actions/configure-aws-credentials@v2
sebastianczech Jun 28, 2023
7354f63
Merge changes from main after removing legacy examples
sebastianczech Jun 29, 2023
26c3558
Deploy examples in the cloud only with latest Terraform version
sebastianczech Jun 29, 2023
c43fcfe
Use terraform-modules-vmseries-ci-workflows in version v1.2.0 as ther…
sebastianczech Jun 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/pr_ci.yml@v1
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/release_ci.yml@v1
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:
sebastianczech marked this conversation as resolved.
Show resolved Hide resolved
@../../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