Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

[Azure] Get a value in a Keyvault with Terraform

  • August 1, 2019
  • 4 min read
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.

By default, if you want to deploy a VM on Azure with Terraform, you must give the username and password in clear in the variable file (see my previous article). But a solution exists, to secure all this 🙂 Just use an Azure Keyvault, and store your password in:

Azure Keyvault secrets

Then, you have to add these lines, at the beginning of your code:

Here we will get the RG, the Keyvault, and the secret that has the Default-Admin-Windows-Linux-VM name in my keyvault and that contains my default password for my VMs. We must then adapt the code so that our admin_password variable takes the value that is in the keyvault:

You can now do a terraform init and terraform plan. You should have the following error:

Default-Admin-Windows-Linux-VM name

This is normal. In fact, you must give the Get and List secrets privileges to the application that is used to deploy the resources in Azure via Terraform in the keyvault:

AzureDevops Permission

You can do again a terraform plan and terraform apply to deploy your resources in a secure way. Note this error message, which will disappear when updating to version 2 of the provider, but where you have to adapt the code:

Terraform plan and terraform apply

This code is available on my Github:

https://github.com/Flodu31/Terraform/tree/master/Deploy_New_Environment_Keyvault

Hey! Found Florent’s article helpful? Looking to deploy a new, easy-to-manage, and cost-effective hyperconverged infrastructure?
Alex Bykovskyi
Alex Bykovskyi StarWind Virtual HCI Appliance Product Manager
Well, we can help you with this one! Building a new hyperconverged environment is a breeze with StarWind Virtual HCI Appliance (VHCA). It’s a complete hyperconverged infrastructure solution that combines hypervisor (vSphere, Hyper-V, Proxmox, or our custom version of KVM), software-defined storage (StarWind VSAN), and streamlined management tools. Interested in diving deeper into VHCA’s capabilities and features? Book your StarWind Virtual HCI Appliance demo today!