From 1a00e23809c66f3958a5543afcb319e40077ab8c Mon Sep 17 00:00:00 2001 From: John Collinson Date: Mon, 9 Sep 2024 12:20:56 +0100 Subject: [PATCH] Added variable to specify whether to use local backend or azurerm backend. --- .github/workflows/ci-pipeline.yaml | 2 +- infrastructure/main.tf | 9 ++++++++- infrastructure/variables.tf | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-pipeline.yaml b/.github/workflows/ci-pipeline.yaml index 509dc30..704672b 100644 --- a/.github/workflows/ci-pipeline.yaml +++ b/.github/workflows/ci-pipeline.yaml @@ -35,7 +35,7 @@ jobs: }' > infrastructure/backend.tf - name: Terraform Init - run: terraform init + run: terraform init -backend-config="use_local_backend=true" working-directory: infrastructure - name: Terraform Validate diff --git a/infrastructure/main.tf b/infrastructure/main.tf index f7e0f07..bc6430a 100644 --- a/infrastructure/main.tf +++ b/infrastructure/main.tf @@ -6,7 +6,14 @@ terraform { } } - backend "azurerm" {} + backend "local" { + path = "terraform.tfstate" + condition = var.use_local_backend + } + + backend "azurerm" { + condition = !var.use_local_backend + } } provider "azurerm" { diff --git a/infrastructure/variables.tf b/infrastructure/variables.tf index ba56da9..e7f116a 100644 --- a/infrastructure/variables.tf +++ b/infrastructure/variables.tf @@ -1,3 +1,9 @@ +variable "use_local_backend" { + description = "Set to true to use the local backend instead of azurerm" + type = bool + default = false +} + variable "vault_name" { type = string default = "myvault"