user15695494
user15695494

Reputation: 51

Presenting Numbers as double digits in Terraform

Using the count function within Terraform to create multiple instances of the same type. Each instance is tagged with the correct Name and associated count number. The problem is, when sorting these instances, the first 10 have a single digit. I would like these to have double digits. E.G. 1 would be 01, 2 would 02 etc. The question is, how can I format the numbering of the first ten digits with double digits? Below is a sample of how I'm currently naming the resources.

"Name"   = "${var.Event} Candidate ${count.index + 1} Linux Management Interface"

Upvotes: 1

Views: 2109

Answers (2)

Chris Kosch
Chris Kosch

Reputation: 31

also

ip = "172.16.0.0${count.index}"

te result will be 01 02 03 04 05

Upvotes: 0

Adil B
Adil B

Reputation: 16846

Try using the format function with the 0-padding and width modifiers for the second string:

"Name"   = "${format("%s Candidate %02s Linux Management Interface", var.Event, count.index + 1)}"

Upvotes: 2

Related Questions