Search code examples
postgresqlazureazure-automationazure-postgresql

PostgreSQL rules in Azure automation


For a business case where I’m working on now I have a problem. I have A device which has to write on an Azure PostgreSQL server (https://azure.microsoft.com/nl-nl/services/postgresql/). The device has a dynamic DNS (creating a network or something like that is not an option).

My first thought was creating an Azure automation runbook who adds a firewall rule to the PostgreSQL server. I created the first couple of lines which extracts the IP from the DNS but there seems not a option to create a firewall rule for PostgreSQL.

Code:

$ips = [System.Net.Dns]::GetHostAddresses("dynamicdns.example.net")
$regex = [regex] "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
$ip2 = $regex.Matches($ips) | %{ $_.value } 

Does anyone know A solution to automate the update of the PostgreSQL firewall so this don’t be a manual job anymore?


Solution

  • I believe you can accomplish the requirement to create a new firewall rule or update an existing firewall rule for PostgreSQL by leveraging this REST API. You may call the REST API from Azure Automation PowerShell runbook with the help of Invoke-WebRequest cmdlet.

    Ideally you would get array of IP's after your first 3 lines of code that was provided. You may have to develop code to call the above mentioned REST API in loop to add all the retrieved array of IP's.