hashicorp / terraform-aws-consul

A Terraform Module for how to run Consul on AWS using Terraform and Packer
Apache License 2.0
401 stars 488 forks source link

Remove type constraint to allow null #239

Closed TomGudman closed 2 years ago

TomGudman commented 2 years ago

Description

When you use terragrunt or even a terraform module calling terraform-aws-consul module you may have spot_price defined but you don't want to assign any value because you want the instances to be on-demand. However since it's templated with the use of a variable, spot_price is always present. Unfortunately the type=number for spot_price makes it impossible to assign an empty value because terraform/terragrunt will tell you that null or "" is not a number.

The change is a simple as not enforcing the type = number in variables.tf

Use case (simplified version)

terragrunt.hcl

terraform {
  source = "git::git@inhouse.net:infrastructure/terraform-modules/cloud-modules.git///aws-consul-server-cluster/"
}
...
inputs = {
  ...
  cluster_name   = "foobar"
  spot_price   = local.SPOT
  ...
}

terraform in-house module

variable "spot_price" {
  description = "If defined, let's use spot instances with a price UP TO this value"
  default     = null
}

module "consul_servers" {
  source = "git::git@github.com:TomGudman/terraform-aws-consul.git//modules/consul-cluster?ref=v0.11.1"

  cluster_name  = var.cluster_name
  cluster_size  = var.num_servers
  instance_type = var.instance_type

  spot_price = var.spot_price
}

Documentation

N/A

TODOs / Related issues

There isn't any issue number yet and I couldn't find one.

hashicorp-cla commented 2 years ago

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes


Thomas Guthmann seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you already have a GitHub account, please add the email address used for this commit to your account.

Have you signed the CLA already but the status is still pending? Recheck it.

TomGudman commented 2 years ago

And replaced again by https://github.com/hashicorp/terraform-aws-consul/pull/240 the third time the charm!