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 7 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
87 changes: 87 additions & 0 deletions .github/actions/plan_apply/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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: set UUID and provider values value
id: uuid
shell: bash
env:
TPATH: ${{ inputs.path }}
run: |
echo "uuid=$(uuidgen | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
sebastianczech marked this conversation as resolved.
Show resolved Hide resolved

- name: configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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: plan infrastructure
id: plan
if: inputs.do_apply == 'false'
sebastianczech marked this conversation as resolved.
Show resolved Hide resolved
env:
TPATH: ${{ inputs.path }}
UUID: ${{ steps.uuid.outputs.uuid }}
shell: bash
run: |
echo "::group::TERRAFORM PLAN"
cd "$GITHUB_WORKSPACE/$TPATH"
DO_APPLY=0 make test
echo "::endgroup::"

- name: create infrastructure
id: apply
if: inputs.do_apply == 'true'
env:
TPATH: ${{ inputs.path }}
UUID: ${{ steps.uuid.outputs.uuid }}
shell: bash
run: |
echo "::group::TERRAFORM APPLY"
cd "$GITHUB_WORKSPACE/$TPATH"
DO_APPLY=1 make test
echo "::endgroup::"

- name: run destroy
FoSix marked this conversation as resolved.
Show resolved Hide resolved
id: destroy
if: always() && inputs.do_apply == 'true'
env:
TPATH: ${{ inputs.path }}
UUID: ${{ steps.uuid.outputs.uuid }}
IDEMPOTENCE: ${{ inputs.idempotence }}
sebastianczech marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
run: |
cd "$GITHUB_WORKSPACE/$TPATH"
echo "::group::TERRAFORM DESTROY"
make destroy
echo "::endgroup::"
107 changes: 0 additions & 107 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]
sebastianczech marked this conversation as resolved.
Show resolved Hide resolved
if: github.actor != 'dependabot[bot]'
secrets: inherit
with:
cloud: aws
tf_version: 1.2 1.3 1.4
sebastianczech marked this conversation as resolved.
Show resolved Hide resolved
do_apply: false
fail_fast: false
apply_timeout: 120
24 changes: 0 additions & 24 deletions .github/workflows/release.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/release_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
tf_version: 1.4 # Do we need on release deploy every example using Terraform in version 1.2 1.3 1.4 ?
FoSix marked this conversation as resolved.
Show resolved Hide resolved
do_apply: false # Temporary we don't deploy examples by setting this on `true`
fail_fast: false
apply_timeout: 120
25 changes: 25 additions & 0 deletions examples/centralized_design/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
init:
@../../makefile.sh init

prep_vars: check_uuid
@if [ -d files ] && [ ! -f files/config/init-cfg.txt ]; then cp files/config/init-cfg.sample.txt files/config/init-cfg.txt; fi

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

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

destroy:
sebastianczech marked this conversation as resolved.
Show resolved Hide resolved
@../../makefile.sh destroy

check_uuid:
ifndef UUID
$(info Missing UUID, generate one for yourself using command:)
$(info export UUID=$$(uuidgen | tr '[:upper:]' '[:lower:]'))
$(error )
else
RG := $(shell echo ${UUID} | cut -d '-' -f 1,5)
PREFIX := ghci$(shell echo ${UUID} | cut -d '-' -f 2)-
STORAGE := $(shell echo ${UUID} | cut -d '-' -f 2,3,4 | tr -d '-')
endif
sebastianczech marked this conversation as resolved.
Show resolved Hide resolved
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 1, then Terraform apply is used, in other case only Terraform plan
if os.Getenv("DO_APPLY") == "1" {
// 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")
}
}
Loading