<p>I'm using a slightly customized Terraform configuration to generate my Kubernetes cluster on AWS. The configuration includes an EFS instance attached to the cluster nodes and master. In order for Kubernetes to use this EFS instance for volumes, my Kubernetes YAML needs the id and endpoint/domain of the EFS instance generated by Terraform.</p>

<p>Currently, my Terraform outputs the EFS id and DNS name, and I need to manually edit my Kubernetes YAML with these values after <code>terraform apply</code> and before I <code>kubectl apply</code> the YAML.</p>

<p>How can I automate passing these Terraform output values to Kubernetes?</p>

<p>I don't know what you mean by a yaml to set up an Kubernetes cluster in AWS. But then, I've always set up my AWS clusters using <a href="https://github.com/kubernetes/kops" rel="nofollow noreferrer">kops</a>. Additionally I don't understand why you would want to mount an EFS to the master and/or nodes instead of to the containers.</p>

<p>But in direct answer to your question: you could write a script to output your Terraform outputs to a <a href="https://github.com/kubernetes/helm" rel="nofollow noreferrer">Helm</a> values file and use that to generate the k8s config.</p>

<p>I stumbled upon this question when searching for a way to get TF outputs to envvars specified in Kubernetes and I expect  more people do. I also suspect that that was really your question as well or at least that it can be a way to solve your problem. So:</p>

<p>You can use the <a href="https://www.terraform.io/docs/providers/kubernetes/" rel="nofollow noreferrer">Kubernetes Terraform provider</a> to connect to your cluster and then use the <a href="https://www.terraform.io/docs/providers/kubernetes/r/config_map.html" rel="nofollow noreferrer"><code>kubernetes_config_map</code></a> resources to create configmaps.</p>

<pre><code>provider "kubernetes" {}

resource "kubernetes_config_map" "efs_configmap" {
  "metadata" {
    name = "efs_config"  // this will be the name of your configmap
  }

  data {
    efs_id = "${aws_efs_mount_target.efs_mt.0.id}"
    efs_dns = "${aws_efs_mount_target.efs_mt.0.dns_name}"
  }
}
</code></pre>

<p>If you have secret parameters use the <a href="https://www.terraform.io/docs/providers/kubernetes/r/secret.html" rel="nofollow noreferrer"><code>kubernetes_secret</code></a> resource:</p>

<pre><code>resource "kubernetes_secret" "some_secrets" {
  "metadata" {
    name = "some_secrets"
  }

  data {
    s3_iam_access_secret = "${aws_iam_access_key.someresourcename.secret}"
    rds_password = "${aws_db_instance.someresourcename.password}"
  }
}    
</code></pre>

<p>You can then <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">consume these in your k8s</a> yaml when setting your environment:</p>

<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: some-app-deployment
spec:
  selector:
    matchLabels:
        app: some
  template:
    metadata:
      labels:
        app: some
    spec:
      containers:
        - name: some-app-container
          image: some-app-image
          env:
            - name: EFS_ID
              valueFrom:
                configMapKeyRef:
                  name: efs_config
                  key: efs_id
            - name: RDS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: some_secrets
                  key: rds_password
</code></pre>
