question

ShuchitaTripathi-2486 avatar image
0 Votes"
ShuchitaTripathi-2486 asked MayankBargali-MSFT edited

How to add public IP to APIM via CLI?

I am trying to add separately managed public IP to Azure APIM (external) using CLI. Command is not giving any error but IP is not getting attached.
Command:
az resource update --ids "<apim-id>" --set properties.publicIPAddresses="20.x.x.x"

Output:
112177-image.png


For reference, this is what I am trying to do:
112196-image.png



How can I add a separately managed public IP to APIM using automation? (preferably CLI, however powershell will also help). Separately managed IP refers to IP created using create public IP command, and then attaching that to APIM.

azure-api-management
image.png (124.5 KiB)
image.png (126.0 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ShuchitaTripathi-2486 It might take between 15-45 minutes to complete the operation. Can you confirm what is the CLI version you are using and whether the publicIPAddresses was updated posted 1hr of executing the command.

0 Votes 0 ·

Hi @MayankBargali-MSFT :
APIM is not updated after 1 hour. It is still showing the old ID. (I am checking the next day)
AZ cli version is 2.25.0

0 Votes 0 ·

I have also tried with public IP's 'name', 'resourceID' and the property PublicIPAddressID (found it in ARM template). Every command gives the same result as above, and none changes the public IP to the one I am passing.

0 Votes 0 ·

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered MayankBargali-MSFT edited

@ShuchitaTripathi-2486 Currently, the Azure portal uses API version 2021-01-01 preview when creating or updating an API Management instance. You can specify this API version using an Azure Resource Manager template or the API Management REST API. The Azure CLI and Azure PowerShell currently support API version 2020-12-01.

When I test with AZ CLI version is 2.25.0/2.26.0 then I observe the Bad Request as it is expected as the Azure CLI doesn't support this functionality yet. The same is documented here.
ERROR: Operation returned an invalid status 'Bad Request'

You should observe the same behavior. You can try running the command with --debug to get more details on the request and error message.

For any CLI feature/feedback/issue you can always post your query here.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank @MayankBargali-MSFT ,
Is there any way this can be achieved?
We are creating APIM resource using terraform. However in terraform, we dont see an option to attach existing public IP. That is why we are going toward attaching the IP after APIM is created.
Is there any way this can be done? Our end goal is to make the APIM external and attach an existing public IP.

0 Votes 0 ·

Adding one line in my previous comment:
We want to achieve it via automation. CLI/Powershell/Terraform/Rest
Not via portal.

0 Votes 0 ·

@ShuchitaTripathi-2486 Yes you can use REST API as currently this operation is only supported using Azure portal and REST API as mentioned in the document.
You need to use the version 2020-12-01 API for APIM Management Operation. You need to first call the Api Management Service - Get API and then use the output and add/update publicIpAddressId property. You can refer to request body section for details on what are the properties supported while updating the APIM instance.

Alternative, you can also use F12 traces to verify how the request body is formed when you are performing any operation from the portal.

0 Votes 0 ·