Commit 7d239b65 authored by xuwang's avatar xuwang
Browse files

terraform: keep TF_CLI_CONFIG_FILE defined but unexport it when online



The bare `export` exports every make variable, so TF_CLI_CONFIG_FILE
leaked into Terraform's environment on normal online runs. Terraform then
tried to open .tf_build/.terraformrc -- a file only written when
TF_OFFLINE is set (see tf-init) -- and printed a spurious "Unable to open
CLI configuration file" warning.

The variable must stay *defined* because the tf-init recipe references it
in a redirect (`printf ... > ${TF_CLI_CONFIG_FILE}`); an empty value makes
bash fail with "syntax error near unexpected token ';'" since it parses the
whole if/then/fi block before the guard runs. So define it unconditionally,
export it only in offline mode, and unexport it otherwise to override the
blanket export.

Changelog: fixed
Co-Authored-By: default avatarClaude Opus 4.8 <noreply@anthropic.com>
parent 88df2ade
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -51,11 +51,19 @@ TF_INIT_RETRY_ON ?= 5[0-9][0-9] |429|Bad Gateway|Service Unavailable|Gateway Tim
# When TF_OFFLINE is set, tf-init writes a CLI config pointing Terraform at the
# mirror and excluding direct registry installs.
TF_PROVIDER_MIRROR_DIR ?= ${HOME}/.terraform.d/plugin-mirror
TF_CLI_CONFIG_FILE ?= ${CURDIR}/${TF_BUILD_DIR}/.terraformrc
# Platforms to fetch when populating the mirror (CI runners are usually linux).
TF_MIRROR_PLATFORMS ?= darwin_amd64 linux_amd64
# Always define this (the tf-init recipe references it in a redirect, so an empty
# value would be a shell syntax error), but only export it to Terraform in
# offline mode. The bare `export` below would otherwise leak it on normal runs,
# pointing Terraform at a .terraformrc that's only written when TF_OFFLINE is set
# (see tf-init) -- producing a spurious "Unable to open CLI configuration file"
# warning. unexport overrides the blanket export for the online case.
TF_CLI_CONFIG_FILE ?= ${CURDIR}/${TF_BUILD_DIR}/.terraformrc
ifdef TF_OFFLINE
export TF_CLI_CONFIG_FILE
else
unexport TF_CLI_CONFIG_FILE
endif

# set the default tf backend