I am hosting a terraform template (module) on a git repo with the following configurations:
terraform {
required_version = ">= 1.2.4"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.13.0"
}
}
}
and
provider "azurerm" {
features{}
tenant_id = var.aad_tenant_id
subscription_id = var.azure_subscription_id
client_id = var.tfsa_user
client_secret = var.tfsa_token
}
There is a nother github repository which is using the above module, with the following code:
module "rg-test1" {
source = "github.com/org_name/tfmod_resource-group"
version = "0.0.4"
resource_group_name = "rg-test3"
location = "westeurope"
aad_tenant_id = "00000000-0000-0000-0000-000000000000"
azure_subscription_id = "00000000-0000-0000-0000-000000000000"
}
and
terraform {
backend "azurerm" {
resource_group_name = "some_group_name"
storage_account_name = "somestorageaccount"
container_name = "some-container-name"
key = "rg/rg-test1.terraform.tfstate"
}
required_version = ">= 1.2.4"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.13.0"
}
}
}
In the pipeline I export the azure login client_* variables as TF_VAR_* enrivonmental variables so the azure token for AzureAD authentication is not shared in code.
Unfortunately it seems that when doing a terraform init
it does not use the remote backend and creates a “local” .terraform* structure inside the runner used by the pipeline.
The error I get is:
Initializing the backend...
[TRACE] Meta.Backend: no config given or present on disk, so returning nil config
[TRACE] Meta.Backend: backend has not previously been initialized in this working directory
[DEBUG] New state was assigned lineage "268f5ce3-843c-1da2-ee6b-5403ae3c5642"
[TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
and at the terraform plan
stage I get asked for a resource_group_name
value again!
Please help as the same module (template) code when run locally while creating the tfmod_resource-group
template using local .tfvars for the required values works fine, it authenticates to azure and provisions the resource group with the name provided in the local .tfvar file.
I’m loosing my sanity, please help!