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>
This commit is contained in:
Jakub Sokołowski 2024-08-29 20:02:53 +02:00
parent fb3f174c5b
commit e1244169a3
No known key found for this signature in database
GPG Key ID: FE65CD384D5BF7B4

View File

@ -1,15 +1,30 @@
# 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 = $2
next
old = resource
if (new == "") {
next
}
}
if ($5 == "created") {
new = $2
new = resource
if (new == "") {
next
}
}
printf "terraform state mv '%s' '%s'\n", old, new
if (old != "" && new != "") {
printf "terraform state mv '%s' '%s'\n", old, new
}
old = new = ""
}