@@ -43,7 +43,9 @@ func adaptSecurityGroupRules(deployment azure.Deployment) (rules []network.Secur
4343
4444func adaptSecurityGroupRule (resource azure.Resource ) network.SecurityGroupRule {
4545 sourceAddressPrefixes := resource .Properties .GetMapValue ("sourceAddressPrefixes" ).AsStringValuesList ("" )
46- sourceAddressPrefixes = append (sourceAddressPrefixes , resource .Properties .GetMapValue ("sourceAddressPrefix" ).AsStringValue ("" , resource .Metadata ))
46+ if prefix := resource .Properties .GetMapValue ("sourceAddressPrefix" ).AsStringValue ("" , resource .Metadata ); prefix .IsNotEmpty () {
47+ sourceAddressPrefixes = append (sourceAddressPrefixes , prefix )
48+ }
4749
4850 var sourcePortRanges []common.PortRange
4951 for _ , portRange := range resource .Properties .GetMapValue ("sourcePortRanges" ).AsList () {
@@ -57,7 +59,9 @@ func adaptSecurityGroupRule(resource azure.Resource) network.SecurityGroupRule {
5759 }
5860
5961 destinationAddressPrefixes := resource .Properties .GetMapValue ("destinationAddressPrefixes" ).AsStringValuesList ("" )
60- destinationAddressPrefixes = append (destinationAddressPrefixes , resource .Properties .GetMapValue ("destinationAddressPrefix" ).AsStringValue ("" , resource .Metadata ))
62+ if prefix := resource .Properties .GetMapValue ("destinationAddressPrefix" ).AsStringValue ("" , resource .Metadata ); prefix .IsNotEmpty () {
63+ destinationAddressPrefixes = append (destinationAddressPrefixes , prefix )
64+ }
6165
6266 var destinationPortRanges []common.PortRange
6367 for _ , portRange := range resource .Properties .GetMapValue ("destinationPortRanges" ).AsList () {
@@ -115,12 +119,10 @@ func adaptNetworkWatcherFlowLog(resource azure.Resource) network.NetworkWatcherF
115119}
116120
117121func adaptNetworkInterfaces (deployment azure.Deployment ) []network.NetworkInterface {
118- var networkInterfaces = make ([]network.NetworkInterface , 0 )
119-
122+ var networkInterfaces []network.NetworkInterface
120123 for _ , resource := range deployment .GetResourcesByType ("Microsoft.Network/networkInterfaces" ) {
121124 networkInterfaces = append (networkInterfaces , adaptNetworkInterface (resource , deployment ))
122125 }
123-
124126 return networkInterfaces
125127}
126128
@@ -130,63 +132,29 @@ func adaptNetworkInterface(resource azure.Resource, _ azure.Deployment) network.
130132 EnableIPForwarding : resource .Properties .GetMapValue ("enableIPForwarding" ).AsBoolValue (false , resource .Metadata ),
131133 HasPublicIP : iacTypes .BoolDefault (false , resource .Metadata ),
132134 PublicIPAddress : iacTypes .StringDefault ("" , resource .Metadata ),
133- SecurityGroups : nil ,
134135 SubnetID : iacTypes .StringDefault ("" , resource .Metadata ),
135136 }
136137
137138 ipConfigs := resource .Properties .GetMapValue ("ipConfigurations" ).AsList ()
138139 ni .IPConfigurations = make ([]network.IPConfiguration , 0 , len (ipConfigs ))
139140
140- var primaryConfigSet bool
141-
142141 for _ , ipConfig := range ipConfigs {
143142 if ipConfig .IsNull () {
144143 continue
145144 }
146-
147- ipConfigMeta := resource .Metadata
148- subnetID := ipConfig .GetMapValue ("subnet" ).GetMapValue ("id" ).AsStringValue ("" , resource .Metadata )
149- publicIP := ipConfig .GetMapValue ("publicIPAddress" )
150- hasPublicIP := iacTypes .BoolDefault (false , ipConfigMeta )
151- publicIPAddress := iacTypes .StringDefault ("" , ipConfigMeta )
152- primary := ipConfig .GetMapValue ("primary" ).AsBoolValue (false , ipConfigMeta )
153-
154- if ! publicIP .IsNull () {
155- hasPublicIP = iacTypes .Bool (true , ipConfigMeta )
156- if publicIPID := publicIP .GetMapValue ("id" ).AsStringValue ("" , resource .Metadata ); publicIPID .Value () != "" {
157- publicIPAddress = publicIPID
158- }
159- }
160-
161- ipConfiguration := network.IPConfiguration {
162- Metadata : ipConfigMeta ,
163- HasPublicIP : hasPublicIP ,
164- PublicIPAddress : publicIPAddress ,
165- SubnetID : subnetID ,
166- Primary : primary ,
167- }
168-
169- ni .IPConfigurations = append (ni .IPConfigurations , ipConfiguration )
170-
171- // For backward compatibility, populate the single-value fields with the primary configuration
172- // If no primary is set, use the first configuration
173- isPrimary := primary .Value () || (len (ni .IPConfigurations ) == 1 && ! primaryConfigSet && primary .GetMetadata ().IsDefault ())
174- if isPrimary && ! primaryConfigSet {
175- if subnetID .Value () != "" {
176- ni .SubnetID = subnetID
177- }
178- if hasPublicIP .Value () {
179- ni .HasPublicIP = hasPublicIP
180- if publicIPAddress .Value () != "" {
181- ni .PublicIPAddress = publicIPAddress
182- }
183- }
184- primaryConfigSet = true
185- }
145+ ipConfigProps := ipConfig .GetMapValue ("properties" )
146+ ni .IPConfigurations = append (ni .IPConfigurations , network.IPConfiguration {
147+ Metadata : resource .Metadata ,
148+ PublicIPAddress : ipConfigProps .GetMapValue ("publicIPAddress" ).
149+ GetMapValue ("id" ).AsStringValue ("" , resource .Metadata ),
150+ SubnetID : ipConfigProps .GetMapValue ("subnet" ).
151+ GetMapValue ("id" ).AsStringValue ("" , resource .Metadata ),
152+ Primary : ipConfigProps .GetMapValue ("primary" ).AsBoolValue (false , resource .Metadata ),
153+ })
186154 }
155+ ni .Setup ()
187156
188157 // Note: SecurityGroups are not resolved for ARM templates as related resource search
189158 // is not yet implemented for ARM (parser cannot evaluate expressions/references)
190-
191159 return ni
192160}
0 commit comments