Skip to content

Commit

Permalink
feat: add tfenv configs and installation steps to readme, add require…
Browse files Browse the repository at this point in the history
…d_version config to provider.tf, update setup_keys.sh to pick up correct auth creds
  • Loading branch information
sanketnadkarni committed Mar 3, 2024
1 parent 431e9fc commit cbb9750
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
20 changes: 19 additions & 1 deletion database-grants/terraform/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions database-grants/terraform/dev/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion database-grants/terraform/dev/setup_keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

0 comments on commit cbb9750

Please sign in to comment.