Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Johnc/end to end tests parallel #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 11 additions & 21 deletions .github/workflows/ci-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,23 @@ jobs:
with:
terraform_version: 1.9.3
terraform_wrapper: false

- name: Terraform Init
run: |
BRANCH_NAME="${{ github.head_ref != '' && github.head_ref || github.ref }}"
TF_STATE_KEY="${BRANCH_NAME//\//_}.tfstate"

terraform init -backend=true -backend-config="resource_group_name=$TF_STATE_RESOURCE_GROUP" -backend-config="storage_account_name=$TF_STATE_STORAGE_ACCOUNT" -backend-config="container_name=github-actions" -backend-config="key=$TF_STATE_KEY"
working-directory: infrastructure
env:
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
TF_STATE_RESOURCE_GROUP: ${{ secrets.TF_STATE_RESOURCE_GROUP }}
TF_STATE_STORAGE_ACCOUNT: ${{ secrets.TF_STATE_STORAGE_ACCOUNT }}

- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.21

- name: Terraform Validate
run: terraform validate
run: |
terraform init -backend=false
terraform validate
working-directory: infrastructure

- name: Run Integration Tests
run: |
terraform init -backend=false
terraform test
working-directory: tests/integration-tests

- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.21

- name: Run End to End Tests
run: |
Expand All @@ -67,6 +54,9 @@ jobs:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
TF_STATE_RESOURCE_GROUP: ${{ secrets.TF_STATE_RESOURCE_GROUP }}
TF_STATE_STORAGE_ACCOUNT: ${{ secrets.TF_STATE_STORAGE_ACCOUNT }}
TF_STATE_STORAGE_CONTAINER: ${{ secrets.TF_STATE_STORAGE_CONTAINER }}

static-code-analysis:
name: Static Code Analysis
Expand Down
15 changes: 14 additions & 1 deletion tests/end-to-end-tests/basic_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e_tests

import (
"fmt"
"os"
"testing"

"github.com/gruntwork-io/terratest/modules/random"
Expand All @@ -14,7 +15,12 @@ import (
* TestBasicDeployment tests a basic deployment of the infrastructure using Terraform using the TF output variables.
*/
func TestBasicDeployment(t *testing.T) {
terraformFolder := "../../infrastructure"
t.Parallel()

terraformFolder := test_structure.CopyTerraformFolderToTemp(t, "../../infrastructure", "")
terraformStateResourceGroup := os.Getenv("TF_STATE_RESOURCE_GROUP")
terraformStateStorageAccount := os.Getenv("TF_STATE_STORAGE_ACCOUNT")
terraformStateContainer := os.Getenv("TF_STATE_STORAGE_CONTAINER")

vaultName := random.UniqueId()
vaultLocation := "uksouth"
Expand All @@ -33,6 +39,13 @@ func TestBasicDeployment(t *testing.T) {
"vault_location": vaultLocation,
"vault_redundancy": vaultRedundancy,
},

BackendConfig: map[string]interface{}{
"resource_group_name": terraformStateResourceGroup,
"storage_account_name": terraformStateStorageAccount,
"container_name": terraformStateContainer,
"key": vaultName + ".tfstate",
},
}

// Save options for later test stages
Expand Down
14 changes: 13 additions & 1 deletion tests/end-to-end-tests/full_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import (
* TestFullDeployment tests the full deployment of the infrastructure using Terraform.
*/
func TestFullDeployment(t *testing.T) {
terraformFolder := "../../infrastructure"
t.Parallel()

terraformFolder := test_structure.CopyTerraformFolderToTemp(t, "../../infrastructure", "")
terraformStateResourceGroup := os.Getenv("TF_STATE_RESOURCE_GROUP")
terraformStateStorageAccount := os.Getenv("TF_STATE_STORAGE_ACCOUNT")
terraformStateContainer := os.Getenv("TF_STATE_STORAGE_CONTAINER")

vaultName := random.UniqueId()
vaultLocation := "uksouth"
Expand All @@ -38,6 +43,13 @@ func TestFullDeployment(t *testing.T) {
"vault_location": vaultLocation,
"vault_redundancy": vaultRedundancy,
},

BackendConfig: map[string]interface{}{
"resource_group_name": terraformStateResourceGroup,
"storage_account_name": terraformStateStorageAccount,
"container_name": terraformStateContainer,
"key": vaultName + ".tfstate",
},
}

// Save options for later test stages
Expand Down
Loading