Skip to content

Instantly share code, notes, and snippets.

@PatrickLang
Last active February 6, 2018 20:27
Show Gist options
  • Save PatrickLang/a52b3eadfdd7f62d44b606aa70ad15dd to your computer and use it in GitHub Desktop.
Save PatrickLang/a52b3eadfdd7f62d44b606aa70ad15dd to your computer and use it in GitHub Desktop.
Terraforming a Windows Server Insider VM to Azure

Convert VHD

From an admin powershell prompt: Convert-VHD .\Windows_InsiderPreview_Server_VHDX_17079.vhdx .\Windows_InsiderPreview_Server_VHDX_17079.vhd

Remaining steps are done with Windows Subsystem for Linux

Login to Azure

az login
az account set --subscription <redacted>

Create resource group and storage account for source VHD, then upload VHD

export rg=plang-insider
export storageacct=planginsider17079
export vhdfilename=Windows_InsiderPreview_Server_VHDX_17079.vhd

az group create --name $rg --location westus2
az storage account create --resource-group $rg --location westus2 --name $storageacct --kind Storage --sku Standard_LRS
az storage container create --account-name $storageacct --name vhds
az storage account keys list --resource-group $rg --account-name $storageacct
export ak="<redacted>"
az storage blob upload --account-name=$storageacct --account-key=$ak --container-name vhds --type page --file /mnt/c/Users/patrick/Downloads/Windows_InsiderPreview_Server_VHDX_17079.vhd --name $vhdfilename

# get URL from this
az storage blob url --account-name $storageacct --account-key $ak --container-name vhds --name $vhdfilename

Terraform it

Install Terraform

curl https://releases.hashicorp.com/terraform/0.11.3/terraform_0.11.3_linux_amd64.zip -o terraform_0.11.3_linux_amd64.zip
unzip terraform_0.11.3_linux_amd64.zip
chmod 755 /usr/local/bin/terraform
sudo mv terraform /usr/local/bin

Create terraform.tfvars file

echo image_uri=`az storage blob url --account-name $storageacct --account-key $ak --container-name vhds --name $vhdfilename` >> terraform.tfvars
echo storage_account_name="\"$storageacct\"" >> terraform.tfvars
echo resource_group="\"$rg\"" >> terraform.tfvars

based off this sample https://github.com/terraform-providers/terraform-provider-azurerm/tree/master/examples/vm-from-user-image

terraform init
terraform apply
# this will ask for some data that's missing from variables.tf

References

I couldn't find a blog that did exactly what I wanted, but these were close:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment