20
Nov

Moving on from my previous post, Creating Simple SQL Server test server with Terraform in Azure, I thought it may be fun to change the SQL Server version of an existing SQL Server.
This assumes you made a mistake and want to wipe out the old version. It will not perform an upgrade in-place of an existing server (pity).

As you will remember the way we choose which ‘image’ file we use to build the new virtual machine from is in the maint.tf file section storage_image_reference. See below.

The values for this definition are resolved from the variables.tf file

So the value for “i_offer = SQ2016SP1-WS2016”, meaning SQL Server 2016, Service pack 2 on a Windows 2016 Work Station. From the Commandline, we can get a list of all available images for SQL 2019 using command below.

az vm image list --location westus --publisher MicrosoftSQLServer --offer SQL2019 --sku SQLDEV --all --output table

The SQL 2019 versions in the output below are shown for different platforms. You can specify the exact version number you want or just set “i_version = latest”, as we have done in our example.

Swap out SQL 2016 for SQL 2019

Edit the variables.tf file with the new version you want to replace your SQL Server with

terraform apply

This will destroy the original VM but not the disks it uses, so in our example, we ran ‘terraform apply’ and allowed to fail. Next we removed the 2 disks the VM uses, from the Azure Portal GUI.

terraform apply

Retry and this time the new virtual machine will get built.

Quick Test

Like we did last time, get the IP of the new machine, Host1-sqlvminstancenew rom the Azure Portal and use mstsc.exe to connect. Credentials are in the variables.tf file.

Check version of the OS and installed SQL Server…..
Both 2019 = success!

Leave a Reply

Your email address will not be published. Required fields are marked *