Hashicorp Vault - Getting Started with Terraform

by
Jeremy Canfield |
Updated: July 18 2024
| Hashicorp Vault articles
This assumes you have installed Terraform, as described at https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started.
Let's say you have the following files in the /usr/local/terraform/hashicorp_vault directory on your Terraform server.
├── provider.tf
├── required_providers.tf
├── token.txt
├── vault_approle_auth_backend_role.tf
required_providers.tf will almost always have this.
terraform {
required_providers {
vault = {
source = "hashicorp/vault"
}
}
}
And let's say provider.tf has the following. In this example, the token in token.txt will be used to authenticate to Hashicorp Vault.
provider "vault" {
address = "https://vault.example.net:8200"
auth_login_token_file {
filename = "token.txt"
}
}
And let's say vault_approle_auth_backend_role.tf has the following.
data "vault_approle_auth_backend_role_id" "role" {
backend = "my-approle-backend"
role_name = "my-role"
}
output "role-id" {
value = data.vault_approle_auth_backend_role_id.role.role_id
}
Then use terraform init to initialize the Vault provider.
terraform init
And use terraform plan to see if you are able to authenticate to Hashicorp Vault using the token in token.txt.
terraform plan
Did you find this article helpful?
If so, consider buying me a coffee over at