Skip to content

Commit 97023b9

Browse files
committed
bug fixes, bump version
1 parent f657c10 commit 97023b9

File tree

13 files changed

+65
-52
lines changed

13 files changed

+65
-52
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Finally aws2tf runs a `terraform plan` command and there should hopefully be no
2424
+ Python3 (v3.8+)
2525
+ boto3 1.36.13 or later (pip3 install -r requirements.txt).
2626
+ AWS cli (v2) **version 2.22.33 or higher** needs to be installed and you need a login with at least "Read" privileges.
27-
+ Terraform **version v1.8.5** or higher needs to be installed. (recommend you avoid early point releases eg. 1.9.0/1.9.1)
27+
+ Terraform **version v1.10.4** or higher needs to be installed. (recommend you avoid early point releases eg. 1.9.0/1.9.1)
2828
+ jq **version 1.6 or higher**
2929

3030
## Optional but recommended

code/build_lists.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def fetch_tgw_data():
7575

7676
def fetch_roles_data():
7777
try:
78-
client = boto3.client('iam')
78+
client = boto3.client('iam',region_name='us-east-1')
7979
response = []
8080
paginator = client.get_paginator('list_roles')
8181
for page in paginator.paginate():
@@ -90,7 +90,7 @@ def fetch_roles_data():
9090

9191
def fetch_policies_data():
9292
try:
93-
client = boto3.client('iam')
93+
client = boto3.client('iam',region_name='us-east-1')
9494
response = []
9595
paginator = client.get_paginator('list_policies')
9696
for page in paginator.paginate(Scope='Local'):
@@ -126,7 +126,8 @@ def fetch_policies_data():
126126
elif resource_type == 's3':
127127
client = boto3.client('s3')
128128
for _, bucket in result:
129-
#here ?
129+
#here ?
130+
#print("Buck from result=",bucket)
130131
try:
131132
####### problematic call
132133
objs = client.list_objects_v2(Bucket=bucket,MaxKeys=1)
@@ -154,7 +155,6 @@ def fetch_policies_data():
154155
# Handle roles data
155156
with open('imported/roles.json', 'w') as f:
156157
json.dump(result, f, indent=2, default=str)
157-
158158
# slower - 3m 29s
159159
#### role attachments stuff
160160

@@ -177,7 +177,7 @@ def build_secondary_lists(id=None):
177177
globals.tracking_message = "Stage 2 of 10, Building secondary IAM resource lists ..."
178178

179179
def fetch_role_policies(role_name):
180-
client = boto3.client('iam')
180+
client = boto3.client('iam',region_name='us-east-1')
181181
try:
182182
# Get attached policies
183183
attached_policies = client.list_attached_role_policies(RoleName=role_name)

code/common.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,19 @@ def call_resource(type, id):
180180

181181
if clfn == "vpc-lattice": getfn = getattr(eval("aws_vpc_lattice"), "get_"+type)
182182
elif clfn == "redshift-serverless": getfn = getattr(eval("aws_redshift_serverless"), "get_"+type)
183-
elif clfn == "s3": getfn = getattr(eval("aws_s3"), "get_"+type)
183+
elif clfn == "s3":
184+
#print("-1aa- clfn:"+clfn+" type:"+type)
185+
getfn = getattr(eval("aws_s3"), "get_"+type)
184186
#elif clfn == "s3": getfn = getattr(ast.literal_eval("aws_s3"), "get_"+type)
185187

186188
else:
187-
# print("-1aa- clfn:"+clfn+" type:"+type)
189+
#print("-1aa- clfn:"+clfn+" type:"+type)
188190
mclfn = clfn.replace("-", "_")
189-
# print("-1ab- mclfn:"+mclfn+" type:"+type)
191+
#print("-1ab- mclfn:"+mclfn+" type:"+type)
190192
getfn = getattr(eval("aws_"+mclfn), "get_"+type)
191193
#print("-1ac- clfn:"+clfn+" type:"+type)
192194

195+
#print("type",type, "id",id, "clfn",clfn, "descfn",descfn, "topkey", topkey,"key",key, "filterid",filterid)
193196
sr = getfn(type, id, clfn, descfn, topkey, key, filterid)
194197

195198
except AttributeError as e:
@@ -818,7 +821,7 @@ def aws_tf(region,args):
818821

