Escape Terraform Unsafe Characters instead of Replacing with --
#263
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, characters that could not be used in Terraform identifiers were replaced by
--
. This behavior cloud lead to a resource name collision, for example(example)
and[example]
would generate--example--
.Instead of replacing those characters with a fixed string, we can escape those characters making any two different string generate a unique Terraform identifier.
As specified in Terraform's documentation,
-
character is a valid identifier character, although it is not recommended to be used and_
should be used instead. So I used-
as an escape character.Everything that is not
_
and is not between0
and9
,A
andZ
, anda
andz
should be escaped,-
included. To escape characters we could simply use the character's Unicode value, so even emojis could be used on resources' identifier and generate a safe Terraform identifier.~
would become-007E-
!
would become-0021-
@
would become-0040-
-
would become-002D-
If a resource was named as
3x 4mp !3
it now would be identified astfer--3x-0020-4mp-0009--0021-3
on Terraform.