Skip to content

Instantly share code, notes, and snippets.

@rickardp
Last active September 13, 2022 20:48
Show Gist options
  • Save rickardp/af27a8f25fe7b8d80fda4d46cc55fab9 to your computer and use it in GitHub Desktop.
Save rickardp/af27a8f25fe7b8d80fda4d46cc55fab9 to your computer and use it in GitHub Desktop.
when your tf state is f*cked
import sys
import re
s=sys.stdin.read()
m = re.compile(r"Error: A resource with the ID \"([^\"]+)\"")
n = re.compile(r" with (.+)$")
x = False
val = None
for l in s.split("\n"):
f = m.match(l)
if f:
val = f.groups()[0].strip()
g = n.match(l)
if g and val is not None:
print(("terraform import '%s' '%s'" %(g.groups()[0].strip().strip(',').strip(), val)).replace('/providers/microsoft.insights/diagnosticSettings/','|'))
val = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment