@@ -150,7 +150,22 @@ func (c *Client) getStorageAccount(ctx context.Context, resourceGroupName, accou
150
150
return resp .Account , nil
151
151
}
152
152
153
- func (c * Client ) GetVNetByTag (ctx context.Context , resourceGroupName , tagKey string , tagValues ... string ) (armnetwork.VirtualNetwork , error ) {
153
+ func (c * Client ) vnetHasAnyTag (vnet armnetwork.VirtualNetwork , tagFilter map [string ][]string ) bool {
154
+ for tagKey , tagValues := range tagFilter {
155
+ tag , ok := vnet .Tags [tagKey ]
156
+ if ! ok {
157
+ continue
158
+ }
159
+ for _ , tagValue := range tagValues {
160
+ if * tag == tagValue {
161
+ return true
162
+ }
163
+ }
164
+ }
165
+ return false
166
+ }
167
+
168
+ func (c * Client ) GetVNetByTags (ctx context.Context , resourceGroupName string , tagFilter map [string ][]string ) (armnetwork.VirtualNetwork , error ) {
154
169
client , err := armnetwork .NewVirtualNetworksClient (c .subscriptionID , c .creds , & arm.ClientOptions {
155
170
ClientOptions : * c .clientOpts ,
156
171
})
@@ -165,19 +180,13 @@ func (c *Client) GetVNetByTag(ctx context.Context, resourceGroupName, tagKey str
165
180
return armnetwork.VirtualNetwork {}, err
166
181
}
167
182
for _ , vnet := range page .Value {
168
- tag , ok := vnet .Tags [tagKey ]
169
- if ! ok {
170
- continue
171
- }
172
- for _ , tagValue := range tagValues {
173
- if * tag == tagValue {
174
- return * vnet , nil
175
- }
183
+ if c .vnetHasAnyTag (* vnet , tagFilter ) {
184
+ return * vnet , nil
176
185
}
177
186
}
178
187
}
179
188
180
- return armnetwork.VirtualNetwork {}, fmt .Errorf ("vnet with tag '%s: % v' not found" , tagKey , tagValues )
189
+ return armnetwork.VirtualNetwork {}, fmt .Errorf ("vnet with tags '%+ v' not found" , tagFilter )
181
190
}
182
191
183
192
func (c * Client ) GetSubnetsByVNet (ctx context.Context , resourceGroupName , vnetName string ) (armnetwork.Subnet , error ) {
0 commit comments