From cbb9750a846743cf07bdcf9f328dbaf0e6c8d8f9 Mon Sep 17 00:00:00 2001 From: "sanket.nadkarni" Date: Mon, 4 Mar 2024 00:10:57 +0530 Subject: [PATCH 1/3] 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}') From c76b93bfd41a0ce5956fe474d10c7253bcb6b27a Mon Sep 17 00:00:00 2001 From: "sanket.nadkarni" Date: Mon, 4 Mar 2024 00:23:36 +0530 Subject: [PATCH 2/3] fix: tf format and minor readme updates --- database-grants/terraform/README.md | 4 +++- database-grants/terraform/dev/provider.tf | 2 +- database-grants/terraform/prod/backend.tf | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/database-grants/terraform/README.md b/database-grants/terraform/README.md index 4623c77..6d36d50 100644 --- a/database-grants/terraform/README.md +++ b/database-grants/terraform/README.md @@ -31,8 +31,10 @@ Use correct version: ```bash tfenv use min-required ``` -OR +OR if you configure `.terraform-version` + ```bash +echo "1.4.6" > .terraform-version tfenv use # this will configure the correct version from .terraform-version file ``` diff --git a/database-grants/terraform/dev/provider.tf b/database-grants/terraform/dev/provider.tf index 8ebb761..3ddbcc6 100644 --- a/database-grants/terraform/dev/provider.tf +++ b/database-grants/terraform/dev/provider.tf @@ -8,7 +8,7 @@ variable "password" { terraform { # Ref: https://developer.hashicorp.com/terraform/tutorials/configuration-language/versions#review-example-configuration - required_version = "~> 1.4.6" + required_version = "~> 1.4.6" required_providers { postgresql = { diff --git a/database-grants/terraform/prod/backend.tf b/database-grants/terraform/prod/backend.tf index 2bc7a4d..8f4bf5e 100644 --- a/database-grants/terraform/prod/backend.tf +++ b/database-grants/terraform/prod/backend.tf @@ -11,6 +11,6 @@ terraform { skip_credentials_validation = true # skip_get_ec2_platforms = true skip_requesting_account_id = true - skip_metadata_api_check = true + skip_metadata_api_check = true } } From 84c0fb150b04196d9c22159794125dbd7890e24c Mon Sep 17 00:00:00 2001 From: "sanket.nadkarni" Date: Wed, 6 Mar 2024 22:34:21 +0530 Subject: [PATCH 3/3] fix: revert the script to previous commit --- database-grants/terraform/dev/setup_keys.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/database-grants/terraform/dev/setup_keys.sh b/database-grants/terraform/dev/setup_keys.sh index 0e15de8..aebb9d4 100755 --- a/database-grants/terraform/dev/setup_keys.sh +++ b/database-grants/terraform/dev/setup_keys.sh @@ -3,9 +3,6 @@ # Retrieve keys from your netrc, specified as # machine sfo2.digitaloceanspaces.com login KEY password SECRET # Source this file before running terraform commands - -grep_string=$(cat backend.tf | grep endpoint | awk -F'=' '{print $2}' | awk -F'/' '{print $NF}' | sed 's/"//g') - -netrc_string=$(grep ${grep_string} ~/.netrc) +netrc_string=$(grep digitalocean.dev.treetracker.org ~/.netrc) export AWS_ACCESS_KEY_ID=$(echo $netrc_string | awk '{print $4}') export AWS_SECRET_ACCESS_KEY=$(echo $netrc_string | awk '{print $6}')