sigs.k8s.io/cluster-api-provider-azure@v1.17.0/azure/services/networkinterfaces/spec_test.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package networkinterfaces
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
    24  	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4"
    25  	. "github.com/onsi/gomega"
    26  	"github.com/onsi/gomega/format"
    27  	"k8s.io/utils/ptr"
    28  	"sigs.k8s.io/cluster-api-provider-azure/azure/services/resourceskus"
    29  )
    30  
    31  var (
    32  	fakeMissingSKUNICSpec = NICSpec{
    33  		Name:                  "my-net-interface",
    34  		ResourceGroup:         "my-rg",
    35  		Location:              "fake-location",
    36  		SubscriptionID:        "123",
    37  		MachineName:           "azure-test1",
    38  		SubnetName:            "my-subnet",
    39  		VNetName:              "my-vnet",
    40  		VNetResourceGroup:     "my-rg",
    41  		PublicLBName:          "my-public-lb",
    42  		AcceleratedNetworking: nil,
    43  		ClusterName:           "my-cluster",
    44  	}
    45  	fakeSku = resourceskus.SKU{
    46  		Name: ptr.To("Standard_D2v2"),
    47  		Kind: ptr.To(string(resourceskus.VirtualMachines)),
    48  		Locations: []*string{
    49  			ptr.To("fake-location"),
    50  		},
    51  		LocationInfo: []*armcompute.ResourceSKULocationInfo{
    52  			{
    53  				Location: ptr.To("fake-location"),
    54  				Zones:    []*string{ptr.To("1")},
    55  			},
    56  		},
    57  		Capabilities: []*armcompute.ResourceSKUCapabilities{
    58  			{
    59  				Name:  ptr.To(resourceskus.AcceleratedNetworking),
    60  				Value: ptr.To(string(resourceskus.CapabilitySupported)),
    61  			},
    62  		},
    63  	}
    64  
    65  	fakeCustomDNSServers = []string{"123.123.123.123", "124.124.124.124"}
    66  
    67  	fakeStaticPrivateIPNICSpec = NICSpec{
    68  		Name:                    "my-net-interface",
    69  		ResourceGroup:           "my-rg",
    70  		Location:                "fake-location",
    71  		SubscriptionID:          "123",
    72  		MachineName:             "azure-test1",
    73  		SubnetName:              "my-subnet",
    74  		VNetName:                "my-vnet",
    75  		VNetResourceGroup:       "my-rg",
    76  		PublicLBName:            "my-public-lb",
    77  		PublicLBAddressPoolName: "cluster-name-outboundBackendPool",
    78  		StaticIPAddress:         "fake.static.ip",
    79  		AcceleratedNetworking:   nil,
    80  		SKU:                     &fakeSku,
    81  		ClusterName:             "my-cluster",
    82  	}
    83  
    84  	fakeDynamicPrivateIPNICSpec = NICSpec{
    85  		Name:                    "my-net-interface",
    86  		ResourceGroup:           "my-rg",
    87  		Location:                "fake-location",
    88  		SubscriptionID:          "123",
    89  		MachineName:             "azure-test1",
    90  		SubnetName:              "my-subnet",
    91  		VNetName:                "my-vnet",
    92  		VNetResourceGroup:       "my-rg",
    93  		PublicLBName:            "my-public-lb",
    94  		PublicLBAddressPoolName: "cluster-name-outboundBackendPool",
    95  		AcceleratedNetworking:   nil,
    96  		SKU:                     &fakeSku,
    97  		ClusterName:             "my-cluster",
    98  	}
    99  
   100  	fakeControlPlaneNICSpec = NICSpec{
   101  		Name:                      "my-net-interface",
   102  		ResourceGroup:             "my-rg",
   103  		Location:                  "fake-location",
   104  		SubscriptionID:            "123",
   105  		MachineName:               "azure-test1",
   106  		SubnetName:                "my-subnet",
   107  		VNetName:                  "my-vnet",
   108  		VNetResourceGroup:         "my-rg",
   109  		PublicLBName:              "my-public-lb",
   110  		PublicLBAddressPoolName:   "my-public-lb-backendPool",
   111  		PublicLBNATRuleName:       "azure-test1",
   112  		InternalLBName:            "my-internal-lb",
   113  		InternalLBAddressPoolName: "my-internal-lb-backendPool",
   114  		AcceleratedNetworking:     nil,
   115  		SKU:                       &fakeSku,
   116  		ClusterName:               "my-cluster",
   117  	}
   118  
   119  	fakeAcceleratedNetworkingNICSpec = NICSpec{
   120  		Name:                  "my-net-interface",
   121  		ResourceGroup:         "my-rg",
   122  		Location:              "fake-location",
   123  		SubscriptionID:        "123",
   124  		MachineName:           "azure-test1",
   125  		SubnetName:            "my-subnet",
   126  		VNetName:              "my-vnet",
   127  		VNetResourceGroup:     "my-rg",
   128  		PublicLBName:          "my-public-lb",
   129  		AcceleratedNetworking: nil,
   130  		SKU:                   &fakeSku,
   131  		ClusterName:           "my-cluster",
   132  	}
   133  
   134  	fakeNonAcceleratedNetworkingNICSpec = NICSpec{
   135  		Name:                  "my-net-interface",
   136  		ResourceGroup:         "my-rg",
   137  		Location:              "fake-location",
   138  		SubscriptionID:        "123",
   139  		MachineName:           "azure-test1",
   140  		SubnetName:            "my-subnet",
   141  		VNetName:              "my-vnet",
   142  		VNetResourceGroup:     "my-rg",
   143  		PublicLBName:          "my-public-lb",
   144  		AcceleratedNetworking: ptr.To(false),
   145  		ClusterName:           "my-cluster",
   146  	}
   147  
   148  	fakeIpv6NICSpec = NICSpec{
   149  		Name:                  "my-net-interface",
   150  		ResourceGroup:         "my-rg",
   151  		Location:              "fake-location",
   152  		SubscriptionID:        "123",
   153  		MachineName:           "azure-test1",
   154  		SubnetName:            "my-subnet",
   155  		VNetName:              "my-vnet",
   156  		IPv6Enabled:           true,
   157  		VNetResourceGroup:     "my-rg",
   158  		PublicLBName:          "my-public-lb",
   159  		AcceleratedNetworking: nil,
   160  		SKU:                   &fakeSku,
   161  		EnableIPForwarding:    true,
   162  		ClusterName:           "my-cluster",
   163  	}
   164  
   165  	fakeControlPlaneCustomDNSSettingsNICSpec = NICSpec{
   166  		Name:                      "my-net-interface",
   167  		ResourceGroup:             "my-rg",
   168  		Location:                  "fake-location",
   169  		SubscriptionID:            "123",
   170  		MachineName:               "azure-test1",
   171  		SubnetName:                "my-subnet",
   172  		VNetName:                  "my-vnet",
   173  		VNetResourceGroup:         "my-rg",
   174  		PublicLBName:              "my-public-lb",
   175  		PublicLBAddressPoolName:   "my-public-lb-backendPool",
   176  		PublicLBNATRuleName:       "azure-test1",
   177  		InternalLBName:            "my-internal-lb",
   178  		InternalLBAddressPoolName: "my-internal-lb-backendPool",
   179  		AcceleratedNetworking:     nil,
   180  		SKU:                       &fakeSku,
   181  		DNSServers:                fakeCustomDNSServers,
   182  		ClusterName:               "my-cluster",
   183  	}
   184  	fakeDefaultIPconfigNICSpec = NICSpec{
   185  		Name:                  "my-net-interface",
   186  		ResourceGroup:         "my-rg",
   187  		Location:              "fake-location",
   188  		SubscriptionID:        "123",
   189  		MachineName:           "azure-test1",
   190  		SubnetName:            "my-subnet",
   191  		VNetName:              "my-vnet",
   192  		IPv6Enabled:           false,
   193  		VNetResourceGroup:     "my-rg",
   194  		PublicLBName:          "my-public-lb",
   195  		AcceleratedNetworking: nil,
   196  		SKU:                   &fakeSku,
   197  		EnableIPForwarding:    true,
   198  		IPConfigs:             []IPConfig{},
   199  		ClusterName:           "my-cluster",
   200  	}
   201  	fakeOneIPconfigNICSpec = NICSpec{
   202  		Name:                  "my-net-interface",
   203  		ResourceGroup:         "my-rg",
   204  		Location:              "fake-location",
   205  		SubscriptionID:        "123",
   206  		MachineName:           "azure-test1",
   207  		SubnetName:            "my-subnet",
   208  		VNetName:              "my-vnet",
   209  		IPv6Enabled:           false,
   210  		VNetResourceGroup:     "my-rg",
   211  		PublicLBName:          "my-public-lb",
   212  		AcceleratedNetworking: nil,
   213  		SKU:                   &fakeSku,
   214  		EnableIPForwarding:    true,
   215  		IPConfigs:             []IPConfig{{}},
   216  		ClusterName:           "my-cluster",
   217  	}
   218  	fakeTwoIPconfigNICSpec = NICSpec{
   219  		Name:                  "my-net-interface",
   220  		ResourceGroup:         "my-rg",
   221  		Location:              "fake-location",
   222  		SubscriptionID:        "123",
   223  		MachineName:           "azure-test1",
   224  		SubnetName:            "my-subnet",
   225  		VNetName:              "my-vnet",
   226  		IPv6Enabled:           false,
   227  		VNetResourceGroup:     "my-rg",
   228  		PublicLBName:          "my-public-lb",
   229  		AcceleratedNetworking: nil,
   230  		SKU:                   &fakeSku,
   231  		EnableIPForwarding:    true,
   232  		IPConfigs:             []IPConfig{{}, {}},
   233  		ClusterName:           "my-cluster",
   234  	}
   235  	fakeTwoIPconfigWithPublicNICSpec = NICSpec{
   236  		Name:                  "my-net-interface",
   237  		ResourceGroup:         "my-rg",
   238  		Location:              "fake-location",
   239  		SubscriptionID:        "123",
   240  		MachineName:           "azure-test1",
   241  		SubnetName:            "my-subnet",
   242  		VNetName:              "my-vnet",
   243  		IPv6Enabled:           false,
   244  		VNetResourceGroup:     "my-rg",
   245  		PublicIPName:          "pip-azure-test1",
   246  		AcceleratedNetworking: nil,
   247  		SKU:                   &fakeSku,
   248  		EnableIPForwarding:    true,
   249  		IPConfigs:             []IPConfig{{}, {}},
   250  		ClusterName:           "my-cluster",
   251  	}
   252  )
   253  
   254  func TestParameters(t *testing.T) {
   255  	testcases := []struct {
   256  		name          string
   257  		spec          *NICSpec
   258  		existing      interface{}
   259  		expect        func(g *WithT, result interface{})
   260  		expectedError string
   261  	}{
   262  		{
   263  			name:     "error when accelerted networking is nil and no SKU is present",
   264  			spec:     &fakeMissingSKUNICSpec,
   265  			existing: nil,
   266  			expect: func(g *WithT, result interface{}) {
   267  				g.Expect(result).To(BeNil())
   268  			},
   269  			expectedError: "unable to get required network interface SKU from machine cache",
   270  		},
   271  		{
   272  			name:     "get parameters for network interface with static private IP",
   273  			spec:     &fakeStaticPrivateIPNICSpec,
   274  			existing: nil,
   275  			expect: func(g *WithT, result interface{}) {
   276  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   277  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   278  					Tags: map[string]*string{
   279  						"Name": ptr.To("my-net-interface"),
   280  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   281  					},
   282  					Location: ptr.To("fake-location"),
   283  					Properties: &armnetwork.InterfacePropertiesFormat{
   284  						Primary:                     nil,
   285  						EnableAcceleratedNetworking: ptr.To(true),
   286  						EnableIPForwarding:          ptr.To(false),
   287  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   288  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   289  							{
   290  								Name: ptr.To("pipConfig"),
   291  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   292  									Primary:                         ptr.To(true),
   293  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/cluster-name-outboundBackendPool")}},
   294  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodStatic),
   295  									PrivateIPAddress:                ptr.To("fake.static.ip"),
   296  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   297  								},
   298  							},
   299  						},
   300  					},
   301  				}))
   302  			},
   303  			expectedError: "",
   304  		},
   305  		{
   306  			name:     "get parameters for network interface with dynamic private IP",
   307  			spec:     &fakeDynamicPrivateIPNICSpec,
   308  			existing: nil,
   309  			expect: func(g *WithT, result interface{}) {
   310  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   311  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   312  					Tags: map[string]*string{
   313  						"Name": ptr.To("my-net-interface"),
   314  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   315  					},
   316  					Location: ptr.To("fake-location"),
   317  					Properties: &armnetwork.InterfacePropertiesFormat{
   318  						EnableAcceleratedNetworking: ptr.To(true),
   319  						EnableIPForwarding:          ptr.To(false),
   320  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   321  						Primary:                     nil,
   322  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   323  							{
   324  								Name: ptr.To("pipConfig"),
   325  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   326  									Primary:                         ptr.To(true),
   327  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/cluster-name-outboundBackendPool")}},
   328  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodDynamic),
   329  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   330  								},
   331  							},
   332  						},
   333  					},
   334  				}))
   335  			},
   336  			expectedError: "",
   337  		},
   338  		{
   339  			name:     "get parameters for control plane network interface",
   340  			spec:     &fakeControlPlaneNICSpec,
   341  			existing: nil,
   342  			expect: func(g *WithT, result interface{}) {
   343  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   344  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   345  					Tags: map[string]*string{
   346  						"Name": ptr.To("my-net-interface"),
   347  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   348  					},
   349  					Location: ptr.To("fake-location"),
   350  					Properties: &armnetwork.InterfacePropertiesFormat{
   351  						EnableAcceleratedNetworking: ptr.To(true),
   352  						EnableIPForwarding:          ptr.To(false),
   353  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   354  						Primary:                     nil,
   355  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   356  							{
   357  								Name: ptr.To("pipConfig"),
   358  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   359  									Primary:                     ptr.To(true),
   360  									Subnet:                      &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   361  									PrivateIPAllocationMethod:   ptr.To(armnetwork.IPAllocationMethodDynamic),
   362  									LoadBalancerInboundNatRules: []*armnetwork.InboundNatRule{{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/inboundNatRules/azure-test1")}},
   363  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{
   364  										{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/my-public-lb-backendPool")},
   365  										{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-internal-lb/backendAddressPools/my-internal-lb-backendPool")}},
   366  								},
   367  							},
   368  						},
   369  					},
   370  				}))
   371  			},
   372  			expectedError: "",
   373  		},
   374  		{
   375  			name:     "get parameters for network interface with accelerated networking",
   376  			spec:     &fakeAcceleratedNetworkingNICSpec,
   377  			existing: nil,
   378  			expect: func(g *WithT, result interface{}) {
   379  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   380  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   381  					Tags: map[string]*string{
   382  						"Name": ptr.To("my-net-interface"),
   383  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   384  					},
   385  					Location: ptr.To("fake-location"),
   386  					Properties: &armnetwork.InterfacePropertiesFormat{
   387  						Primary:                     nil,
   388  						EnableAcceleratedNetworking: ptr.To(true),
   389  						EnableIPForwarding:          ptr.To(false),
   390  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   391  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   392  							{
   393  								Name: ptr.To("pipConfig"),
   394  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   395  									Primary:                         ptr.To(true),
   396  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   397  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodDynamic),
   398  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{},
   399  								},
   400  							},
   401  						},
   402  					},
   403  				}))
   404  			},
   405  			expectedError: "",
   406  		},
   407  		{
   408  			name:     "get parameters for network interface without accelerated networking",
   409  			spec:     &fakeNonAcceleratedNetworkingNICSpec,
   410  			existing: nil,
   411  			expect: func(g *WithT, result interface{}) {
   412  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   413  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   414  					Tags: map[string]*string{
   415  						"Name": ptr.To("my-net-interface"),
   416  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   417  					},
   418  					Location: ptr.To("fake-location"),
   419  					Properties: &armnetwork.InterfacePropertiesFormat{
   420  						Primary:                     nil,
   421  						EnableAcceleratedNetworking: ptr.To(false),
   422  						EnableIPForwarding:          ptr.To(false),
   423  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   424  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   425  							{
   426  								Name: ptr.To("pipConfig"),
   427  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   428  									Primary:                         ptr.To(true),
   429  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   430  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodDynamic),
   431  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{},
   432  								},
   433  							},
   434  						},
   435  					},
   436  				}))
   437  			},
   438  			expectedError: "",
   439  		},
   440  		{
   441  			name:     "get parameters for network interface ipv6",
   442  			spec:     &fakeIpv6NICSpec,
   443  			existing: nil,
   444  			expect: func(g *WithT, result interface{}) {
   445  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   446  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   447  					Tags: map[string]*string{
   448  						"Name": ptr.To("my-net-interface"),
   449  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   450  					},
   451  					Location: ptr.To("fake-location"),
   452  					Properties: &armnetwork.InterfacePropertiesFormat{
   453  						Primary:                     nil,
   454  						EnableAcceleratedNetworking: ptr.To(true),
   455  						EnableIPForwarding:          ptr.To(true),
   456  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   457  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   458  							{
   459  								Name: ptr.To("pipConfig"),
   460  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   461  									Primary:                         ptr.To(true),
   462  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   463  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodDynamic),
   464  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{},
   465  								},
   466  							},
   467  							{
   468  								Name: ptr.To("ipConfigv6"),
   469  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   470  									Subnet:                  &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   471  									Primary:                 ptr.To(false),
   472  									PrivateIPAddressVersion: ptr.To(armnetwork.IPVersionIPv6),
   473  								},
   474  							},
   475  						},
   476  					},
   477  				}))
   478  			},
   479  			expectedError: "",
   480  		},
   481  		{
   482  			name:     "get parameters for network interface default ipconfig",
   483  			spec:     &fakeDefaultIPconfigNICSpec,
   484  			existing: nil,
   485  			expect: func(g *WithT, result interface{}) {
   486  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   487  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   488  					Tags: map[string]*string{
   489  						"Name": ptr.To("my-net-interface"),
   490  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   491  					},
   492  					Location: ptr.To("fake-location"),
   493  					Properties: &armnetwork.InterfacePropertiesFormat{
   494  						Primary:                     nil,
   495  						EnableAcceleratedNetworking: ptr.To(true),
   496  						EnableIPForwarding:          ptr.To(true),
   497  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   498  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   499  							{
   500  								Name: ptr.To("pipConfig"),
   501  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   502  									Primary:                         ptr.To(true),
   503  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   504  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodDynamic),
   505  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{},
   506  								},
   507  							},
   508  						},
   509  					},
   510  				}))
   511  			},
   512  			expectedError: "",
   513  		},
   514  		{
   515  			name:     "get parameters for network interface with one ipconfig",
   516  			spec:     &fakeOneIPconfigNICSpec,
   517  			existing: nil,
   518  			expect: func(g *WithT, result interface{}) {
   519  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   520  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   521  					Tags: map[string]*string{
   522  						"Name": ptr.To("my-net-interface"),
   523  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   524  					},
   525  					Location: ptr.To("fake-location"),
   526  					Properties: &armnetwork.InterfacePropertiesFormat{
   527  						Primary:                     nil,
   528  						EnableAcceleratedNetworking: ptr.To(true),
   529  						EnableIPForwarding:          ptr.To(true),
   530  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   531  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   532  							{
   533  								Name: ptr.To("pipConfig"),
   534  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   535  									Primary:                         ptr.To(true),
   536  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   537  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodDynamic),
   538  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{},
   539  								},
   540  							},
   541  						},
   542  					},
   543  				}))
   544  			},
   545  			expectedError: "",
   546  		},
   547  		{
   548  			name:     "get parameters for network interface with two ipconfigs",
   549  			spec:     &fakeTwoIPconfigNICSpec,
   550  			existing: nil,
   551  			expect: func(g *WithT, result interface{}) {
   552  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   553  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   554  					Tags: map[string]*string{
   555  						"Name": ptr.To("my-net-interface"),
   556  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   557  					},
   558  					Location: ptr.To("fake-location"),
   559  					Properties: &armnetwork.InterfacePropertiesFormat{
   560  						Primary:                     nil,
   561  						EnableAcceleratedNetworking: ptr.To(true),
   562  						EnableIPForwarding:          ptr.To(true),
   563  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   564  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   565  							{
   566  								Name: ptr.To("pipConfig"),
   567  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   568  									Primary:                         ptr.To(true),
   569  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   570  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodDynamic),
   571  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{},
   572  								},
   573  							},
   574  							{
   575  								Name: ptr.To("my-net-interface-1"),
   576  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   577  									Primary:                         ptr.To(false),
   578  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   579  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodDynamic),
   580  									LoadBalancerBackendAddressPools: nil,
   581  								},
   582  							},
   583  						},
   584  					},
   585  				}))
   586  			},
   587  			expectedError: "",
   588  		},
   589  		{
   590  			name:     "get parameters for network interface with two ipconfigs and a public ip",
   591  			spec:     &fakeTwoIPconfigWithPublicNICSpec,
   592  			existing: nil,
   593  			expect: func(g *WithT, result interface{}) {
   594  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   595  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   596  					Tags: map[string]*string{
   597  						"Name": ptr.To("my-net-interface"),
   598  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   599  					},
   600  					Location: ptr.To("fake-location"),
   601  					Properties: &armnetwork.InterfacePropertiesFormat{
   602  						Primary:                     nil,
   603  						EnableAcceleratedNetworking: ptr.To(true),
   604  						EnableIPForwarding:          ptr.To(true),
   605  						DNSSettings:                 &armnetwork.InterfaceDNSSettings{},
   606  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   607  							{
   608  								Name: ptr.To("pipConfig"),
   609  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   610  									Primary:                   ptr.To(true),
   611  									Subnet:                    &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   612  									PrivateIPAllocationMethod: ptr.To(armnetwork.IPAllocationMethodDynamic),
   613  									PublicIPAddress: &armnetwork.PublicIPAddress{
   614  										ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/publicIPAddresses/pip-azure-test1"),
   615  									},
   616  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{},
   617  								},
   618  							},
   619  							{
   620  								Name: ptr.To("my-net-interface-1"),
   621  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   622  									Primary:                         ptr.To(false),
   623  									Subnet:                          &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   624  									PrivateIPAllocationMethod:       ptr.To(armnetwork.IPAllocationMethodDynamic),
   625  									LoadBalancerBackendAddressPools: nil,
   626  								},
   627  							},
   628  						},
   629  					},
   630  				}))
   631  			},
   632  			expectedError: "",
   633  		},
   634  		{
   635  			name:     "get parameters for control plane network interface with DNS servers",
   636  			spec:     &fakeControlPlaneCustomDNSSettingsNICSpec,
   637  			existing: nil,
   638  			expect: func(g *WithT, result interface{}) {
   639  				g.Expect(result).To(BeAssignableToTypeOf(armnetwork.Interface{}))
   640  				g.Expect(result.(armnetwork.Interface)).To(Equal(armnetwork.Interface{
   641  					Tags: map[string]*string{
   642  						"Name": ptr.To("my-net-interface"),
   643  						"sigs.k8s.io_cluster-api-provider-azure_cluster_my-cluster": ptr.To("owned"),
   644  					},
   645  					Location: ptr.To("fake-location"),
   646  					Properties: &armnetwork.InterfacePropertiesFormat{
   647  						EnableAcceleratedNetworking: ptr.To(true),
   648  						EnableIPForwarding:          ptr.To(false),
   649  						DNSSettings: &armnetwork.InterfaceDNSSettings{
   650  							DNSServers: []*string{ptr.To("123.123.123.123"), ptr.To("124.124.124.124")},
   651  						},
   652  						IPConfigurations: []*armnetwork.InterfaceIPConfiguration{
   653  							{
   654  								Name: ptr.To("pipConfig"),
   655  								Properties: &armnetwork.InterfaceIPConfigurationPropertiesFormat{
   656  									Subnet:                      &armnetwork.Subnet{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/my-subnet")},
   657  									Primary:                     ptr.To(true),
   658  									PrivateIPAllocationMethod:   ptr.To(armnetwork.IPAllocationMethodDynamic),
   659  									LoadBalancerInboundNatRules: []*armnetwork.InboundNatRule{{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/inboundNatRules/azure-test1")}},
   660  									LoadBalancerBackendAddressPools: []*armnetwork.BackendAddressPool{
   661  										{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-public-lb/backendAddressPools/my-public-lb-backendPool")},
   662  										{ID: ptr.To("/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Network/loadBalancers/my-internal-lb/backendAddressPools/my-internal-lb-backendPool")}},
   663  								},
   664  							},
   665  						},
   666  					},
   667  				}))
   668  			},
   669  			expectedError: "",
   670  		},
   671  	}
   672  	format.MaxLength = 10000
   673  	for _, tc := range testcases {
   674  		tc := tc
   675  		t.Run(tc.name, func(t *testing.T) {
   676  			g := NewWithT(t)
   677  			t.Parallel()
   678  
   679  			result, err := tc.spec.Parameters(context.TODO(), tc.existing)
   680  			if tc.expectedError != "" {
   681  				g.Expect(err).To(HaveOccurred())
   682  				g.Expect(err).To(MatchError(tc.expectedError))
   683  			} else {
   684  				g.Expect(err).NotTo(HaveOccurred())
   685  			}
   686  			tc.expect(g, result)
   687  		})
   688  	}
   689  }