Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awsandy committed Oct 5, 2024
1 parent 26c55c2 commit 82c0129
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
4 changes: 1 addition & 3 deletions .python/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def call_resource(type, id):


def tfplan1():
print("Terraform Plan - Dependancies Detection Loop ...")

rf = "resources.out"
# com="terraform plan -generate-config-out="+ rf + " -out tfplan -json > plan2.json"

Expand All @@ -240,8 +240,6 @@ def tfplan1():
com = "mv aws_*.tf imported"
rout = rc(com)



com = "terraform plan -generate-config-out=" + \
rf + " -out tfplan -json > plan1.json"
print(com)
Expand Down
1 change: 1 addition & 0 deletions .python/fixtf_aws_resources/aws_not_implemented.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#
"aws_appstream_directory_config": True,
"aws_appstream_fleet_stack_association": True,
"aws_appstream_stack": True,
"aws_appstream_user_stack_association": True,
"aws_appsync_api_cache": True,
"aws_appsync_domain_name_api_association": True,
Expand Down
3 changes: 2 additions & 1 deletion .python/fixtf_aws_resources/fixtf_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
def aws_glue_crawler(t1,tt1,tt2,flag1,flag2):
skip=0
if tt1 == "database_name" and tt2 != "null":
t1 = tt1 + " = aws_glue_catalog_database.d-"+globals.acc+"__"+tt2+".name\n"
if globals.gluedbs[tt2]:
t1 = tt1 + " = aws_glue_catalog_database.d-"+globals.acc+"__"+tt2+".name\n"
#common.add_dependancy("aws_glue_catalog_database",tt2)

elif tt1 == "sample_size":
Expand Down
31 changes: 25 additions & 6 deletions .python/get_aws_resources/aws_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import boto3
import globals
import inspect
import sys

def get_aws_glue_catalog_database(type, id, clfn, descfn, topkey, key, filterid):

if globals.debug:
print("--> In get_aws_glue_catalog_database doing " + type + ' with id ' + str(id) +
print("--> Inn get_aws_glue_catalog_database doing " + type + ' with id ' + str(id) +
" clfn="+clfn+" descfn="+descfn+" topkey="+topkey+" key="+key+" filterid="+filterid)

try:
Expand All @@ -22,11 +23,13 @@ def get_aws_glue_catalog_database(type, id, clfn, descfn, topkey, key, filterid)
tfid="d-"+pkey.replace(":","__")
common.write_import(type,pkey,tfid)
common.add_dependancy("aws_glue_catalog_table",pkey)
globals.gluedbs[j[key]]=True

#pkey2="aws_glue_catalog_table."+pkey
#globals.rproc[pkey2]=True

else:
if ":" in id: id =id.split(":")[1]
if ":" in id: id =id.split(":")[1]
response = client.get_database(Name=id)
if response == []:
print("Empty response for "+type+ " id="+str(id)+" returning")
Expand All @@ -37,14 +40,26 @@ def get_aws_glue_catalog_database(type, id, clfn, descfn, topkey, key, filterid)
pkey=globals.acc+":"+j[key]
tfid="d-"+pkey.replace(":","__")
common.write_import(type,pkey,tfid)
globals.gluedbs[j[key]]=True
#print("KD add aws_glue_catalog_table "+pkey)
common.add_dependancy("aws_glue_catalog_table",pkey)
gkey="aws_glue_catalog_table."+pkey
globals.rproc[gkey]=True


except Exception as e:
common.handle_error(e,str(inspect.currentframe().f_code.co_name),clfn,descfn,topkey,id)
exc_type, exc_obj, exc_tb = sys.exc_info()
exn=str(exc_type.__name__)
if exn=="AccessDeniedException" and "Insufficient Lake Formation permission" in str(e):
print("AccessDeniedException - Insufficient Lake Formation permission for",type,id)
if id is not None:
if ":" in id: id =id.split(":")[1]
pkey=globals.acc+":"+id
gkey="aws_glue_catalog_database."+pkey

globals.rproc[gkey]=True
else:
common.handle_error(e,str(inspect.currentframe().f_code.co_name),clfn,descfn,topkey,id)

return True

Expand Down Expand Up @@ -75,16 +90,20 @@ def get_aws_glue_catalog_table(type, id, clfn, descfn, topkey, key, filterid):


tkey="aws_glue_catalog_table"+"."+catalogn+":"+databasen

#print(catalogn, databasen, tabnam,cc)
response = []
client = boto3.client(clfn)

if cc == 1:
response = client.get_tables(CatalogId=catalogn,DatabaseName=databasen)
if cc == 2:
response = client.get_tables(CatalogId=catalogn,DatabaseName=databasen,Expression=tabnam)

if response == []: print("Empty response for "+type+ " id="+str(id)+" returning"); return True

if response[topkey] == []:
print("Empty response for "+type+ " id="+str(id)+" returning");
tkey="aws_glue_catalog_table"+"."+catalogn+":"+databasen
globals.rproc[tkey]=True
return True
for j in response[topkey]:
#Terraform import id = "123456789012:MyDatabase:MyTable"
pkey=catalogn+":"+databasen+":"+j[key]
Expand Down
1 change: 1 addition & 0 deletions .python/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@
rolelist={}
bucketlist={}
tgwlist={}
gluedbs={}
2 changes: 1 addition & 1 deletion aws2tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def main():
lc = lc + 1

# go again plan and split / fix

print("Terraform Plan - Dependancies Detection Loop "+str(lc)+".....")

x=glob.glob("import__aws_*.tf")
#print(str(x))
Expand Down

0 comments on commit 82c0129

Please sign in to comment.