Giter VIP home page Giter VIP logo

terraform-vault-dynamic-db-demo's Introduction

HashiCorp Vault and Postgres Dynamic DB Demo

Repo that contains a shell script and Terraform code that will configure the following:

  • A shell script will launch a Postgres docker container and a HashiCorp dev vault instance with the token set to root.
  • Terraform code that will configure the dev Vault environment to create dynamic Postgres credentials using the Postgres docker container.

NOTE This is for demo purpose only.

Requirements

This has been tested under the following versions

Docker version 20.10.21, build baeda1
Terraform==1.3.7

Building the environment

In a terminal window, issue the ./start/docker_vault_start.sh. This shell script is responsible for:

  • Launch a docker container using the latest Postgres docker container.
  • Start a vault dev instance with the token set to root.

Open another terminal window and issue the following export commands:

export VAULT_ADDR=http://127.0.0.1:8200
export VAULT_TOKEN=root

In the same terminal window where you exported the variables we will use Terraform to configure Vault.

terraform init
terraform plan
terraform apply -auto-approve

Creating dynamic users

Once Vault has been configured use the following commands to interact with Vault and test the dynamic DB functionality.

Create a dynamic user: vault read db/creds/readonly

List the db users configured on the Postgres Docker container:

docker exec -i \
    postgresdb \
    psql -U pgadmin -c "SELECT usename, valuntil FROM pg_user;"

Revoke a dynamic user: vault lease revoke {{lease_id}}

The lease_id can be found in the vault read db/creds/readonly output

Key                Value
---                -----
lease_id           db/creds/readonly/wSPPN3H8uYlcmS3JkMZKG9NU
lease_duration     768h
lease_renewable    true
(username and password removed)

Shutting down the environment

Issue a terraform destroy -auto-approve to remove the Vault configuration

Issue a ctrl + c to terminate the vault instance

To find the running container issue a docker container ls | grep postgres and then docker container stop {{ container_id }}

terraform-vault-dynamic-db-demo's People

Contributors

jshively37 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.