Skip to content

Commit

Permalink
Added TF state storage container variable to tests and workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
johncollinson2001 committed Sep 20, 2024
1 parent a80bb06 commit 638eecf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
32 changes: 8 additions & 24 deletions .github/workflows/ci-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,23 @@ jobs:
with:
terraform_version: 1.9.3
terraform_wrapper: false

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


#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"

- name: Terraform Init
- name: Terraform Validate
run: |
terraform init -backend=false
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: Terraform Validate
run: terraform validate
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 @@ -72,7 +56,7 @@ jobs:
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 }}
BRANCH_NAME: ${{ github.head_ref != '' && github.head_ref || github.ref }}
TF_STATE_STORAGE_CONTAINER: ${{ secrets.TF_STATE_STORAGE_CONTAINER }}

static-code-analysis:
name: Static Code Analysis
Expand Down
3 changes: 2 additions & 1 deletion tests/end-to-end-tests/basic_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestBasicDeployment(t *testing.T) {
terraformFolder := "../../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 @@ -42,7 +43,7 @@ func TestBasicDeployment(t *testing.T) {
BackendConfig: map[string]interface{}{
"resource_group_name": terraformStateResourceGroup,
"storage_account_name": terraformStateStorageAccount,
"container_name": "tfstate",
"container_name": terraformStateContainer,
"key": vaultName + ".tfstate",
},
}
Expand Down
3 changes: 2 additions & 1 deletion tests/end-to-end-tests/full_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestFullDeployment(t *testing.T) {
terraformFolder := "../../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 @@ -46,7 +47,7 @@ func TestFullDeployment(t *testing.T) {
BackendConfig: map[string]interface{}{
"resource_group_name": terraformStateResourceGroup,
"storage_account_name": terraformStateStorageAccount,
"container_name": "tfstate",
"container_name": terraformStateContainer,
"key": vaultName + ".tfstate",
},
}
Expand Down

0 comments on commit 638eecf

Please sign in to comment.