DEV Community

Cover image for Give Azure resources access to your Azure database in ARM and Terraform templates
Ryan Rousseau for Octopus Deploy

Posted on • Originally published at blog.rousseau.dev

2 2

Give Azure resources access to your Azure database in ARM and Terraform templates

Sometimes when I create a new database server in Azure, I forget one step. It doesn't take long before I get connection errors, and I immediately what I missed.

I need to set the Allow Azure services and resources to access this server setting to Yes.

Allow Azure services and resources to access this server

I create most of my cloud resources with automation scripts. I want to set this value to Yes in my ARM or Terraform templates.

I used the Export Template button the Azure portal to see if I could figure out how to do this. This is what I found:

{
    "type": "Microsoft.Sql/servers/firewallRules",
    "apiVersion": "2015-05-01-preview",
    "name": "[concat(parameters('servers_demoserver_name'), '/AllowAllWindowsAzureIps')]",
    "dependsOn": [
        "[resourceId('Microsoft.Sql/servers', parameters('servers_demoserver_name'))]"
    ],
    "properties": {
        "startIpAddress": "0.0.0.0",
        "endIpAddress": "0.0.0.0"
    }
}

Yes represents a firewall rule with the starting and ending IP addresses set to 0.0.0.0.

To do the same in Terraform, use something like:

resource "azurerm_sql_firewall_rule" "AllowAllWindowsAzureIps" {
  name                = "AllowAllWindowsAzureIps"
  resource_group_name = "${azurerm_resource_group.main.name}"
  server_name         = "${azurerm_sql_server.main.name}"
  start_ip_address    = "0.0.0.0"
  end_ip_address      = "0.0.0.0"
}

There you go! Add this trick to your ARM or Terraform repertoire and avoid future connection errors.

This post was originally published at blog.rousseau.dev. Cover photo by Scott Webb on Unsplash.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more