Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUERY] How to add or remove IP address target from Application Gateway backend pool using the SDK #47631

Open
rabindra-harlalka opened this issue Dec 20, 2024 · 5 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Network question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@rabindra-harlalka
Copy link

rabindra-harlalka commented Dec 20, 2024

Library name and version

Azure.ResourceManager.Network 1.9.0

Query/Question

How to add or remove IP address target from Application Gateway backend pool using the SDK? Using Az CLI, it's possible to do the same like so: az network application-gateway address-pool update --gateway-name <GWNAME> -g <RESOURCE_GROUP> --name <BACKENDPOOLNAME> --add backendAddresses ipAddress=<IP_ADDRESS>. However, it's not clear how to do the same with the SDK.
I have created a service principal with Network Contributor role assigned to the Application Gateway resource in question. Next I create a ClientCertificateCredential object and do the following:

var armClient = new ArmClient(credential, subscriptionId);

var appGatewayResource = await armClient.GetApplicationGatewayResource(
       new ResourceIdentifier($"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/applicationGateways/{applicationGatewayName}")
        ).GetAsync();

// Get the Backend Pool
var backendPool = appGatewayResource.Value.Data.BackendAddressPools.FirstOrDefault(pool => pool.Name == backendPoolName);

backendPool.BackendAddresses.Add(new ApplicationGatewayBackendAddress { IPAddress = vmIpAddress });

What should be the next step?

Environment

No response

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 20, 2024
@jsquire jsquire added Network Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Dec 20, 2024
@jsquire
Copy link
Member

jsquire commented Dec 20, 2024

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@ArthurMa1978
Copy link
Member

Thanks for your feedback @rabindra-harlalka , @HarveyLink please look into this question.

@mcgallan mcgallan assigned mcgallan and unassigned HarveyLink Dec 25, 2024
@mcgallan
Copy link
Member

@rabindra-harlalka Thank you for reaching out to us.
If you are using the SDK to create a resource, you can refer to the following code for setting the IP address in BackendAddressPools using ApplicationGatewayData to add an IP address:

var appGatewayData = new ApplicationGatewayData()
{
    //other properties
    BackendAddressPools = {
        new ApplicationGatewayBackendAddressPool()
        {
            Name = backendAddressPoolName,
            BackendAddresses = {
                new ApplicationGatewayBackendAddress()
                {
                    IPAddress = ipAddresses[0]
                },
                new ApplicationGatewayBackendAddress()
                {
                    IPAddress = ipAddresses[1]
                }
            }
        },
        new ApplicationGatewayBackendAddressPool()
        {
            Name = nicBackendAddressPoolName
        }
    },
};

After that, call collection.CreateOrUpdateAsync(WaitUntil.Completed, appGwName, appGatewayData) to complete the creation or update of the resource:

var lro1 = await client.GetDefaultSubscription().GetResourceGroups().CreateOrUpdateAsync(Azure.WaitUntil.Completed, rgName, new ResourceGroupData(AzureLocation.EastUS2));
var resourceGroup = lro1.Value;
var collection = resourceGroup..GetApplicationGateways();
var resource = (await collection.CreateOrUpdateAsync(WaitUntil.Completed, resourceName, appGatewayData)).value;

The removal operation is implemented in the same way. You need to set the remaining IP addresses as parameters for the new BackendAddressPools after completing the removal operation, and then call CreateOrUpdate to complete the resource upgrade. If you are only updating data, you can directly call CreateOrUpdate() with the new data after your own steps to update it. Please let us know if you have any further questions or need additional assistance.

@mcgallan mcgallan added needs-author-feedback Workflow: More information is needed from author to address the issue. and removed needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Dec 27, 2024
Copy link

Hi @rabindra-harlalka. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

@rabindra-harlalka
Copy link
Author

rabindra-harlalka commented Dec 30, 2024

After that, call collection.CreateOrUpdateAsync(WaitUntil.Completed, appGwName, appGatewayData) to complete the creation or update of the resource:

var lro1 = await client.GetDefaultSubscription().GetResourceGroups().CreateOrUpdateAsync(Azure.WaitUntil.Completed, rgName, new ResourceGroupData(AzureLocation.EastUS2));
var resourceGroup = lro1.Value;
var collection = resourceGroup..GetApplicationGateways();
var resource = (await collection.CreateOrUpdateAsync(WaitUntil.Completed, resourceName, appGatewayData)).value;

The removal operation is implemented in the same way. You need to set the remaining IP addresses as parameters for the new BackendAddressPools after completing the removal operation, and then call CreateOrUpdate to complete the resource upgrade. If you are only updating data, you can directly call CreateOrUpdate() with the new data after your own steps to update it. Please let us know if you have any further questions or need additional assistance.

@mcgallan, thanks for the response. The suggested code works to add or remove IP addresses. However, I noticed that for the above to work, I also need to assign Network Contributor role at the resource group level, besides at the App Gateway resource level which I had already given. Once that was done, I was able to add or remove. From a few measurements, the rough time it took to complete an operation is ~12 seconds. I wish there was a quicker or simpler way, but I do see that the same happens on Azure Portal as well behind the scenes - a new deployment takes place for IP address update.

My question is answered. This query can be closed.

@github-actions github-actions bot added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-author-feedback Workflow: More information is needed from author to address the issue. labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. Mgmt This issue is related to a management-plane library. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team Network question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

5 participants