@@ -92,6 +92,86 @@ func createPublicIP(ctx context.Context, in *pipInput) (*armnetwork.PublicIPAddr
9292 return & resp .PublicIPAddress , nil
9393}
9494
95+ func createAPILoadBalancer (ctx context.Context , pip * armnetwork.PublicIPAddress , in * lbInput ) (* armnetwork.LoadBalancer , error ) {
96+ loadBalancerName := in .infraID
97+ probeName := "api-probe"
98+ frontEndIPConfigName := "public-lb-ip-v4"
99+ backEndAddressPoolName := in .infraID
100+ idPrefix := fmt .Sprintf ("subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/loadBalancers" , in .subscriptionID , in .resourceGroup )
101+
102+ pollerResp , err := in .lbClient .BeginCreateOrUpdate (ctx ,
103+ in .resourceGroup ,
104+ loadBalancerName ,
105+ armnetwork.LoadBalancer {
106+ Location : to .Ptr (in .region ),
107+ SKU : & armnetwork.LoadBalancerSKU {
108+ Name : to .Ptr (armnetwork .LoadBalancerSKUNameStandard ),
109+ Tier : to .Ptr (armnetwork .LoadBalancerSKUTierRegional ),
110+ },
111+ Properties : & armnetwork.LoadBalancerPropertiesFormat {
112+ FrontendIPConfigurations : []* armnetwork.FrontendIPConfiguration {
113+ {
114+ Name : & frontEndIPConfigName ,
115+ Properties : & armnetwork.FrontendIPConfigurationPropertiesFormat {
116+ PrivateIPAllocationMethod : to .Ptr (armnetwork .IPAllocationMethodDynamic ),
117+ PublicIPAddress : pip ,
118+ },
119+ },
120+ },
121+ BackendAddressPools : []* armnetwork.BackendAddressPool {
122+ {
123+ Name : & backEndAddressPoolName ,
124+ },
125+ },
126+ Probes : []* armnetwork.Probe {
127+ {
128+ Name : & probeName ,
129+ Properties : & armnetwork.ProbePropertiesFormat {
130+ Protocol : to .Ptr (armnetwork .ProbeProtocolHTTPS ),
131+ Port : to.Ptr [int32 ](6443 ),
132+ IntervalInSeconds : to.Ptr [int32 ](5 ),
133+ NumberOfProbes : to.Ptr [int32 ](2 ),
134+ RequestPath : to .Ptr ("/readyz" ),
135+ },
136+ },
137+ },
138+ LoadBalancingRules : []* armnetwork.LoadBalancingRule {
139+ {
140+ Name : to .Ptr ("api-v4" ),
141+ Properties : & armnetwork.LoadBalancingRulePropertiesFormat {
142+ Protocol : to .Ptr (armnetwork .TransportProtocolTCP ),
143+ FrontendPort : to.Ptr [int32 ](6443 ),
144+ BackendPort : to.Ptr [int32 ](6443 ),
145+ IdleTimeoutInMinutes : to.Ptr [int32 ](30 ),
146+ EnableFloatingIP : to .Ptr (false ),
147+ LoadDistribution : to .Ptr (armnetwork .LoadDistributionDefault ),
148+ FrontendIPConfiguration : & armnetwork.SubResource {
149+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/frontendIPConfigurations/%s" , idPrefix , loadBalancerName , frontEndIPConfigName )),
150+ },
151+ BackendAddressPool : & armnetwork.SubResource {
152+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/backendAddressPools/%s" , idPrefix , loadBalancerName , backEndAddressPoolName )),
153+ },
154+ Probe : & armnetwork.SubResource {
155+ ID : to .Ptr (fmt .Sprintf ("/%s/%s/probes/%s" , idPrefix , loadBalancerName , probeName )),
156+ },
157+ },
158+ },
159+ },
160+ },
161+ Tags : in .tags ,
162+ }, nil )
163+
164+ if err != nil {
165+ return nil , fmt .Errorf ("cannot create load balancer: %w" , err )
166+ }
167+
168+ resp , err := pollerResp .PollUntilDone (ctx , nil )
169+ if err != nil {
170+ return nil , err
171+ }
172+ return & resp .LoadBalancer , nil
173+ }
174+
95175func updateOutboundLoadBalancerToAPILoadBalancer (ctx context.Context , pip * armnetwork.PublicIPAddress , in * lbInput ) (* armnetwork.LoadBalancer , error ) {
96176 loadBalancerName := in .infraID
97177 probeName := "api-probe"
0 commit comments