Skip to content

Commit

Permalink
Fix tfenv -chdir usage
Browse files Browse the repository at this point in the history
* When using the `-chdir` flag with terraform, tfenv doesn't respect the
  `.terraform-version` file if the paht is absolute: tfutils/tfenv#354
* This changes the path so that it is relative
  • Loading branch information
Stretch96 committed Nov 6, 2023
1 parent 2f477b8 commit ff1a06a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions bin/aws-sso/account-init
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ do
then
WORKSPACE_EXISTS=1
fi
done < <(terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" workspace list)
done < <(terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" workspace list)

if [ "$WORKSPACE_EXISTS" == "1" ]
then
echo "==> $NEW_WORKSPACE_NAME workspace exists"
terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" workspace select "$NEW_WORKSPACE_NAME"
terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" workspace select "$NEW_WORKSPACE_NAME"
else
terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" workspace new "$NEW_WORKSPACE_NAME"
terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" workspace new "$NEW_WORKSPACE_NAME"
fi

"$APP_ROOT/bin/dalmatian" aws-sso generate-config
Expand Down
2 changes: 1 addition & 1 deletion bin/aws-sso/generate-config
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ do
"$DALMATIAN_ACCOUNT_ADMIN_ROLE_NAME" \
"$SSO_CONFIG_REGION"
fi
done < <(terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" workspace list)
done < <(terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" workspace list)
6 changes: 3 additions & 3 deletions bin/deploy/account-bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ do
]]
then
WORKSPACE_EXISTS=1
terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" workspace select "$workspace"
terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" workspace select "$workspace"
ACCOUNT_NAME=$(echo "$workspace" | cut -d'-' -f5-)
if [[ "$ACCOUNT_NAME" == "dalmatian-main" ]]; then
TF_VAR_enable_s3_tfvars=true
Expand All @@ -93,13 +93,13 @@ do
export TF_VAR_enable_s3_tfvars
export TF_VAR_tfvars_s3_tfvars_files
export AWS_PROFILE="$ACCOUNT_NAME"
terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" "${OPTIONS[@]}" \
terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" "${OPTIONS[@]}" \
-var-file="$CONFIG_TFVARS_DEFAULT_ACCOUNT_BOOTSRAP_FILE" \
-var-file="$CONFIG_TFVARS_DIR/$CONFIG_GLOBAL_ACCOUNT_BOOSTRAP_TFVARS_FILE" \
-var-file="$CONFIG_TFVARS_DIR/000-terraform.tfvars" \
-var-file="$CONFIG_TFVARS_DIR/100-$workspace.tfvars"
fi
done 9< <(terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" workspace list)
done 9< <(terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" workspace list)

if [ "$WORKSPACE_EXISTS" == "0" ]
then
Expand Down
2 changes: 1 addition & 1 deletion bin/deploy/list-accounts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ do
then
echo "$workspace"
fi
done < <(terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" workspace list)
done < <(terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" workspace list)
2 changes: 1 addition & 1 deletion bin/terraform-dependencies/get-tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ do
'. += { "\($workspace_name)": { "path": $workspace_tfvars_path, "key": $workspace_tfvars_file } }')
fi
fi
done 9< <(terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" workspace list)
done 9< <(terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" workspace list)

echo "$TFVARS_PATHS_JSON" > "$CONFIG_TFVARS_PATHS_FILE"
8 changes: 4 additions & 4 deletions bin/terraform-dependencies/initialise
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ usage() {
exit 1
}

OPTIONS=(
ACCOUNT_BOOTSTRAP_OPTIONS=(
"-backend-config=$CONFIG_ACCOUNT_BOOTSTRAP_BACKEND_VARS_FILE"
)
while getopts "ruh" opt; do
case $opt in
r)
OPTIONS+=("-reconfigure")
ACCOUNT_BOOTSTRAP_OPTIONS+=("-reconfigure")
;;
u)
OPTIONS+=("-upgrade")
ACCOUNT_BOOTSTRAP_OPTIONS+=("-upgrade")
;;
h)
usage
Expand All @@ -34,4 +34,4 @@ done

echo "==> Attempting Terraform init ..."
export AWS_PROFILE="dalmatian-main"
terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" init "${OPTIONS[@]}"
terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" init "${ACCOUNT_BOOTSTRAP_OPTIONS[@]}"
2 changes: 1 addition & 1 deletion bin/terraform-dependencies/set-tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ then
WORKSPACES+=("$workspace")
echo "$WORKSPACE_INDEX) $workspace"
fi
done < <(terraform -chdir="$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR" workspace list)
done < <(terraform -chdir="$(grealpath --relative-to="$PWD" "$TMP_ACCOUNT_BOOTSTRAP_TERRAFORM_DIR")" workspace list)

while true
do
Expand Down

0 comments on commit ff1a06a

Please sign in to comment.