From cbb9750a846743cf07bdcf9f328dbaf0e6c8d8f9 Mon Sep 17 00:00:00 2001 From: "sanket.nadkarni" Date: Mon, 4 Mar 2024 00:10:57 +0530 Subject: [PATCH] feat: add tfenv configs and installation steps to readme, add required_version config to provider.tf, update setup_keys.sh to pick up correct auth creds --- database-grants/terraform/README.md | 20 +++++++++++++++++++- database-grants/terraform/dev/provider.tf | 3 +++ database-grants/terraform/dev/setup_keys.sh | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/database-grants/terraform/README.md b/database-grants/terraform/README.md index e0975e9..4623c77 100644 --- a/database-grants/terraform/README.md +++ b/database-grants/terraform/README.md @@ -1,6 +1,11 @@ # Prerequisites -- Terraform 1.4.6 , please stick to this version for now, tested 1.6.x, it brings issue with the Dititalocean storage as backend +- Ensure you have `tfenv` installed in your system. https://github.com/tfutils/tfenv + +- The terraform configuration in this directory requires to have `terraform` binary version to be minimum 1.4.6 Ref: https://developer.hashicorp.com/terraform/tutorials/configuration-language/versions#review-example-configuration + + + # How to set up terraform @@ -22,6 +27,19 @@ source setup_keys.sh # How to run terraform +Use correct version: +```bash +tfenv use min-required +``` +OR +```bash +tfenv use # this will configure the correct version from .terraform-version file +``` + +```bash +terraform version # check if the version matches with the required_version in provider.tf +``` + Init: ```bash diff --git a/database-grants/terraform/dev/provider.tf b/database-grants/terraform/dev/provider.tf index 4dacebd..8ebb761 100644 --- a/database-grants/terraform/dev/provider.tf +++ b/database-grants/terraform/dev/provider.tf @@ -7,6 +7,9 @@ variable "password" { } terraform { + # Ref: https://developer.hashicorp.com/terraform/tutorials/configuration-language/versions#review-example-configuration + required_version = "~> 1.4.6" + required_providers { postgresql = { source = "cyrilgdn/postgresql" diff --git a/database-grants/terraform/dev/setup_keys.sh b/database-grants/terraform/dev/setup_keys.sh index aebb9d4..0e15de8 100755 --- a/database-grants/terraform/dev/setup_keys.sh +++ b/database-grants/terraform/dev/setup_keys.sh @@ -3,6 +3,9 @@ # Retrieve keys from your netrc, specified as # machine sfo2.digitaloceanspaces.com login KEY password SECRET # Source this file before running terraform commands -netrc_string=$(grep digitalocean.dev.treetracker.org ~/.netrc) + +grep_string=$(cat backend.tf | grep endpoint | awk -F'=' '{print $2}' | awk -F'/' '{print $NF}' | sed 's/"//g') + +netrc_string=$(grep ${grep_string} ~/.netrc) export AWS_ACCESS_KEY_ID=$(echo $netrc_string | awk '{print $4}') export AWS_SECRET_ACCESS_KEY=$(echo $netrc_string | awk '{print $6}')