Terraform: Need way to interpolate count index as other than zero-based (for host names)

Created on 16 Dec 2014  ยท  7Comments  ยท  Source: hashicorp/terraform

Around our shop, server names with numbers are done one-based.
Since the only way, in a counted resource, to interpolate a ${count.index} is zero-based, this causes annoying zero-based server names.

IWBNI there were either another "part" for count, say index1, or a way to specify an offset such as indexplus 1 or a way to nest those references and an "add" interpolation. Something, anything, please.

core enhancement

Most helpful comment

I think there might be a related issue for this, but what about left padding a number to a certain number of digits so you can use the count to create server names like server-01, server-02, etc.?

All 7 comments

Hm, I think we probably need to introduce basic math into our interpolation language or something...

It would be very helpful if terraform supported basic math feature or index1 feature.

@tkak It is coming )

Done. We added math support in for int types so you can do things like ${count.index+1} now.

I think there might be a related issue for this, but what about left padding a number to a certain number of digits so you can use the count to create server names like server-01, server-02, etc.?

@jimmycuadra There is a sprintf-style issue on page 1 somewhere. :)

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ketzacoatl picture ketzacoatl  ยท  3Comments

jrnt30 picture jrnt30  ยท  3Comments

thebenwaters picture thebenwaters  ยท  3Comments

rkulagowski picture rkulagowski  ยท  3Comments

franklinwise picture franklinwise  ยท  3Comments