Deploying IAC with your secrets in Terraform Vault

DAY 23 – Deploying IAC with your secrets in Terraform Vault – Day Twenty three

100 days of Cloud on GitHub – Read On iCTPro.co.nz – Read on Dev.to

What is Vault?

Securely accesses secrets , HashiCorp explains as Vault comes…


This content originally appeared on DEV Community and was authored by Anuvindh Sankaravilasam

DAY 23 - Deploying IAC with your secrets in Terraform Vault - Day Twenty three

Image tweetImage COVER

100 days of Cloud on GitHub - Read On iCTPro.co.nz - Read on Dev.to

What is Vault?

Securely accesses secrets , HashiCorp explains as Vault comes with various pluggable components called secrets engines and authentication methods allowing you to integrate with external systems. Vault issues temporary tokens to access the resources.
Image vault image

  • In the blog I will be demonstrating how to setup a vault
  • Accessing secrets from Vault to Deploy your infrastructure into a AWS environment.

Prerequisite

Install AWS CLI and Configure with IAM credentials

Image click

Install Vault

Goto this link to install Vault
I Am using a WSL Linux on windows

  • Getting GPG key
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
  • Adding HashiCorp Linux repo
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
  • install
sudo apt-get update && sudo apt-get install vault

Setup Vault Project folder

  • Lets create a project folder named Vault and cd into it

Setup Vault Server (Dev environment)

vault server -dev -dev-root-token-id="environment"

Image vault server

Note down the Vault Address, Unsealkey & Root token.

Sign into vault server

Image vault login
Enter token as "environment"

  • Select Secret & Click Create Secret.
  • Enter your IAM Programmatic access keys & Save.

Image AWS CLI

Deploying with Vault

  • Create a main.tf file and copy paste this command
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "3.58.0"
    }
  }
}

data "vault_generic_secret" "aws_creds" {
    path = "secret/aws"
}

provider "aws" {
  region  = data.vault_generic_secret.aws_creds.data["region"]
    access_key = data.vault_generic_secret.aws_creds.data["aws_access_key_id"]
    secret_key = data.vault_generic_secret.aws_creds.data["aws_secret_access_key"]
}


resource "aws_instance" "my_server" {
  ami           = "ami-059af0b76ba105e7e"
  instance_type = "t2.nano"
    tags = {
        Name = "Vault-Server"
    }
}

You have to change ami incase your region is not on ap-southeast-2

  • Initialize Terraform
terraform init
  • Plan terraform
terraform plan

You will be prompted to enter the vault url, in this case it is http://127.0.0.1:8200/

Image url vault

  • Deploy infrastructure
terraform apply -auto-approve
  • Enter url of vault when its prompted.

Image result

  • Teardown your infrastructure

if you are happy with the deployment , you can tear down the deployed resources

terraform apply -auto-approve -destroy

😀🎉Congratulations🎉 you have successfully deployed IAC with Terraform Vault

Image congratulations

✅Connect with me on Twitter
🤝🏽Connect with me on Linkedin
🧑🏼‍🤝‍🧑🏻 Read more post on dev.to or iCTPro.co.nz
💻 Connect with me on GitHub

.ltag__user__id__637154 .follow-action-button { background-color: #141D2B !important; color: #9FEF00 !important; border-color: #141D2B !important; }
anuvindhs image


This content originally appeared on DEV Community and was authored by Anuvindh Sankaravilasam


Print Share Comment Cite Upload Translate Updates
APA

Anuvindh Sankaravilasam | Sciencx (2022-03-21T02:32:34+00:00) Deploying IAC with your secrets in Terraform Vault. Retrieved from https://www.scien.cx/2022/03/21/deploying-iac-with-your-secrets-in-terraform-vault/

MLA
" » Deploying IAC with your secrets in Terraform Vault." Anuvindh Sankaravilasam | Sciencx - Monday March 21, 2022, https://www.scien.cx/2022/03/21/deploying-iac-with-your-secrets-in-terraform-vault/
HARVARD
Anuvindh Sankaravilasam | Sciencx Monday March 21, 2022 » Deploying IAC with your secrets in Terraform Vault., viewed ,<https://www.scien.cx/2022/03/21/deploying-iac-with-your-secrets-in-terraform-vault/>
VANCOUVER
Anuvindh Sankaravilasam | Sciencx - » Deploying IAC with your secrets in Terraform Vault. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/21/deploying-iac-with-your-secrets-in-terraform-vault/
CHICAGO
" » Deploying IAC with your secrets in Terraform Vault." Anuvindh Sankaravilasam | Sciencx - Accessed . https://www.scien.cx/2022/03/21/deploying-iac-with-your-secrets-in-terraform-vault/
IEEE
" » Deploying IAC with your secrets in Terraform Vault." Anuvindh Sankaravilasam | Sciencx [Online]. Available: https://www.scien.cx/2022/03/21/deploying-iac-with-your-secrets-in-terraform-vault/. [Accessed: ]
rf:citation
» Deploying IAC with your secrets in Terraform Vault | Anuvindh Sankaravilasam | Sciencx | https://www.scien.cx/2022/03/21/deploying-iac-with-your-secrets-in-terraform-vault/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.