horie-t
horie-t

Reputation: 61

Is there any way to separate terraform's expression into multiple lines?

I want to know the way to separate terraform expressions into multiple lines because they're sometimes too long if in 1 line.

$ terraform version
Terraform v0.14.2
locals {
  bucket_name = var.bucket_name == "" ? "hoge-${formatdate("YYYYMMDDHHmmss", timestamp())}" : var.bucket_name
}
locals {
  bucket_name = var.bucket_name == "" ? \
                "hoge-${formatdate("YYYYMMDDHHmmss", timestamp())}" : \
                 var.bucket_name
}

But this raise an Error: Invalid expression.

Is there any way to separate an expression into multiple lines?

Upvotes: 6

Views: 932

Answers (1)

Marcin
Marcin

Reputation: 238687

You can just put it in brackets:

locals {
  bucket_name = (var.bucket_name == "" 
              ? "hoge-${formatdate("YYYYMMDDHHmmss", timestamp())}" 
              : var.bucket_name)
}

Upvotes: 8

Related Questions