Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace by resource #1305

Merged

Conversation

benashz
Copy link
Contributor

@benashz benashz commented Jan 18, 2022

This is an initial POC that adds the namespace field to all Vault resources and datasources. All namespace directives are applied relative to the provider's configured namespace. This new approach allows for namespaced resources to be created without having to specify a namespace specific provider.

More to come.

Example using for_each

provider "vault" {}

variable "namespaces" {
  default = {
    "ns-2578258393756625436" = true
    "ns-2578258393756625437" = true
    "ns-2578258393756625438" = true
    "ns-2578258393756625439" = true
  }
}

resource "vault_namespace" "ns1" {
  for_each = var.namespaces
  path     = each.key
}

resource "vault_namespace" "children" {
  for_each  = var.namespaces
  namespace = vault_namespace.ns1[each.key].path
  path      = "child-${each.key}"
}

resource "vault_mount" "v1" {
  for_each  = var.namespaces
  namespace = vault_namespace.ns1[each.key].path
  path      = "secretsv1"
  type      = "kv"
  options   = {
    version = "1"
  }
}

resource "vault_generic_secret" "test" {
  for_each  = var.namespaces
  namespace = vault_mount.v1[each.key].namespace
  path      = "${vault_mount.v1[each.key].path}/test-6085250770492118070"
  data_json = jsonencode(
    {
      "zip" = "zap"
    }
  )
}
VAULT_NAMESPACE=ns-2578258393756625436 vault kv get secretsv1/test-6085250770492118070
=== Data ===
Key    Value
---    -----
zip    zap

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Relates #546

Release note for CHANGELOG:


Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'

...

@benashz benashz changed the base branch from main to VAULT-4254/namespace-poc January 18, 2022 19:26
@FalcoSuessgott
Copy link
Contributor

This is huge and would simplify my tf code base for enterprise vault a lot. Hope we can get this soon merged :)
Thanks for that POC !

@hashicorp-cla
Copy link

hashicorp-cla commented Mar 12, 2022

CLA assistant check
All committers have signed the CLA.

@benashz benashz changed the base branch from VAULT-4254/namespace-poc to main April 12, 2022 18:10
@benashz benashz changed the base branch from main to VAULT-5858/release-ns-enhancements April 19, 2022 18:19
@benashz benashz added this to the 3.7.0 milestone May 18, 2022
@benashz benashz changed the base branch from VAULT-5858/release-ns-enhancements to main May 24, 2022 19:22
@benashz benashz changed the base branch from main to VAULT-5858/release-ns-enhancements May 24, 2022 19:22
@benashz benashz marked this pull request as ready for review May 25, 2022 19:25
@benashz benashz changed the title Namespace enhancement POC 1 Namespace by resource May 25, 2022
@benashz benashz requested a review from calvn May 25, 2022 23:19
@benashz benashz force-pushed the VAULT-4254/namespace-poc-count branch from 36bdf36 to 92d2bff Compare May 31, 2022 18:11
Copy link
Contributor

@vinay-gopalan vinay-gopalan left a comment

Choose a reason for hiding this comment

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

Looks great! Had a couple questions :)

internal/provider/meta.go Show resolved Hide resolved
internal/provider/meta.go Show resolved Hide resolved
internal/provider/meta.go Show resolved Hide resolved
- add tests for provider.GetClient()
- use some env var constants from the `vault/api` package
Copy link
Contributor

@vinay-gopalan vinay-gopalan left a comment

Choose a reason for hiding this comment

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

Code and tests are looking great!

@benashz benashz merged commit 6813aee into VAULT-5858/release-ns-enhancements Jun 1, 2022
@benashz benashz deleted the VAULT-4254/namespace-poc-count branch June 1, 2022 19:17
benashz added a commit that referenced this pull request Jun 2, 2022
This change adds support for configuring namespaces at the resource or data source level.

All namespace directives are applied relative to the provider's configured namespace. This new approach allows for namespace'd resources to be created without having to pass a namespace specific provider, although that method is still fully supported.
bwagner3slb added a commit to bwagner3slb/terraform-provider-vault that referenced this pull request Aug 15, 2022
marcboudreau pushed a commit to marcboudreau/terraform-provider-vault that referenced this pull request Nov 6, 2022
This change adds support for configuring namespaces at the resource or data source level.

All namespace directives are applied relative to the provider's configured namespace. This new approach allows for namespace'd resources to be created without having to pass a namespace specific provider, although that method is still fully supported.
marcboudreau pushed a commit to marcboudreau/terraform-provider-vault that referenced this pull request Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants