Sed spell to ease moving to Terraform 0.13

December 28, 2020 

When moving from older versions of Terraform 0.12.x to latest 0.12.x (now: 0.12.29) you may notice the following warnings:

Warning: Interpolation-only expressions are deprecated                                                                                                                              

  on line 11, in resource "hcloud_server_network" "backup_example_org":                                                                                                 
  11:   server_id = "${}"        

These make sense, but may come as a surprise as earlier 0.12.x versions were perfectly fine with them.

You may have tons of these, so fixing them manually gets tiresome. The fix is not too difficult, but is quite unreadable due to escaping:

ls *.tf|xargs sed -i s/"\"\${\(.*\)}\""/"\1"/g

This basically uses regexp capture groups to get rid of "${}" and leave what's inside the curly braces intact. So, the output looks like this (courtesy of "git diff"):

 resource "hcloud_server_network" "backup_example_org" {
-  server_id = "${}"
-  network_id = "${}"
-  ip = "${var.backup_example_org_private_ip}"
+  server_id =
+  network_id =
+  ip = var.backup_example_org_private_ip

After this there's a good change you're back to

$ terraform validate
Success! The configuration is valid.
Samuli Seppänen
Samuli Seppänen
Author archive