Skip to content
Snippets Groups Projects
Commit 2a4e0a8e authored by Tiger Watson's avatar Tiger Watson
Browse files

Merge branch 'mtyaka/config-file-check' into 'master'

fix: set .terraformrc file only if it exists

See merge request https://gitlab.com/gitlab-org/terraform-images/-/merge_requests/186



Merged-by: default avatarTiger Watson <twatson@gitlab.com>
Approved-by: default avatarTiger Watson <twatson@gitlab.com>
Co-authored-by: default avatarMatjaz Gregoric <mtyaka@gmail.com>
parents a9eede43 47cd6481
No related branches found
No related tags found
No related merge requests found
...@@ -94,8 +94,12 @@ export TF_VAR_CI_PROJECT_URL="${TF_VAR_CI_PROJECT_URL:-${CI_PROJECT_URL}}" ...@@ -94,8 +94,12 @@ export TF_VAR_CI_PROJECT_URL="${TF_VAR_CI_PROJECT_URL:-${CI_PROJECT_URL}}"
# Use terraform automation mode (will remove some verbose unneeded messages) # Use terraform automation mode (will remove some verbose unneeded messages)
export TF_IN_AUTOMATION=true export TF_IN_AUTOMATION=true
DEFAULT_TF_CONFIG_PATH="$HOME/.terraformrc"
# Set a Terraform CLI Configuration File # Set a Terraform CLI Configuration File
export TF_CLI_CONFIG_FILE="${TF_CLI_CONFIG_FILE:-$HOME/.terraformrc}" if [ -z "${TF_CLI_CONFIG_FILE}" ] && [ -f "${DEFAULT_TF_CONFIG_PATH}" ]; then
export TF_CLI_CONFIG_FILE="${DEFAULT_TF_CONFIG_PATH}"
fi
terraform_authenticate_private_registry() { terraform_authenticate_private_registry() {
...@@ -116,6 +120,7 @@ terraform_authenticate_private_registry() { ...@@ -116,6 +120,7 @@ terraform_authenticate_private_registry() {
else else
# If we have a version older than 1.2.0, we use the credentials file. # If we have a version older than 1.2.0, we use the credentials file.
# This authentication method can be safely deleted when we'll remove support for Terraform 1.0 and 1.1 # This authentication method can be safely deleted when we'll remove support for Terraform 1.0 and 1.1
export TF_CLI_CONFIG_FILE="${TF_CLI_CONFIG_FILE:-$DEFAULT_TF_CONFIG_PATH}"
if [ ! -f "${TF_CLI_CONFIG_FILE}" ] && [ "${CI_SERVER_PROTOCOL}" = "https" ] && [ -n "${CI_SERVER_HOST}" ] && [ -n "${CI_SERVER_PORT}" ]; then if [ ! -f "${TF_CLI_CONFIG_FILE}" ] && [ "${CI_SERVER_PROTOCOL}" = "https" ] && [ -n "${CI_SERVER_HOST}" ] && [ -n "${CI_SERVER_PORT}" ]; then
cat << EOF > "${TF_CLI_CONFIG_FILE}" cat << EOF > "${TF_CLI_CONFIG_FILE}"
credentials "${CI_SERVER_HOST}:${CI_SERVER_PORT}" { credentials "${CI_SERVER_HOST}:${CI_SERVER_PORT}" {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment