terraformamazon-kinesis

Why is my variable using the default value instead of the value from locals?


I'm using Terraform and noticed that one of my variables always falls back to its default value, even though I define a different value in a locals block.

Here’s what I have in variables.tf:

variable "peak_number_of_shards" {
  type        = number
  description = "Number of shards that Kinesis stream will have under load"
  default     = 4
}

What I have in my prod/locals.tf:

locals {
  peak_number_of_shards = 16
  ...
}

In my eu-west-1.tf file:

  peak_number_of_shards     = local.peak_number_of_shards

In my State Machine I am using like that:

      ScaleUpKinesisStream = {
        Comment  = "State to scale Kinesis stream up synchronously"
        Type     = "Task"
        Resource = "arn:aws:states:::states:startExecution.sync"
        Parameters = {
          StateMachineArn = aws_sfn_state_machine.xxx.id
          Input = {
            stream_name        = aws_kinesis_stream.xxx.name
            target_shard_count = var.peak_number_of_shards
          }
        }
        Next = "CheckDateParameters"
        Catch = [{
          ErrorEquals = ["States.ALL"]
          Next        = "NotifyError"
        }]
      }

However, when I run terraform plan or terraform apply, it always uses the default value 4, not the value from the local. Other attributes are fine, sometimes some of the attributes fallbacks to the default values in some way but I couldn't understand the reason.

Terraform v0.13.7


Solution

  • Terraform local values and input variables are two completely separate things. You would reference the variable as var.peak_number_of_shards while you would reference the local value as local.peak_number_of_shards.

    The local value doesn't override the input variable value in any way. They are stored completely separately and access in completely separate ways.


    If you want to somehow use the input variable, but also override it in some way, then that is probably possible, but you need to provide details in your question of exactly what you are trying to accomplish before we can show you the correct way to do that.