Home > front end >  Parameterised input values while using Terraform module
Parameterised input values while using Terraform module

Time:09-13

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: enter image description here

CodePudding user response:

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.

CodePudding user response:

The error was due to syntax.

More info: https://discuss.hashicorp.com/t/multi-line-string-variable/44172

  • Related