Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions authentication/policy.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "vault_policy" "policies" {
name = split(".", each.value)[0]
policy = file("${path.module}/templates/policy/${each.value}")
for_each = fileset("${path.module}/templates/policy/", "*.hcl")
}
2 changes: 1 addition & 1 deletion authentication/templates/default_template.tftpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"policies": [%{ for i,policy in policies ~}"${policy}"%{if i < length(policies) -1 }, %{ endif }%{~ endfor ~}],
"password": "password"
"password": "${password}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,11 @@ path "kv-v2/*"
path "sys/health"
{
capabilities = ["read", "sudo"]
}
}

# Update Certs
path "certs_int/*"
{
capabilities = ["create", "read", "update", "delete", "list", "sudo"]
}

7 changes: 7 additions & 0 deletions authentication/templates/users.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"username": "viewer",
"password": "password123",
"policies": ["view_policy"]
}
]
27 changes: 8 additions & 19 deletions authentication/userpass.tf
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
locals {
users = jsondecode(file("${path.module}/templates/users.json"))
}

resource "vault_auth_backend" "userpass" {
type = "userpass"
path = var.path
description = "Main userpass authentication"
}

resource "vault_generic_endpoint" "devops_user" {
resource "vault_generic_endpoint" "users" {
for_each = { for user in local.users : user.username => user }
Copy link

Copilot AI Jun 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the usernames in the users JSON are unique to prevent key collisions in the for_each mapping.

Suggested change
for_each = { for user in local.users : user.username => user }
for_each = local.unique_usernames

Copilot uses AI. Check for mistakes.
depends_on = [vault_auth_backend.userpass]
path = "auth/userpass/users/devops_user"
path = "auth/userpass/users/${each.value.username}"
ignore_absent_fields = true

data_json = templatefile("${path.module}/templates/default_template.tftpl", { policies = sort(["default", "admin_policy"]) })
data_json = templatefile("${path.module}/templates/default_template.tftpl", { policies = sort(each.value.policies), password = each.value.password })
}

resource "vault_generic_endpoint" "root_user" {
depends_on = [vault_auth_backend.userpass]
path = "auth/userpass/users/root"
ignore_absent_fields = true

data_json = templatefile("${path.module}/templates/default_template.tftpl", { policies = sort(["default", "root_policy"]) })
}

resource "vault_generic_endpoint" "view_user" {
depends_on = [vault_auth_backend.userpass]
path = "auth/userpass/users/viewer"
ignore_absent_fields = true

data_json = templatefile("${path.module}/templates/default_template.tftpl", { policies = sort(["default", "view_policy"]) })
}
4 changes: 0 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
module "policy" {
source = "./policy"
}

module "authentication" {
source = "./authentication"
path = "userpass"
Expand Down
5 changes: 0 additions & 5 deletions policy/main.tf

This file was deleted.

Loading