<p>I am writing a terraform file in GCP to run a stateless application on a GKE, these are the steps I'm trying to get into terraform.</p>
<ol>
<li>Create a service account</li>
<li>Grant roles to the service account</li>
<li>Creating the cluster</li>
<li>Configuring the deployment</li>
</ol>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mllp-adapter-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mllp-adapter
  template:
    metadata:
      labels:
        app: mllp-adapter
    spec:
      containers:
        - name: mllp-adapter
          imagePullPolicy: Always
          image: gcr.io/cloud-healthcare-containers/mllp-adapter
          ports:
            - containerPort: 2575
              protocol: TCP
              name: &quot;port&quot;
          command:
            - &quot;/usr/mllp_adapter/mllp_adapter&quot;
            - &quot;--port=2575&quot;
            - &quot;--hl7_v2_project_id=PROJECT_ID&quot;
            - &quot;--hl7_v2_location_id=LOCATION&quot;
            - &quot;--hl7_v2_dataset_id=DATASET_ID&quot;
            - &quot;--hl7_v2_store_id=HL7V2_STORE_ID&quot;
            - &quot;--api_addr_prefix=https://healthcare.googleapis.com:443/v1&quot;
            - &quot;--logtostderr&quot;
            - &quot;--receiver_ip=0.0.0.0&quot;
</code></pre>
<ol start="5">
<li>Add internal load balancer to make it accesible outside of the cluster</li>
</ol>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mllp-adapter-service
  annotations:
    cloud.google.com/load-balancer-type: &quot;Internal&quot;
spec:
  type: LoadBalancer
  ports:
  - name: port
    port: 2575
    targetPort: 2575
    protocol: TCP
  selector:
    app: mllp-adapter
</code></pre>
<p>I've found this <a href="https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/examples/simple_autopilot_public" rel="nofollow noreferrer">example</a> in order to create an auto-pilot-public cluster, however I don't know where to specify the YAML file of my step 4</p>
<p>Also I've found this other <a href="https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/examples/deploy_service" rel="nofollow noreferrer">blueprint</a> that deploy a service to the created cluster using the kubernetes provider, which I hope solves my step 5.</p>
<p>I'm new at terraform and GCP architecture in general, I got all of this working following <a href="https://cloud.google.com/healthcare-api/docs/how-tos/mllp-adapter" rel="nofollow noreferrer">documentation</a> however I'm now trying to find a way to deploy this on a dev enviroment for testing purposes but that's outside of my sandbox and it's supposed to be deployed using terraform, I think I'm getting close to it.</p>
<p>Can someone enlight me what's the next step or how to add those YAML configurations to the <code>.tf</code> examples I've found?</p>
<p>Am I doing this right? :(</p>

Scared Sandwich
<p>You can use this script and extend it further to deploy the YAML files with that : <a href="https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/examples/simple_autopilot_public" rel="nofollow noreferrer">https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/examples/simple_autopilot_public</a></p>
<p>The above TF script is creating the GKE auto pilot cluster for YAML deployment you can use the K8s provider and apply the files using that.</p>
<p><a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/deployment" rel="nofollow noreferrer">https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/deployment</a></p>
<p>Full example : <a href="https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/examples/simple_autopilot_public" rel="nofollow noreferrer">https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/tree/master/examples/simple_autopilot_public</a></p>
<p>main.tf</p>
<pre><code>locals {
  cluster_type           = &quot;simple-autopilot-public&quot;
  network_name           = &quot;simple-autopilot-public-network&quot;
  subnet_name            = &quot;simple-autopilot-public-subnet&quot;
  master_auth_subnetwork = &quot;simple-autopilot-public-master-subnet&quot;
  pods_range_name        = &quot;ip-range-pods-simple-autopilot-public&quot;
  svc_range_name         = &quot;ip-range-svc-simple-autopilot-public&quot;
  subnet_names           = [for subnet_self_link in module.gcp-network.subnets_self_links : split(&quot;/&quot;, subnet_self_link)[length(split(&quot;/&quot;, subnet_self_link)) - 1]]
}

data &quot;google_client_config&quot; &quot;default&quot; {}

provider &quot;kubernetes&quot; {
  host                   = &quot;https://${module.gke.endpoint}&quot;
  token                  = data.google_client_config.default.access_token
  cluster_ca_certificate = base64decode(module.gke.ca_certificate)
}

module &quot;gke&quot; {
  source                          = &quot;../../modules/beta-autopilot-public-cluster/&quot;
  project_id                      = var.project_id
  name                            = &quot;${local.cluster_type}-cluster&quot;
  regional                        = true
  region                          = var.region
  network                         = module.gcp-network.network_name
  subnetwork                      = local.subnet_names[index(module.gcp-network.subnets_names, local.subnet_name)]
  ip_range_pods                   = local.pods_range_name
  ip_range_services               = local.svc_range_name
  release_channel                 = &quot;REGULAR&quot;
  enable_vertical_pod_autoscaling = true
}
</code></pre>
<p>Another Good example which use the YAML files as template and apply it using the terraform. : <a href="https://github.com/epiphone/gke-terraform-example/tree/master/terraform/dev" rel="nofollow noreferrer">https://github.com/epiphone/gke-terraform-example/tree/master/terraform/dev</a></p>
