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
15 changes: 11 additions & 4 deletions vault-backed/aws/aws.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ resource "aws_iam_access_key" "secrets_engine_credentials" {
}


# Provides an IAM policy attached to a user. In this case, allowing the secrets_engine user to assume other roles via STS
# Provides an IAM policy attached to a user. In this case, allowing the secrets_engine user rotate its own access key
#
# https://developer.hashicorp.com/vault/api-docs/secret/aws#rotate-root-iam-credentials
#
# Note that if the credentials are rotated, there will be drift in this Terraform configuration
#
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_user_policy
resource "aws_iam_user_policy" "vault_secrets_engine_generate_credentials" {
Expand All @@ -92,11 +96,14 @@ resource "aws_iam_user_policy" "vault_secrets_engine_generate_credentials" {
Statement = [
{
Action = [
"sts:AssumeRole",
"iam:GetUser",
"iam:CreateAccessKey",
"iam:DeleteAccessKey",
"iam:ListAccessKeys"
]
Effect = "Allow"
Resource = "${aws_iam_role.tfc_role.arn}"
Resource = aws_iam_user.secrets_engine.arn
},
]
})
}
}
4 changes: 2 additions & 2 deletions vault-backed/aws/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ variable "tfc_workspace_name" {

variable "vault_url" {
type = string
description = "The URL of the Vault instance you'd like to use with Terraform Cloud"
description = "The URL of the Vault instance you'd like to use with Terraform Cloud."
}

variable "jwt_backend_path" {
Expand All @@ -56,4 +56,4 @@ variable "tfc_vault_audience" {
type = string
default = "vault.workload.identity"
description = "The audience value to use in run identity tokens"
}
}
7 changes: 5 additions & 2 deletions vault-backed/aws/vault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ provider "vault" {
#
# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/jwt_auth_backend
resource "vault_jwt_auth_backend" "tfc_jwt" {
namespace = var.vault_namespace
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this a lot more than pulling the namespace from the provider 👍 Thanks!

path = var.jwt_backend_path
type = "jwt"
oidc_discovery_url = "https://${var.tfc_hostname}"
Expand Down Expand Up @@ -43,7 +44,8 @@ resource "vault_jwt_auth_backend_role" "tfc_role" {
#
# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/policy
resource "vault_policy" "tfc_policy" {
name = "tfc-policy"
namespace = var.vault_namespace
name = "tfc-policy"

policy = <<EOT
# Allow tokens to query themselves
Expand Down Expand Up @@ -88,9 +90,10 @@ resource "vault_aws_secret_backend" "aws_secret_backend" {
#
# https://registry.terraform.io/providers/hashicorp/vault/latest/docs/resources/aws_secret_backend_role
resource "vault_aws_secret_backend_role" "aws_secret_backend_role" {
namespace = var.vault_namespace
backend = vault_aws_secret_backend.aws_secret_backend.path
name = var.aws_secret_backend_role_name
credential_type = "assumed_role"

role_arns = [aws_iam_role.tfc_role.arn]
}
}