-
Notifications
You must be signed in to change notification settings - Fork 984
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
kubernetes_secret data is not read from cluster after secret creation #1221
Comments
This looks like it might be a duplicate of #1168 |
@astorath Have you found any workaround? |
Here's what we ended up doing: Terraform: data "external" "kubernetes_secret_env_systems" {
for_each = kubernetes_service_account.env_systems
program = ["Powershell.exe", "& ./Get-KubernetesSecretData.ps1"]
working_dir = path.module
query = {
kubeConfigContext = var.cluster_name
namespace = each.value.metadata.0.namespace
secretName = each.value.default_secret_name
jsonPath = "{.data}"
}
}
# Example usage
# data.external.kubernetes_secret_env_systems[each.key].result.token File: Get-KubernetesSecretData.ps1 $ErrorActionPreference = "Stop"
# Read stdin as string
$jsonPayload = [Console]::In.ReadLine()
$json = ConvertFrom-Json $jsonPayload
if (-not $json) {
Write-Error "Unable to parse JSON input."
}
if ([string]::IsNullOrEmpty($json.kubeConfigContext)) {
Write-Error "Required property 'kubeConfigContext' not provided in JSON input."
}
if ([string]::IsNullOrEmpty($json.namespace)) {
Write-Error "Required property 'namespace' not provided in JSON input."
}
if ([string]::IsNullOrEmpty($json.secretName)) {
Write-Error "Required property 'secretName' not provided in JSON input."
}
if (-not [string]::IsNullOrEmpty($json.kubeConfigPath)) {
$Env:KUBECONFIG = $json.kubeConfigPath
}
$null = kubectl config use-context ($json.kubeConfigContext)
$dataJsonPath = "{@}"
if ($json.jsonPath) {
$dataJsonPath = $json.jsonPath
}
$ns = $json.namespace
$name = $json.secretName
$secretData = kubectl get secret $name -o jsonpath=$dataJsonPath --namespace=$ns
Write-Output $secretData |
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! |
Still relevant. With #1792 it isn't clear how to create token for ServiceAccount using provider's resources. |
Terraform Version, Provider Version and Kubernetes Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
https://gist.github.com/astorath/0511a583ce91f95fff58e676c16bae6e
Steps to Reproduce
kubectl create serviceaccount gitlab
2.
terraform plan
Expected Behavior
secret's
kubernetes_secret
data is read from cluster after creationActual Behavior
secret's
kubernetes_secret
data is treated as null as per resource manifestImportant Factoids
References
Community Note
The text was updated successfully, but these errors were encountered: