Azure / vagrant-azure

Enable Vagrant to manage virtual machines in Microsoft Azure
MIT License
315 stars 112 forks source link
azure ruby vagrant vagrant-azure-plugin vagrant-plugin

PSA: Hi vagrant-azure plugin users, we are unable to continue supporting this project, so it is now archived. Even though this project is archived, the existing plugin will still work as it currently does. This should not affect any workflows currently using vagrat-azure.

We know there are many folks who are actively using this plugin but have long suffered from a lack of support in this project. We would like to encourage the community to fork this project and work together to advance and support Vagrant on Azure.

We thank everyone for their support through usage, issues and contributions.

Vagrant Azure Provider

Gem Version

This is a Vagrant 1.7.3+ plugin that adds Microsoft Azure provider to Vagrant, allowing Vagrant to control and provision machines in Microsoft Azure.

Getting Started

Install Vagrant

Create an Azure Active Directory (AAD) Application

AAD encourages the use of Applications / Service Principals for authenticating applications. An application / service principal combination provides a service identity for Vagrant to manage your Azure Subscription. Click here to learn about AAD applications and service principals.

The output of az ad sp create-for-rbac should look like the following:

{
  "appId": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
  "displayName": "some-display-name",
  "name": "http://azure-cli-2017-04-03-15-30-52",
  "password": "XXXXXXXXXXXXXXXXXXXX",
  "tenant": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
}

The values tenant, appId and password map to the configuration values azure.tenant_id, azure.client_id and azure.client_secret in your Vagrant file or environment variables.

For *nix, edit your Vagrantfile as shown below and provide all the values as explained.

Create a Vagrantfile

Create a directory and add the Linux or Windows Vagrantfile content below to a file named Vagrantfile.

Linux Vagrantfile

Vagrant.configure('2') do |config|
  config.vm.box = 'azure'

  # use local ssh key to connect to remote vagrant box
  config.ssh.private_key_path = '~/.ssh/id_rsa'
  config.vm.provider :azure do |azure, override|

    # each of the below values will default to use the env vars named as below if not specified explicitly
    azure.tenant_id = ENV['AZURE_TENANT_ID']
    azure.client_id = ENV['AZURE_CLIENT_ID']
    azure.client_secret = ENV['AZURE_CLIENT_SECRET']
    azure.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
  end

end

Windows Vagrantfile

Vagrant.configure('2') do |config|
  config.vm.box = 'azure'

  config.vm.provider :azure do |azure, override|

    # each of the below values will default to use the env vars named as below if not specified explicitly
    azure.tenant_id = ENV['AZURE_TENANT_ID']
    azure.client_id = ENV['AZURE_CLIENT_ID']
    azure.client_secret = ENV['AZURE_CLIENT_SECRET']
    azure.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']

    azure.vm_image_urn = 'MicrosoftSQLServer:SQL2016-WS2012R2:Express:latest'
    azure.instance_ready_timeout = 600
    azure.vm_password = 'TopSecretPassw0rd'
    azure.admin_username = "OctoAdmin"
    override.winrm.transport = :ssl
    override.winrm.port = 5986
    override.winrm.ssl_peer_verification = false # must be false if using a self signed cert
  end

end

Spin Up a Box in Azure

Install the vagrant-azure plugin using the standard Vagrant 1.1+ installation methods. After installing the plugin, you can vagrant up and use azure provider. For example:

$ vagrant box add azure https://github.com/azure/vagrant-azure/raw/v2.0/dummy.box --provider azure
$ vagrant plugin install vagrant-azure
$ vagrant up --provider=azure

This will bring up an Azure VM as per the configuration options set above.

You can now either SSH (if its a *Nix VM) using vagrant ssh, RDP (if its a Windows VM) using vagrant rdp or PowerShell vagrant powershell.

Normally, a lot of the options, e.g., vm_image_urn, will be embedded in a box file and you just have to provide minimal options in the Vagrantfile. Since, we're using a dummy box, there are no pre-configured defaults.

Configuration

The vagrant-azure provide exposes Azure specific configuration options:

Mandatory Parameters

Optional VM Parameters

Optional VM Image Parameters

vm_image_urn, vm_vhd_uri, and vm_managed_image_id are mutually exclusive. They should not be used in combination.

Optional VM Data Disk Parameters (Preview)

The data disk functionality is preview and may change before the 2.0 release.

Optional Networking Parameters

Optional Windows Parameters

Optional Provisioning Parameters

Optional Azure Parameters

Extended Documentation

For more information on common scenarios and other features visit the extended documentation.