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

Feature request: add a standard "name" attribute #2448

Open
Manbeardo opened this issue Mar 19, 2024 · 2 comments
Open

Feature request: add a standard "name" attribute #2448

Manbeardo opened this issue Mar 19, 2024 · 2 comments

Comments

@Manbeardo
Copy link

Description

It would be dramatically easier to DRY up k8s templates while implicitly ordering the resource DAG if every k8s resource had a "name" attribute. As-is, we can extract the name attribute by using coalesce(kubernetes_manifest.my_manifest.metadata[*].name...), but that's an awfully complicated way to access such a commonly-used attribute.

Potential Terraform Configuration

resource "kubernetes_namespace" "my_ns" {
  metadata {
    name = "my-namespace"
  }
}

# proposed option: name attribute
resource "kubernetes_secret" "secret_0" {
  metadata {
    name      = "secret-0"
    namespace = kubernetes_namespace.my_ns.name
  }

  data = {
    foo = "bar"
  }
}

# current option #1: use coalesce
resource "kubernetes_secret" "secret_1" {
  metadata {
    name      = "secret-1"
    namespace = coalesce(kubernetes_namespace.my_ns.metadata[*].name...)
  }

  data = {
    foo = "bar"
  }
}

# current option #2: use depends_on
resource "kubernetes_secret" "secret_2" {
  depends_on = [kubernetes_namespace.my_ns]
  metadata {
    name      = "secret-2"
    namespace = "my-namespace"
  }

  data = {
    foo = "bar"
  }
}

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@sheneska
Copy link
Contributor

Hi @Manbeardo, thanks for opening this issue.
A much simpler alternative to this would be setting the namespace without the coalesce function, and instead just referencing the name attribute in the metadata (metadata[0].name). Since name is the first and thus only attribute in the metadata this should always work.
Hope this helped!

@Manbeardo
Copy link
Author

What about code that uses generate_name instead of name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants