@@ -105,44 +105,51 @@ func adaptNetworks(modules terraform.Modules) (networks []compute.Network) {
105
105
return networks
106
106
}
107
107
108
- func expandRange (ports string , attr * terraform. Attribute ) []iacTypes. IntValue {
108
+ func expandRange (ports string , meta iacTypes. Metadata ) (compute. PortRange , bool ) {
109
109
ports = strings .ReplaceAll (ports , " " , "" )
110
110
if ! strings .Contains (ports , "-" ) {
111
111
i , err := strconv .Atoi (ports )
112
112
if err != nil {
113
- return nil
114
- }
115
- return []iacTypes.IntValue {
116
- iacTypes .Int (i , attr .GetMetadata ()),
113
+ return compute.PortRange {}, false
117
114
}
115
+ return compute.PortRange {
116
+ Metadata : meta ,
117
+ Start : iacTypes .Int (i , meta ),
118
+ End : iacTypes .Int (i , meta ),
119
+ }, true
118
120
}
119
121
parts := strings .Split (ports , "-" )
120
122
if len (parts ) != 2 {
121
- return nil
123
+ return compute. PortRange {}, false
122
124
}
123
125
start , err := strconv .Atoi (parts [0 ])
124
126
if err != nil {
125
- return nil
127
+ return compute. PortRange {}, false
126
128
}
127
129
end , err := strconv .Atoi (parts [1 ])
128
130
if err != nil {
129
- return nil
130
- }
131
- var output []iacTypes.IntValue
132
- for i := start ; i <= end ; i ++ {
133
- output = append (output , iacTypes .Int (i , attr .GetMetadata ()))
131
+ return compute.PortRange {}, false
134
132
}
135
- return output
133
+
134
+ return compute.PortRange {
135
+ Metadata : meta ,
136
+ Start : iacTypes .Int (start , meta ),
137
+ End : iacTypes .Int (end , meta ),
138
+ }, true
136
139
}
137
140
138
141
func adaptFirewallRule (firewall * compute.Firewall , firewallBlock , ruleBlock * terraform.Block , allow bool ) {
139
142
protocolAttr := ruleBlock .GetAttribute ("protocol" )
140
143
portsAttr := ruleBlock .GetAttribute ("ports" )
141
144
142
- var ports []iacTypes. IntValue
145
+ var rngs []compute. PortRange
143
146
rawPorts := portsAttr .AsStringValues ()
144
147
for _ , portStr := range rawPorts {
145
- ports = append (ports , expandRange (portStr .Value (), portsAttr )... )
148
+ rng , ok := expandRange (portStr .Value (), portsAttr .GetMetadata ())
149
+ if ! ok {
150
+ continue
151
+ }
152
+ rngs = append (rngs , rng )
146
153
}
147
154
148
155
// ingress by default
@@ -153,7 +160,7 @@ func adaptFirewallRule(firewall *compute.Firewall, firewallBlock, ruleBlock *ter
153
160
Enforced : iacTypes .BoolDefault (true , firewallBlock .GetMetadata ()),
154
161
IsAllow : iacTypes .Bool (allow , ruleBlock .GetMetadata ()),
155
162
Protocol : protocolAttr .AsStringValueOrDefault ("tcp" , ruleBlock ),
156
- Ports : ports ,
163
+ Ports : rngs ,
157
164
}
158
165
159
166
disabledAttr := firewallBlock .GetAttribute ("disabled" )
0 commit comments