Home > Blockchain >  How to apply yaml file on terraform?
How to apply yaml file on terraform?

Time:01-10

How do I do this but in terraform using kubernetes provider??

kubectl apply -k "github.com/kubernetes-sigs/aws-efs-csi-driver/deploy/kubernetes/overlays/stable/?ref=release-1.4"

I have searched for a few, but none mention applying a direct yaml file.

CodePudding user response:

You can achieve that differently; if that works for you. You want to execute kubectl from Terraform, not communicating directly with the Kubernetes API.

I think this method has more advantages than what you originally asking for, because it removes an external dependency.

There's a kubectl provider you can use. You can download the YAML and commit it with your Terraform code. That way it is also easier to review changes to the YAML (between versions).

It would look something like this:

resource "kubectl_manifest" "test" {
    yaml_body = <<YAML
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    azure/frontdoor: enabled
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: "Prefix"
        backend:
          serviceName: test
          servicePort: 80
YAML
}

CodePudding user response:

I would suggest you use the aws-efs-csi-driver Helm Chart and further using the helm terraform provider.

Would be easy and neat.

## refer to the provider documentation to configure accordingly this is the simplest example.
provider "helm" {
  kubernetes {
    config_path = "~/.kube/config"
  }

resource "helm_release" "aws_efs_csi_driver" {
  name       = "aws-efs-csi-driver"

  repository = "https://kubernetes-sigs.github.io/aws-efs-csi-driver/"
  chart      = "aws-efs-csi-driver"

  set {
   ### Your custom values ###
  }
}
  • Related