DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Data Engineering
  3. Databases
  4. ARM Template Deployments for MySQL and PostgreSQL

ARM Template Deployments for MySQL and PostgreSQL

Microsoft recently announced a preview of MySQL and PostgreSQL databases as a PaaS service running in Azure. These templates can help you begin creating templates.

Sam Cogan user avatar by
Sam Cogan
·
Jun. 09, 17 · Opinion
Like (1)
Save
Tweet
Share
4.67K Views

Join the DZone community and get the full member experience.

Join For Free

A few weeks ago, Microsoft announced a preview of MySQL and PostgreSQL databases as a PaaS service running in Azure. Since then, we’ve not yet seen full documentation of the ARM templates required to deploy these; however, some example templates did appear on GitHub a few days ago that provide enough information to begin creating templates that use these two database services.

Both databases look to follow the same design, with just a variation in type name. They also both follow a similar layout to Azure SQL, with a top-level server object then child objects for databases and firewall rules.

At present, to be able to deploy these resources using ARM templates, you do need to use the 2016-02-01-privatepreview API version. Whilst this does state private preview, it is published publically on GitHub and works without being on the private preview.

A full example of a web app and MySQL deployment can be found here and a PostgreSQL one can be found here.

Template

Below is the full JSON for deploying a database server, database, and firewall rule. We’ll break this down and look at the parameters you need to provide.

{
    "apiVersion": "2016-02-01-privatepreview",
    "kind": "",
    "location": "[resourceGroup().location]",
    "name": "[variables('serverName')]",
    "properties": {
        "version": "[parameters('postgresqlVersion')]",
        "administratorLogin": "[parameters('administratorLogin')]",
        "administratorLoginPassword": "[parameters('administratorLoginPassword')]",
        "storageMB": "[parameters('databaseSkuSizeMB')]"
    },
    "sku": {
        "name": "[parameters('databaseSkuName')]",
        "tier": "[parameters('databaseSkuTier')]",
        "capacity": "[parameters('databaseDTU')]",
        "size": "[parameters('databaseSkuSizeMB')]",
        "family": "SkuFamily"
    },
    "type": "Microsoft.DBforPostgreSQL/servers",
    "resources": [
        {
            "type": "firewallrules",
            "apiVersion": "2016-02-01-privatepreview",
            "dependsOn": [
                "[concat('Microsoft.DBforPostgreSQL/servers/', variables('serverName'))]"
            ],
            "location": "[resourceGroup().location]",
            "name": "[concat(variables('serverName'),'firewall')]",
            "properties": {
                "startIpAddress": "0.0.0.0",
                "endIpAddress": "255.255.255.255"
            }
        },
        {
            "name": "[variables('databaseName')]",
            "type": "databases",
            "apiVersion": "2016-02-01-privatepreview",
            "properties": {
                "charset": "utf8",
                "collation": "English_United States.1252"
            },
            "dependsOn": [
                "[concat('Microsoft.DBforPostgreSQL/servers/', variables('serverName'))]"
            ]
        }
    ]
}
  • apiVersion: As mentioned, this needs to be “2016-02-01-privatepreview”.

  • kind: It’s not clear what this parameter is for. By the looks of the schema, it accepts two values, storage or blobstorage, but in all the examples, this is left blank.

  • type: For MySQL, this will be Microsoft.DBforMySQL/servers and for PostgreSQL, Microsoft.DBforPostgreSQL/servers.

  • administrationLogin and Password: These are obviously the credentials you will use to access the database.

Properties

  • version: For MySQL, versions 5.6 and 5.7 are supported. For PostgreSQL, this is 9.5 and 9.6.

  • storageMB: At present, only two sizes are supported, so your value must be exactly 102400 or 51200 (100GB or 50GB).

Sku

  • tier: At present, only one tier is available. Standard and Premium will be available later.

  • capacity: This is the performance capacity in DTU; can be 50 or 100 DTU.

  • size: This is the DB size in MB again; 102400 or 51200.

  • name: This combines the tier, capacity, and size, can be MYSQLB100 or MYSQLB50 and PostgreSQLB50 or PostgreSQLB100.

  • family: Unclear what this is for; set to SKUFamily.

Firewall Rules

The firewall rules child resource is the same as we have seen in Azure SQL, but using the preview API.

Database

The database child resource is a bit simpler than the Azure SQL one, with the performance and size being determined by the parent. The database has only two real configuration options, charset and collation , which can be set as you require.

Connection String

If you're creating one of these DBs, chances are you are using it with an Azure web app and you need to hook the two together with a connection string. If that’s the case, you can use the parameters provided in your template to build this connection string in the web app section of your template:

MySQL

"resources": [
    {
        "apiVersion": "2015-04-01",
        "name": "connectionstrings",
        "type": "config",
        "dependsOn": [
            "[concat('Microsoft.Web/sites/', parameters('siteName'))]"
        ],
        "properties": {
            "defaultConnection": {
                "value": "[concat('Database=', variables('databaseName'), ';Data Source=', variables('serverName'), '.mysql.database.azure.com;User Id=', parameters('dbadministratorLogin'),'@', variables('serverName'),';Password=', parameters('dbadministratorLoginPassword'))]",
                "type": "MySQL"
            }
        }
    }
]

PostgreSQL

"resources": [
    {
        "apiVersion": "2015-04-01",
        "name": "connectionstrings",
        "type": "config",
        "dependsOn": [
            "[concat('Microsoft.Web/sites/', parameters('siteName'))]"
        ],
        "properties": {
            "defaultConnection": {
                "value": "[concat('Database=', variables('databaseName'), ';Server=', variables('serverName'), '.postgres.database.azure.com;User Id=', parameters('administratorLogin'),'@', variables('serverName'),';Password=', parameters('administratorLoginPassword'))]",
                "type": "PostgreSQL"
            }
        }
    }
]

As mentioned, a full example of a web app and MYSQL deployment can be found here and a PostgreSQL one can be found here.

MySQL Template PostgreSQL Database Arm (geography)

Published at DZone with permission of Sam Cogan. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Deep Dive Into AIOps and MLOps
  • Fargate vs. Lambda: The Battle of the Future
  • What Is Continuous Testing?
  • What’s New in the Latest Version of Angular V15?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: