how to limit a string to a specific length in Terraform?

4,682 views
Skip to first unread message

ja...@fpcomplete.com

unread,
Apr 14, 2016, 10:18:01 AM4/14/16
to Terraform
The elasticache API on AWS is strict about the length of the string it receives for a "cache cluster identifier":

"The parameter CacheClusterIdentifier is not a valid identifier because it is longer than 20 characters."


I have hacked around this a few times, but now I would like to put in place a more reasonable solution for this issue in my code, and I believe the most straightforward would be to simply limit the length of the string I pass into that parameter.

If I have a string that is 30 characters, and need to limit it to 20 characters, what is the way to do this in Terraform?

Tobias McNulty

unread,
Jun 9, 2016, 11:57:04 PM6/9/16
to Terraform
I would love to know if this is possible too; stumbled across this thread after encountering the same error. I'm not even sure what attribute needs to be reduced in size.

Tobias McNulty

unread,
Jun 10, 2016, 12:14:04 AM6/10/16
to Terraform
Actually, this isn't so hard, e.g.:

resource "aws_elasticache_cluster" "redis" {

    cluster_id = "${format("%.14s", var.project_name)}-redis"

    engine = "redis"

    node_type = "${var.redis_node_type}"

    port = 6379

    num_cache_nodes = 1

Charlie

unread,
Oct 22, 2018, 6:46:15 AM10/22/18
to Terraform

Charlie

unread,
Oct 22, 2018, 6:46:42 AM10/22/18
to Terraform
string(20) you can put it


On Thursday, 14 April 2016 19:48:01 UTC+5:30, ja...@fpcomplete.com wrote:
Reply all
Reply to author
Forward
0 new messages