Not able to create Virtual Network Rule for MySQL flexible server using powershell code

MONDALABDULKADIR-7547 25 Reputation points
2024-10-17T14:44:27.3533333+00:00

Hello Team ,

Actually we have IAC infracture to deploy MYSQL DBaaS services. However the existing terraform modules now has been depreciated and we are trying to upgrade the latest terraform module to deploy the same.

Now the issue is:-

In the existing code we are using "azurerm_mysql_firewall_rule" but in latest terraform module same module has been depreciated.

We are trying to deploy the MySQL flexible server using terraform and want to create Virtual Network Rule for MySQL using powershell module "New-AzMySqlVirtualNetworkRule" but doesn't work it seems.

Can someone please help just to create the Virtual Network Rule for existing MySQL flexible server without creating DNS zone , Records , Private Endpoints ets?

I could not see any azure powershell API for the same.

Used code:-

$virtualNetworkRule = New-AzMySqlVirtualNetworkRule -ResourceGroupName $resourceGroupName `

-ServerName $serverName `

-VirtualNetworkRuleName "myVnetRule" `

-SubnetId $subnet.Id

Error:-

New-AzMySqlVirtualNetworkRule : Failed to perform 'write' on resource(s) of type 'servers/virtualNetworkRules', because the parent resource

/subscriptions/xxxxxxx/resourceGroups/xxxxxxxxxx/providers/Microsoft.DBforMySQL/servers/weemeasbxtestmysql1' could not be found.

Thanks ,

Abdul Kadir

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
843 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,579 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Syed Mohsin Abbas 5 Reputation points
    2024-10-17T15:27:05.51+00:00

    The error indicates that the MySQL server resource isn’t found. Ensure the server name and resource group are correct in your code. Additionally, make sure that the MySQL flexible server is properly deployed before running the New-AzMySqlVirtualNetworkRule command.

    If the issue persists, check if the required permissions to write to the virtual network rules are set, and ensure you're using the correct API version for flexible servers.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.