skip to Main Content

We have been using Terraform EKS module and trying to parametrize ‘eks_managed_node_groups’ values based on the development and production environment. We have used file() and variable approaches but both resulted in the error.

varibales.tf

variable "eks_cluster_nodegroups" {
  description = "Nodegroups of the EKS cluster"
}

.tfvars

eks_cluster_nodegroups = <<EOF
{
    ng-1 = {
      min_size     = 1
      max_size     = 2
      desired_size = 1

      instance_types = ['t3.small']
      capacity_type  = 'SPOT' //ON_DEMAND
    }
}
EOF

eks.tf

module "eks" {
  source  = "terraform-aws-modules/eks/aws"
  version = "~> 18.0"
.....
.....
eks_managed_node_groups = var.eks_cluster_nodegroups
.....
}

Thank you.

EKS module: https://registry.terraform.io/modules/terraform-aws-modules/eks/aws/latest

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

  2. You can use jsondecode to convert your string to TF object:

    eks_managed_node_groups = jsondecode(var.eks_cluster_nodegroups)
    

    Also it would be easier not to use JSON string in the first place for your eks_cluster_nodegroups.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search