Search code examples
amazon-web-servicesterraformkubernetes-helmamazon-efs

EFS CSI driver using Terraform


I am attempting to install the EFS CSI driver using Helm via Terraform, but I'm encountering an issue related to specifying the repo URL and image tag/URI. Whenever I provide these values, I receive a "context deadline exceeded" error.

Here is a snippet of my Terraform code that deploys the Helm chart:

resource "helm_release" "test_aws_efs_controller" {
  name       = "aws-efs-csi-driver"
  repository = "https://kubernetes-sigs.github.io/aws-efs-csi-driver/"
  chart      = "aws-efs-csi-driver"
  namespace  = "${var.project_name}-${var.environment_name}-microservices"
  version    = "2.2.0"

  set {
    name  = "clusterName"
    value = var.test_ekscluster_id
  }

  # set {
  #   name  = "image.repository"
  #   value = "public.ecr.aws/efs-csi-driver/amazon/aws-efs-csi-driver:v1.6.0"
  # }


  # set {
  #   name  = "image.tag"
  #   value = "v2.4.8"
  # }

  set {
    name  = "controller.serviceAccount.create"
    value = true
  }

  set {
    name  = "controller.serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
    value = var.aws_efs_controller_role_arn
  }

  set {
    name  = "controller.serviceAccount.name"
    value = "${var.project_name}-${var.environment_name}-efs-controller"
  }

  depends_on = [
    var.test_nodegroup,
    var.aws_efs_controller_role_attach
  ]

}

I have tried various combinations for the repository and version fields, as well as different values for image.repository, but I continue to encounter the "context deadline exceeded" error.

Can someone please provide guidance on the correct values to use for these fields when deploying the EFS CSI driver with Helm via Terraform? Additionally, if there are any specific Helm chart configurations that need to be set for this driver, please let me know.


Solution

  • Based on the documentation in the Helm chart GitHub repo:

    To specify an image repository, add the following argument. Replace the repository address with the cluster's container image address.

    The example the documentation shows is:

    --set image.repository=602401143452.dkr.ecr.region-code.amazonaws.com/eks/aws-efs-csi-driver
    

    Since the cluster is running in the Mumbai (ap-south-1) region, you need to fix the code to the following:

    resource "helm_release" "test_aws_efs_controller" {
      name       = "aws-efs-csi-driver"
      repository = "https://kubernetes-sigs.github.io/aws-efs-csi-driver/"
      chart      = "aws-efs-csi-driver"
      namespace  = "${var.project_name}-${var.environment_name}-microservices"
      version    = "2.4.9"
    
      set {
        name  = "clusterName"
        value = var.test_ekscluster_id
      }
    
      set {
        name  = "image.repository"
        value = "602401143452.dkr.ecr.ap-south-1.amazonaws.com/eks/aws-efs-csi-driver"
      }
    
      set {
          name  = "image.tag"
          value = "v1.6.0"
      }
    
      set {
        name  = "controller.serviceAccount.create"
        value = true
      }
    
      set {
        name  = "controller.serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
        value = var.aws_efs_controller_role_arn
      }
    
      set {
        name  = "controller.serviceAccount.name"
        value = "${var.project_name}-${var.environment_name}-efs-controller"
      }
    
    }
    

    In order to find which Helm chart version to use, this command should be used:

    helm search repo aws-efs-csi-driver
    

    which will output:

    NAME                                    CHART VERSION   APP VERSION DESCRIPTION
    aws-efs-csi-driver/aws-efs-csi-driver   2.4.9           1.6.0       A Helm chart for AWS EFS CSI Driver
    

    The version argument of the helm_release expects what is listed under the CHART VERSION column. The APP VERSION in this case matches what is listed in the GitHub documentation for AWS EFS CSI driver:

    public.ecr.aws/efs-csi-driver/amazon/aws-efs-csi-driver:v1.6.0
    

    Where the image tag (v1.6.0) corresponds to the app version. However, that might be the case for this particular chart, and not a rule for all the other charts.