34
34
"rename" : "pools" ,
35
35
"module" : ""
36
36
},
37
+ {
38
+ "resource_type" : "null_resource" ,
39
+ "name" : "wait_for_zonal_cluster" ,
40
+ "rename" : "wait_for_cluster" ,
41
+ "module" : "" ,
42
+ "plural" : False
43
+ },
37
44
]
38
45
39
46
class ModuleMigration :
@@ -60,6 +67,9 @@ def moves(self):
60
67
if "rename" in migration :
61
68
new .name = migration ["rename" ]
62
69
70
+ old .plural = migration .get ("plural" , True )
71
+ new .plural = migration .get ("plural" , True )
72
+
63
73
pair = (old .path (), new .path ())
64
74
moves .append (pair )
65
75
return moves
@@ -177,7 +187,7 @@ def path(self):
177
187
if parts [0 ] == '' :
178
188
del parts [0 ]
179
189
path = "." .join (parts )
180
- if self .index is not - 1 :
190
+ if self .index is not - 1 and self . plural :
181
191
path = "{0}[{1}]" .format (path , self .index )
182
192
return path
183
193
@@ -276,6 +286,7 @@ def migrate(statefile=None, dryrun=False):
276
286
if dryrun :
277
287
print (" " .join (argv ))
278
288
else :
289
+ argv = [arg .strip ('"' ) for arg in argv ]
279
290
subprocess .run (argv , check = True , encoding = 'utf-8' )
280
291
281
292
def main (argv ):
@@ -285,7 +296,7 @@ def main(argv):
285
296
# print("cp {} {}".format(args.oldstate, args.newstate))
286
297
# shutil.copy(args.oldstate, args.newstate)
287
298
288
- migrate (dryrun = True )
299
+ migrate (dryrun = args . dryrun )
289
300
290
301
def argparser ():
291
302
parser = argparse .ArgumentParser (description = 'Migrate Terraform state' )
@@ -294,9 +305,9 @@ def argparser():
294
305
# 'modified)')
295
306
# parser.add_argument('newstate', metavar='newstate.json',
296
307
# 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.' )
300
311
return parser
301
312
302
313
0 commit comments