terraform-provider-kubernetes icon indicating copy to clipboard operation
terraform-provider-kubernetes copied to clipboard

data object for provider configuration

Open salzig opened this issue 3 years ago • 3 comments

Description

It would be kind of helpful/useful to get access to provider information using a data object (eg. used host), so it would be possible to fetch this information to create resource with reference to it. Escpecially useful when working with multiple clusters.

Potential Terraform Configuration

provider "kubernetes" {
  config_path    = "~/.kube/config"
  alias = "A"
}
data "kubernetes_provider" "A" {
  provider = kubernetes.A
}
output "host_a" {
  value = data.kubernetes_provider.A.host
}

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

salzig avatar Aug 30 '21 10:08 salzig

I'm not sure I understand what your use case is for this data source. Could you provide a more concrete example?

The options supplied to the provider block are either going to be hard coded into the config, or sourced from a variable or other data source anyway so you should be able to reference those in any resource? You could put your provider config into a local variable that was an object, for example, and reference it in both the provider and the resource you want to create.

If you want to pull data from the kubeconfig file itself you can use file and yamldecode to load it and pull out specifics if required.

In any case, a "provider config" data source seems more like a meta feature that would be a part of Terraform itself rather than this specific provider so I would recommend opening an issue on the core repo if you have a concrete use-case for this.

jrhouston avatar Aug 30 '21 21:08 jrhouston

Currently i'm experimenting with generating serviceaccounts for ~7 different Kubernetes Clusters, plus with limited access for "specific" namespaces and resources, and provide kubeconfigs for "matching" projects in a private gitlab installation as CI/CD-Variables. This setup is quite volatile, that's why i choose to test this with terraform.

Now, after generating a serviceaccount (with specific provider, namespace, rolebinding, etc) while generating the kubeconfig, i was wondering how i'm getting the host in a sane way. My first thought was that the used provider is known, so it should be "easy" to retrieve the information there.

Maybe comparable to https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity

salzig avatar Aug 31 '21 09:08 salzig

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

github-actions[bot] avatar Sep 01 '22 00:09 github-actions[bot]

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Oct 31 '22 02:10 github-actions[bot]