Skip to content

Commit 4461904

Browse files
committed
Fix migration script
1 parent 3b98ff4 commit 4461904

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

helpers/migrate.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
"rename": "pools",
3535
"module": ""
3636
},
37+
{
38+
"resource_type": "null_resource",
39+
"name": "wait_for_zonal_cluster",
40+
"rename": "wait_for_cluster",
41+
"module": "",
42+
"plural": False
43+
},
3744
]
3845

3946
class ModuleMigration:
@@ -60,6 +67,9 @@ def moves(self):
6067
if "rename" in migration:
6168
new.name = migration["rename"]
6269

70+
old.plural = migration.get("plural", True)
71+
new.plural = migration.get("plural", True)
72+
6373
pair = (old.path(), new.path())
6474
moves.append(pair)
6575
return moves
@@ -177,7 +187,7 @@ def path(self):
177187
if parts[0] == '':
178188
del parts[0]
179189
path = ".".join(parts)
180-
if self.index is not -1:
190+
if self.index is not -1 and self.plural:
181191
path = "{0}[{1}]".format(path, self.index)
182192
return path
183193

@@ -276,6 +286,7 @@ def migrate(statefile=None, dryrun=False):
276286
if dryrun:
277287
print(" ".join(argv))
278288
else:
289+
argv = [arg.strip('"') for arg in argv]
279290
subprocess.run(argv, check=True, encoding='utf-8')
280291

281292
def main(argv):
@@ -285,7 +296,7 @@ def main(argv):
285296
# print("cp {} {}".format(args.oldstate, args.newstate))
286297
# shutil.copy(args.oldstate, args.newstate)
287298

288-
migrate(dryrun=True)
299+
migrate(dryrun=args.dryrun)
289300

290301
def argparser():
291302
parser = argparse.ArgumentParser(description='Migrate Terraform state')
@@ -294,9 +305,9 @@ def argparser():
294305
# 'modified)')
295306
# parser.add_argument('newstate', metavar='newstate.json',
296307
# help='The path to the new state file')
297-
# parser.add_argument('--dryrun', action='store_true',
298-
# help='Print the `terraform state mv` commands instead '
299-
# 'of running the commands.')
308+
parser.add_argument('--dryrun', action='store_true',
309+
help='Print the `terraform state mv` commands instead '
310+
'of running the commands.')
300311
return parser
301312

302313

0 commit comments

Comments
 (0)