@@ -72,9 +72,9 @@ func (a *sgAdapter) adaptSecurityGroups(modules terraform.Modules) []ec2.Securit
72
72
}
73
73
for _ , sgRule := range orphanResources {
74
74
if sgRule .GetAttribute ("type" ).Equals ("ingress" ) {
75
- orphanage .IngressRules = append (orphanage .IngressRules , adaptSGRule (sgRule , modules ))
75
+ orphanage .IngressRules = append (orphanage .IngressRules , adaptSGRule (sgRule ))
76
76
} else if sgRule .GetAttribute ("type" ).Equals ("egress" ) {
77
- orphanage .EgressRules = append (orphanage .EgressRules , adaptSGRule (sgRule , modules ))
77
+ orphanage .EgressRules = append (orphanage .EgressRules , adaptSGRule (sgRule ))
78
78
}
79
79
}
80
80
securityGroups = append (securityGroups , orphanage )
@@ -116,21 +116,21 @@ func (a *sgAdapter) adaptSecurityGroup(resource *terraform.Block, module terrafo
116
116
117
117
ingressBlocks := resource .GetBlocks ("ingress" )
118
118
for _ , ingressBlock := range ingressBlocks {
119
- ingressRules = append (ingressRules , adaptSGRule (ingressBlock , module ))
119
+ ingressRules = append (ingressRules , adaptSGRule (ingressBlock ))
120
120
}
121
121
122
122
egressBlocks := resource .GetBlocks ("egress" )
123
123
for _ , egressBlock := range egressBlocks {
124
- egressRules = append (egressRules , adaptSGRule (egressBlock , module ))
124
+ egressRules = append (egressRules , adaptSGRule (egressBlock ))
125
125
}
126
126
127
127
rulesBlocks := module .GetReferencingResources (resource , "aws_security_group_rule" , "security_group_id" )
128
128
for _ , ruleBlock := range rulesBlocks {
129
129
a .sgRuleIDs .Resolve (ruleBlock .ID ())
130
130
if ruleBlock .GetAttribute ("type" ).Equals ("ingress" ) {
131
- ingressRules = append (ingressRules , adaptSGRule (ruleBlock , module ))
131
+ ingressRules = append (ingressRules , adaptSGRule (ruleBlock ))
132
132
} else if ruleBlock .GetAttribute ("type" ).Equals ("egress" ) {
133
- egressRules = append (egressRules , adaptSGRule (ruleBlock , module ))
133
+ egressRules = append (egressRules , adaptSGRule (ruleBlock ))
134
134
}
135
135
}
136
136
@@ -154,24 +154,14 @@ func (a *sgAdapter) adaptSecurityGroup(resource *terraform.Block, module terrafo
154
154
}
155
155
}
156
156
157
- func adaptSGRule (resource * terraform.Block , modules terraform. Modules ) ec2.SecurityGroupRule {
157
+ func adaptSGRule (resource * terraform.Block ) ec2.SecurityGroupRule {
158
158
ruleDescAttr := resource .GetAttribute ("description" )
159
159
ruleDescVal := ruleDescAttr .AsStringValueOrDefault ("" , resource )
160
160
161
161
var cidrs []iacTypes.StringValue
162
162
163
163
cidrBlocks := resource .GetAttribute ("cidr_blocks" )
164
164
ipv6cidrBlocks := resource .GetAttribute ("ipv6_cidr_blocks" )
165
- varBlocks := modules .GetBlocks ().OfType ("variable" )
166
-
167
- for _ , vb := range varBlocks {
168
- if cidrBlocks .IsNotNil () && cidrBlocks .ReferencesBlock (vb ) {
169
- cidrBlocks = vb .GetAttribute ("default" )
170
- }
171
- if ipv6cidrBlocks .IsNotNil () && ipv6cidrBlocks .ReferencesBlock (vb ) {
172
- ipv6cidrBlocks = vb .GetAttribute ("default" )
173
- }
174
- }
175
165
176
166
if cidrBlocks .IsNotNil () {
177
167
cidrs = cidrBlocks .AsStringValues ()
@@ -185,6 +175,9 @@ func adaptSGRule(resource *terraform.Block, modules terraform.Modules) ec2.Secur
185
175
Metadata : resource .GetMetadata (),
186
176
Description : ruleDescVal ,
187
177
CIDRs : cidrs ,
178
+ FromPort : resource .GetAttribute ("from_port" ).AsIntValueOrDefault (- 1 , resource ),
179
+ ToPort : resource .GetAttribute ("to_port" ).AsIntValueOrDefault (- 1 , resource ),
180
+ Protocol : resource .GetAttribute ("protocol" ).AsStringValueOrDefault ("" , resource ),
188
181
}
189
182
}
190
183
@@ -203,6 +196,9 @@ func adaptSingleSGRule(resource *terraform.Block) ec2.SecurityGroupRule {
203
196
Metadata : resource .GetMetadata (),
204
197
Description : description ,
205
198
CIDRs : cidrs ,
199
+ FromPort : resource .GetAttribute ("from_port" ).AsIntValueOrDefault (- 1 , resource ),
200
+ ToPort : resource .GetAttribute ("to_port" ).AsIntValueOrDefault (- 1 , resource ),
201
+ Protocol : resource .GetAttribute ("ip_protocol" ).AsStringValueOrDefault ("" , resource ),
206
202
}
207
203
}
208
204
@@ -236,7 +232,7 @@ func adaptNetworkACLRule(resource *terraform.Block) ec2.NetworkACLRule {
236
232
actionVal := actionAttr .AsStringValueOrDefault ("" , resource )
237
233
238
234
protocolAtrr := resource .GetAttribute ("protocol" )
239
- protocolVal := protocolAtrr .AsStringValueOrDefault ("-1 " , resource )
235
+ protocolVal := protocolAtrr .AsStringValueOrDefault ("" , resource )
240
236
241
237
cidrAttr := resource .GetAttribute ("cidr_block" )
242
238
if cidrAttr .IsNotNil () {
@@ -253,5 +249,7 @@ func adaptNetworkACLRule(resource *terraform.Block) ec2.NetworkACLRule {
253
249
Action : actionVal ,
254
250
Protocol : protocolVal ,
255
251
CIDRs : cidrs ,
252
+ FromPort : resource .GetAttribute ("from_port" ).AsIntValueOrDefault (- 1 , resource ),
253
+ ToPort : resource .GetAttribute ("to_port" ).AsIntValueOrDefault (- 1 , resource ),
256
254
}
257
255
}
0 commit comments