Skip to content

Commit

Permalink
Create vault.tf
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 3, 2024
1 parent e897bee commit 22d7176
Showing 1 changed file with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
provider "vault" {
address = "https://vault.pi-network.com:8200"
}

# Create a Vault namespace for the Pi Network
resource "vault_namespace" "pi_network" {
path = "pi-network"
}

# Create a Vault policy for the Pi Network
resource "vault_policy" "pi_network" {
name = "pi-network-policy"
policy = <<EOF
path "pi-network/*" {
capabilities = ["create", "read", "update", "delete", "list"]
}
path "pi-network/secret/*" {
capabilities = ["create", "read", "update", "delete", "list"]
}
path "pi-network/auth/*" {
capabilities = ["create", "read", "update", "delete", "list"]
}
EOF
}

# Create a Vault role for the Pi Network
resource "vault_role" "pi_network" {
name = "pi-network-role"
namespace = vault_namespace.pi_network.path
policy_ids = [vault_policy.pi_network.id]
token_ttl = 3600
token_max_ttl = 86400
}

# Create a Vault secret engine for the Pi Network
resource "vault_mount" "pi_network_secret" {
path = "pi-network/secret"
type = "kv"
description = "Pi Network secret engine"
}

# Create a Vault secret for the Pi Network
resource "vault_kv_secret" "pi_network_secret" {
path = vault_mount.pi_network_secret.path
data_json = <<EOF
{
"username": "pi-network",
"password": "your_secret_password"
}
EOF
}

# Create a Vault auth backend for the Pi Network
resource "vault_auth_backend" "pi_network" {
type = "ldap"
path = "pi-network/auth"
description = "Pi Network auth backend"

config = {
url = "ldap://ldap.pi-network.com"
userdn = "cn=admin,dc=pi-network,dc=com"
password = "your_ldap_password"
}
}

# Create a Vault auth role for the Pi Network
resource "vault_auth_role" "pi_network" {
name = "pi-network-auth-role"
auth_backend = vault_auth_backend.pi_network.path
token_policies = [vault_policy.pi_network.id]
}

# Output the Vault role ID and token
output "pi_network_role_id" {
value = vault_role.pi_network.id
}

output "pi_network_token" {
value = vault_role.pi_network.token
sensitive = true
}

0 comments on commit 22d7176

Please sign in to comment.