819822
with open("provider.tf", 'w') as f3:
820823
f3.write('terraform {\n')
821-
f3.write(' required_version = "> 1.9.5"\n')
824+
f3.write(' required_version = "> 1.10.4"\n')
822825
f3.write(' required_providers {\n')
823826
f3.write(' aws = {\n')
824827
f3.write(' source = "hashicorp/aws"\n')

code/fixtf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,8 @@ def deref_array(t1,tt1,tt2,ttft,prefix,skip):
705705

706706

707707
def deref_role_arn(t1,tt1,tt2):
708+
if tt2 == "null" or tt2 == "[]": return t1
709+
708710
if tt2.startswith("arn:aws:events:"): print(tt2)
709711

710712
if tt2.startswith("arn:aws:s3:::"):
@@ -761,6 +763,7 @@ def deref_s3(t1, tt1, tt2):
761763

762764
#if tt1 == "security_groups": t1,skip = deref_array(t1,tt1,tt2,"aws_security_group","sg-",skip)
763765
def deref_role_arn_array(t1,tt1,tt2):
766+
764767
if tt2 == "null" or tt2 == "[]": return t1
765768
tt2=tt2.replace('"','').replace(' ','').replace('[','').replace(']','')
766769
cc=tt2.count(',')
@@ -844,7 +847,7 @@ def deref_elb_arn_array(t1,tt1,tt2):
844847

845848
#### other arn derefs here
846849
def generic_deref_arn(t1, tt1, tt2):
847-
850+
print("Here",t1)
848851
try:
849852
if tt2.endswith("*"): return t1
850853
print("*** generic "+t1)

code/fixtf_aws_resources/fixtf_application_autoscaling.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ def aws_appautoscaling_scheduled_action(t1,tt1,tt2,flag1,flag2):
1111

1212
def aws_appautoscaling_target(t1,tt1,tt2,flag1,flag2):
1313
skip=0
14-
#if tt1 == "role_arn":
15-
# if ":role/aws-service-role" in tt2:
16-
# t1=fixtf.globals_replace(t1,tt1,tt2)
17-
# else:
18-
# if tt2 != "null":
19-
# if ":" in tt2: tt2=tt2.split("/")[-1]
20-
# t1=tt1 + " = aws_iam_role." + tt2 + ".arn\n"
21-
# common.add_dependancy("aws_iam_role",tt2)
14+
2215
return skip,t1,flag1,flag2
2316

code/fixtf_aws_resources/fixtf_dynamodb.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def aws_dynamodb_kinesis_streaming_destination(t1,tt1,tt2,flag1,flag2):
1414

1515
def aws_dynamodb_table(t1,tt1,tt2,flag1,flag2):
1616
skip=0
17+
if tt1=="recovery_period_in_days" and tt2=="0":
18+
skip=1
1719
return skip,t1,flag1,flag2
1820

1921
def aws_dynamodb_table_item(t1,tt1,tt2,flag1,flag2):

code/fixtf_aws_resources/fixtf_ecs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ def aws_ecs_cluster(t1,tt1,tt2,flag1,flag2):
88
if tt1 == "namespace":
99
if "arn:" in tt2: t1=fixtf.globals_replace(t1,tt1,tt2)
1010

11-
12-
1311
return skip,t1,flag1,flag2
1412

1513
def aws_ecs_account_setting_default(t1,tt1,tt2,flag1,flag2):

code/fixtf_aws_resources/fixtf_lambda.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def aws_lambda_function(t1,tt1,tt2,flag1,flag2):
3535

3636
if tt2 == "null": skip=1
3737

38-
38+
###### layers code
3939
elif tt1 == "layers" and tt2!="[]":
4040
if tt2 != "null" and "arn:" in tt2:
4141
cc=tt2.count(',')
@@ -49,28 +49,31 @@ def aws_lambda_function(t1,tt1,tt2,flag1,flag2):
4949
for i in range(cc+1):
5050
subn=tt2.split(',')[i]
5151
subn=subn.strip(" ").lstrip('"').rstrip('"').strip(" ")
52-
53-
tarn=subn.replace("/","_").replace(".","_").replace(":","_").replace("|","_").replace("$","_").replace(",","_").replace("&","_").replace("#","_").replace("[","_").replace("]","_").replace("=","_").replace("!","_").replace(";","_")
54-
common.add_dependancy("aws_lambda_layer_version",subn)
55-
builds=builds+"aws_lambda_layer_version."+tarn+".arn,"
52+
if globals.acc in subn:
53+
tarn=subn.replace("/","_").replace(".","_").replace(":","_").replace("|","_").replace("$","_").replace(",","_").replace("&","_").replace("#","_").replace("[","_").replace("]","_").replace("=","_").replace("!","_").replace(";","_")
54+
common.add_dependancy("aws_lambda_layer_version",subn)
55+
builds=builds+"aws_lambda_layer_version."+tarn+".arn,"
56+
else:
57+
builds=builds+"\""+subn+"\", "
5658

5759
if builds.endswith(','):
5860
builds=builds.rstrip(',')
5961
t1 = tt1+" = ["+builds+"]\n"
6062

6163
elif cc == 0:
62-
tt2=tt2.lstrip('"').rstrip('"')
63-
larn=tt2.split(":")[:-1]
64-
myarn=""
65-
for ta in larn:
66-
myarn=myarn+ta+":"
67-
68-
myarn=myarn.rstrip(":")
69-
tarn=tt2.replace("/","_").replace(".","_").replace(":","_").replace("|","_").replace("$","_").replace(",","_").replace("&","_").replace("#","_").replace("[","_").replace("]","_").replace("=","_").replace("!","_").replace(";","_")
70-
# test we can get at it before sub
71-
72-
t1 = tt1+" = [aws_lambda_layer_version."+tarn+ ".arn]\n"
73-
common.add_dependancy("aws_lambda_layer_version",tt2)
64+
if globals.acc in tt2:
65+
tt2=tt2.lstrip('"').rstrip('"')
66+
larn=tt2.split(":")[:-1]
67+
myarn=""
68+
for ta in larn:
69+
myarn=myarn+ta+":"
70+
71+
myarn=myarn.rstrip(":")
72+
tarn=tt2.replace("/","_").replace(".","_").replace(":","_").replace("|","_").replace("$","_").replace(",","_").replace("&","_").replace("#","_").replace("[","_").replace("]","_").replace("=","_").replace("!","_").replace(";","_")
73+
# test we can get at it before sub
74+
75+
t1 = tt1+" = [aws_lambda_layer_version."+tarn+ ".arn]\n"
76+
common.add_dependancy("aws_lambda_layer_version",tt2)
7477

7578
return skip,t1,flag1,flag2
7679

code/fixtf_aws_resources/fixtf_networkmanager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import common
2+
import globals
23

34
def aws_networkmanager_attachment_accepter(t1,tt1,tt2,flag1,flag2):
45
skip=0
@@ -97,9 +98,11 @@ def aws_networkmanager_transit_gateway_registration(t1,tt1,tt2,flag1,flag2):
9798
if tt1=="global_network_id" and tt2 !="null":
9899
t1=tt1+" = aws_networkmanager_global_network."+tt2+".id\n"
99100
elif tt1=="transit_gateway_arn" and tt2 !="null":
100-
tgid=tt2.split("/")[-1]
101-
t1=tt1+" = aws_ec2_transit_gateway."+tgid+".arn\n"
102-
common.add_dependancy("aws_ec2_transit_gateway",tgid)
101+
if tt2.startswith("arn:"):
102+
tgid=tt2.split("/")[-1]
103+
if tgid in str(globals.tgwlist.keys()):
104+
t1=tt1+" = aws_ec2_transit_gateway."+tgid+".arn\n"
105+
common.add_dependancy("aws_ec2_transit_gateway",tgid)
103106
return skip,t1,flag1,flag2
104107

105108
def aws_networkmanager_transit_gateway_route_table_attachment(t1,tt1,tt2,flag1,flag2):

code/get_aws_resources/aws_iam.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ def get_aws_iam_role(type,id,clfn,descfn,topkey,key,filterid):
287287

288288

289289
try:
290-
client = boto3.client(clfn)
290+
# hardcode to us-east-1 for iam
291+
client = boto3.client(clfn,region_name='us-east-1')
291292
response = []
292293
if id is None:
293294

0 commit comments

Comments
 (0)