Comments (2)
Hi @dbogen,
This is an unfortunate quirk of Terraform v0.11 and earlier: all provider results are either strings, lists of strings, or maps of strings. The bug here is that format
should see that you used %d
and automatically try to convert the string result to an integer, as all other language features do, but instead (because in v0.11 format
is based on Go's formatter) it leaves it as a string but produces invalid output.
This is fixed in both regards in the master
branch of Terraform, in preparation for the forthcoming v0.12.0 release:
- Providers now return full type information for their attributes, allowing Terraform Core to see that the result of
random_integer
is a number rather than a string. - The
format
function is no longer based on Go's ownfmt
package and instead is a custom implementation that understands how to do all of the standard type conversions used in the Terraform language, so that%d
can be used with strings containing decimal digits just as is the case for arithmetic operators on strings, etc.
The random
provider won't need to change at all to benefit from this when running in v0.12.0 mode, except to support the new v0.12.0 plugin protocol. The latest version of this provider is already compatible, so no further changes are required here for it to work. The example you tried here should therefore work as expected in v0.12.0-beta1 and in the forthcoming v0.12.0 release, without any further changes.
To work around this in Terraform v0.11, I'd suggest performing some no-op arithmetic on the result to force the language to convert to integer. For example:
bar_int = "bar-${format("%05d", floor(random_integer.foo.result))}"
Although that will no longer be necessary in Terraform v0.12.0, that additional floor
function won't do any harm there, and so this workaround shouldn't cause any compatibility difficulties during upgrade, allowing you to remove it at your leisure after upgrading.
from terraform-provider-random.
This works as expected in Terraform 0.12 and above.
from terraform-provider-random.
Related Issues (20)
- GitHub Actions - deprecated warnings found - action required! HOT 1
- add "pet_name_length" parameter to the random_pet resource HOT 3
- random_shuffle crashes when result_count=0 HOT 2
- Add prefix and suffix properties HOT 3
- ERROR: API version 2022-05-01 does not have operation group │ 'storage_accounts' HOT 1
- Calculating incorrect bytes on imported resource HOT 1
- Documentation: random_shuffle output is already list HOT 2
- random_pet generating non unique names
- Update Go Module to Go 1.20 Minimum HOT 1
- tyring to upgrade azurerm version but getting below error. HOT 3
- Ambiguous wording in docs on the parameters for RandomPassword, eg "numeric = true" can still generate a password without numerics.
- Resource 'snowflake_grant_privileges_to_role' marks 'priveleges' attribute as changed regardless of any changes being made HOT 2
- random_shuffle need to add position 0 of an array to return 1 single result string HOT 2
- Support UUIDv7
- Enable password cannot have more than 2 repeated characters
- Feature Request: random IP from CIDR range HOT 4
- Feature Request: Random Date HOT 2
- `random_bytes` resource does not explicitly mention being "sufficiently random for cryptographic use HOT 2
- `random_bytes` resource does not explicitly mention being "sufficiently random for cryptographic use" HOT 2
- Improve documentation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-provider-random.