Skip to content

Instantly share code, notes, and snippets.

@jpedro
Created March 15, 2019 16:35
Show Gist options
  • Save jpedro/f5bf3f0a40ad97aa00324352c5786528 to your computer and use it in GitHub Desktop.
Save jpedro/f5bf3f0a40ad97aa00324352c5786528 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import hcl
import os
import fnmatch
def checkHcl(file):
# print "==> CHECKING %s" % file
with open(file, "r") as f:
try:
obj = hcl.load(f)
except:
# print "--> NO HCL in %s" % file
return
res = obj.get("resource")
if not res:
# print "--> NO RESOURCES in %s" % file
return
sqls = res.get("google_sql_database_instance")
if not sqls:
# print "--> NO SQL in %s" % file
return
for name, spec in sqls.iteritems():
# Dont rescue. Let it break if theres no backup
enabled = spec["settings"]["backup_configuration"]["enabled"]
print "==> FILE %s" % file
print " NAME %s" % name
print " ENABLED %s" % enabled
print
for root, dir, files in os.walk("gcp"):
for items in fnmatch.filter(files, "*.tf"):
file = root + "/" + items
checkHcl(file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment