
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, this assumes approle authentication has already been enabled and you have a role ID and secret ID that can be used to authenticate to Hashicorp Vault.
provider "vault" {
address = "https://vault.example.net:8200"
auth_login {
path = "approle/"
parameters = {
role_id = "b4a68549-1464-7aac-b0cd-d22954985aa8"
secret_id = "6039e2e2-6017-8db9-2e1b-dd6bd449f901"
}
}
}
Or provider.tf could have 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"
}
}
The token.txt must only be readable by the user that owns the token.txt file.
chmod 0600 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