-
Notifications
You must be signed in to change notification settings - Fork 86
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
Can't supply kubeconfig path using KUBE_CONFIG_PATH env variable #440
Comments
The provider does not attempt to fetch attribute values from environment variables. The reason for this is that there is currently no good support to implement this in the new provider SDK. The docs are incorrect, I will create a PR that fixes it, sorry for the confusion. |
why not doing something like the |
"config_path": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KUBE_CONFIG_PATH", nil),
Description: "Path to the kube config file. Can be set with KUBE_CONFIG_PATH.",
ConflictsWith: []string{"config_paths"},
}, terraform-provider-flux/internal/provider/provider.go Lines 147 to 150 in 9c8106c
|
Not only does the kubernetes provider, the helm provider also supports setting a set of common kubernetes arguments via environment variables:
I think it's better if flux could align with the popular kubernetes and helm provider, as that improves friction. |
Is this missing functionality blocking your ability to use the provider? The reason I ask is that this provider uses github.com/hashicorp/terraform-plugin-framework The kubernetes and helm providers use github.com/hashicorp/terraform-plugin-sdk which is seen as the old way. See snippet from the plugin-sdk README below:
|
Edited:
I managed to verify that #506 added support for But the other options such as KUBE_CLIENT_CERT_DATA/KUBE_CLIENT_KEY_DATA/KUBE_CLUSTER_CA_CERT_DATA/KUBE_HOST still not supported. I don't think it's a blocking issue, but a good enhancement worth considering: Potential So they might got the following environment variables and terraform provider before they integrate The following .env demo is based on 1password-cli, but they can also be injected by CI or IaC platform such as Terraform Cloud: KUBE_CLIENT_CERT_DATA=op://${VAULT}/kubernetes/${SECTION}/KUBE_CLIENT_CERT_DATA
KUBE_CLIENT_KEY_DATA=op://${VAULT}/kubernetes/${SECTION}/KUBE_CLIENT_KEY_DATA
KUBE_CLUSTER_CA_CERT_DATA=op://${VAULT}/kubernetes/${SECTION}/KUBE_CLUSTER_CA_CERT_DATA
KUBE_HOST=op://${VAULT}/kubernetes/${SECTION}/KUBE_HOST Or they can provide a dev credential on the local machine: KUBE_CONFIG_PATH=~/.kube/config And the terraform provider config is the same: provider "kubernetes" {}
provider "helm" {
kubernetes {}
} As you see, the credentials config of OK. Now the users want to integrate
variable "KUBE_CLIENT_CERT_DATA" {
nullable = false
type = string
}
variable "KUBE_CLIENT_KEY_DATA" {
nullable = false
sensitive = true
type = string
}
variable "KUBE_CLUSTER_CA_CERT_DATA" {
nullable = false
type = string
}
variable "KUBE_HOST" {
nullable = false
type = string
}
provider "flux" {
kubernetes = {
client_certificate = var.KUBE_CLIENT_CERT_DATA
client_key = var.KUBE_CLIENT_KEY_DATA
cluster_ca_certificate = var.KUBE_CLUSTER_CA_CERT_DATA
host = var.KUBE_HOST
}
git = {}
}
TF_VAR_KUBE_CLIENT_CERT_DATA=op://${VAULT}/kubernetes/${SECTION}/KUBE_CLIENT_CERT_DATA
TF_VAR_KUBE_CLIENT_KEY_DATA=op://${VAULT}/kubernetes/${SECTION}/KUBE_CLIENT_KEY_DATA
TF_VAR_KUBE_CLUSTER_CA_CERT_DATA=op://${VAULT}/kubernetes/${SECTION}/KUBE_CLUSTER_CA_CERT_DATA
TF_VAR_KUBE_HOST=op://${VAULT}/kubernetes/${SECTION}/KUBE_HOST These are so much boilerplate code, and please note that now the authentication method is locked, so if users want to use file based credential such as kubeconfig or change some authentation option, they must change the I don't think terraform-plugin-framework couldn't use environment variables as provider credentials. They even provide an example in the official document. And terraform-provider-flux seems already using this mechanism: terraform-provider-flux/internal/provider/provider.go Lines 360 to 364 in 6042c15
Common set of environment variables of P.S. For real world terraform users, they might separate their terraform code to modules and workspaces, and when they do the above mentioned boilerplate code would magnified. |
@networkhermit |
@swade1987
Thanks again for the attention. Edited: I managed to verify that #506 added support for But the other options such as KUBE_CLIENT_CERT_DATA/KUBE_CLIENT_KEY_DATA/KUBE_CLUSTER_CA_CERT_DATA/KUBE_HOST still not supported. |
Hello,
I faced situation when I can't dynamically define path to kubeconfig in flux provider without using extra (bridge) variable:
according to documentation config_path for kubernetes attribute could be supplied using KUBE_CONFIG_PATH env variable, but it doesn't work together with git attribute:
lead to following error:
same for
How I could supply path to kubeconfig without bridging value like:
$TF_VAR_kubeconfig > var.kubeconfig > kubernetes.config_path
and make it work directly:
$KUBE_CONFIG_PATH > kubernetes.config_path
in my case?
Version:
fluxcd/flux v0.25.3
Thanks
The text was updated successfully, but these errors were encountered: