Почему бы не использовать template_file:
data "template_file" "kube_config" {
template = "${file("${path.module}/kubeconfig.tpl")}"
vars {
vpc_name = "${var.vpc_name}"
eks_name = "${aws_eks_cluster.eks_cluster.id}"
eks_endpoint = "${aws_eks_cluster.eks_cluster.endpoint}"
eks_cert = "${aws_eks_cluster.eks_cluster.certificate_authority.0.data}"
}
}
Где файл, используемый для шаблонирования, выглядит следующим образом:
apiVersion: v1
clusters:
- cluster:
server: ${eks_endpoint}
certificate-authority-data: ${eks_cert}
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: aws
name: aws-${vpc_name}
current-context: aws-${vpc_name}
kind: Config
preferences: {}
users:
- name: aws
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1
command: heptio-authenticator-aws
args:
- "token"
- "-i"
- "${eks_name}"
#- "-r"
#- "<role ARN>"
#env:
#- name: AWS_PROFILE
# value: "<profile>"
Если вам не нужно ничего делать с переменными перед генерацией файла, шаблон может быть лучшим вариантом.
Тогда вы можете запускать команды, используя обработанный файл:
resource "null_resource" "config_setup" {
triggers {
kubeconfig_change = "${data.template_file.kube_config.rendered}"
configmap_change = "{local.config-map-aws-auth}"
}
provisioner "local-exec" {
command = "mkdir -p ${var.vpc_name}_output_EKS; echo '${data.template_file.kube_config.rendered}' >${var.vpc_name}_output_EKS/kubeconfig"
}
}