I just recently started a new job and the codebase that I inherited is…not great. One of the main problems is that it was written for Terraform 0.11 and was never fully upgraded to 0.12 and the goodies that HCL2 and 0.13 brought with them. Of course this means that I needed to find all of the old-style interpolations in our Terraform code base and replace them with the new format. Luckily with VS Code and a little regex, this is a super easy task. This regex is PCRE so you can also use it with sed/awk too if you prefer the command line.
- Open the Find and Replace panel
- Next to the Find box, click the box that looks like: .*
- Search for:
"\${([a-zA-Z0-9_.]+)}"
(you can visit https://regex101.com/r/K8E5xc/2 for an explanation of how it works along with some examples) - In the Replace box, enter:
$1
- Now when you actually run the search and replace, it’ll pull the interpolated data out of the old-style interpolation by removing the opening
"${
and closing}"
Hopefully this helps some of you who might not be as comfortable with regex clean up your code base and find those old-style interpolations in your Terraform code, since I believe 0.14 will start throwing actual errors and not just warnings on these issues.