try vault postgres secret engine
This commit is contained in:
6
iac/backend.tf
Normal file
6
iac/backend.tf
Normal file
@@ -0,0 +1,6 @@
|
||||
terraform {
|
||||
backend "gcs" {
|
||||
bucket = "arcodange-tf"
|
||||
prefix = "webapp/main"
|
||||
}
|
||||
}
|
||||
58
iac/main.tf
Normal file
58
iac/main.tf
Normal file
@@ -0,0 +1,58 @@
|
||||
data "vault_auth_backend" "kubernetes" {
|
||||
path = "kubernetes"
|
||||
}
|
||||
variable "name" {
|
||||
type = string
|
||||
default = "webapp"
|
||||
}
|
||||
variable "database" {
|
||||
type = string
|
||||
nullable = true
|
||||
default = null
|
||||
}
|
||||
locals {
|
||||
name = lower(var.name)
|
||||
database = var.database == null ? local.name : var.database
|
||||
|
||||
vault_mount_postgres = { path = "postgres" }
|
||||
vault_mount_kvv2 = { path = "kvv2" }
|
||||
}
|
||||
|
||||
resource "vault_database_secret_backend_role" "role" {
|
||||
backend = local.vault_mount_postgres.path
|
||||
name = "${local.name}"
|
||||
db_name = "postgres"
|
||||
creation_statements = [
|
||||
"CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';",
|
||||
"GRANT ${local.name}_role TO \"{{name}}\";",
|
||||
]
|
||||
revocation_statements = [
|
||||
"REVOKE ALL ON DATABASE ${local.database} FROM \"{{name}}\";" # should we drop the role ?
|
||||
]
|
||||
renew_statements=[]
|
||||
rollback_statements=[]
|
||||
}
|
||||
|
||||
resource "vault_kv_secret_v2" "webapp_config" {
|
||||
mount = local.vault_mount_kvv2.path
|
||||
name = "webapp/config"
|
||||
cas = 1
|
||||
# delete_all_versions = true
|
||||
data_json = jsonencode(
|
||||
{
|
||||
zip = "zap",
|
||||
foo = "bar"
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
resource "vault_kubernetes_auth_backend_role" "role" {
|
||||
backend = data.vault_auth_backend.kubernetes.path
|
||||
role_name = local.name
|
||||
bound_service_account_names = [local.name]
|
||||
bound_service_account_namespaces = [local.name]
|
||||
token_ttl = 3600
|
||||
token_policies = ["default", local.name]
|
||||
audience = "vault"
|
||||
alias_name_source = "serviceaccount_name"
|
||||
}
|
||||
16
iac/providers.tf
Normal file
16
iac/providers.tf
Normal file
@@ -0,0 +1,16 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
vault = {
|
||||
source = "vault"
|
||||
version = "4.4.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider vault {
|
||||
address = "https://vault.arcodange.duckdns.org"
|
||||
auth_login_jwt { # TERRAFORM_VAULT_AUTH_JWT environment variable
|
||||
mount = "gitea_jwt"
|
||||
role = "gitea_cicd_webapp"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user