I am new to terraform and Kubernetes. We are trying to get the service account secret token to pass to create the kubeconfig file. We were using the default_secret_name attribute of the kubernetes_service_account resource to get the same. With the 1.24 version, the default_secret_name attribute has been deprecated and asked to use the kubernetes_secret_v1 resource. We need help to get the method to retrieve the secret token.
Using the default_secret_name attribute, the token has been referenced as
data “kubernetes_secret” “service_account_secret” {
metadata {
name = “${kubernetes_service_account.admin_service_account.default_secret_name}”
}
}
data “template_file” “kubeconfig” {
…
vars = {
…
token = “${data.kubernetes_secret.service_account_secret.data.token}”
}
}
How do we refer to/get the token value using the kubernetes_secrets_v1 resource?
Thanks for your response. We tried to implement using the resource and the data resource and received the error.
List item
When using kubernetes_service_account resource:
resource “kubernetes_service_account” “admin_service_account” {
metadata {
name = “admin-service-account”
}
}
List item
When used kubernetes_service_account_v1 resource:
resource “kubernetes_service_account_v1” “service_account_token” {
metadata {
name = “service_account_token”
}
}
metadata.0.name a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, ‘-’ or ‘.’, and must start and end with an alphanumeric character (e.g. ‘example.com’, regex used for validation is ‘a-z0-9?(.a-z0-9?)*’)