Locals in Terraform

A local value store a result from an expression (this can be interpolation or output from a Terraform function), so you can use it multiple times within a module without repeating it. These are more like variables in other scripting or programming languages.

...
data "aws_caller_identity" "current" {}

# local values allow you to assign a name to an expression
# locals can make your code more readable
locals {
  aws_full_bucket_name = "${lower(data.aws_caller_identity.current.user_id)}-${var.bucket_name}"
}

resource "aws_s3_bucket" "bucket1" {
  bucket = local.aws_full_bucket_name
}
...