infra-utils/terraform/rename.awk
Jakub Sokołowski e1244169a3
terraform/rename.awk: fix to ignore order of lines
Also ignore resources that are only created or only destroyed.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2024-08-29 20:03:12 +02:00

31 lines
627 B
Awk

# Script for renaming Terraform resources when changing names.
# WARNING: Use '-no-color' flag when running 'terraform plan'.
BEGIN{
old = new = ""
}
/will be/{
resource = $2
if (resource ~ "cloudflare_record") {
next
}
if ($5 == "updated") {
next
}
if ($5 == "destroyed") {
old = resource
if (new == "") {
next
}
}
if ($5 == "created") {
new = resource
if (new == "") {
next
}
}
if (old != "" && new != "") {
printf "terraform state mv '%s' '%s'\n", old, new
}
old = new = ""
}