Skip to content
This repository has been archived by the owner on Jan 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #190 from devigned/storage-refactor
Browse files Browse the repository at this point in the history
Storage refactor -- move to managed disks
  • Loading branch information
devigned authored Apr 19, 2017
2 parents 28f458e + b034d65 commit fe4de98
Show file tree
Hide file tree
Showing 43 changed files with 1,287 additions and 414 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ id
.DS_Store
Gemfile.lock
azure.box
Vagrantfile
/Vagrantfile
!example_box/Vagrantfile
!example_box/README.md
babu
Expand Down
120 changes: 120 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
AllCops:
TargetRubyVersion: 2.2
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
# to ignore them, so only the ones explicitly set in this file are enabled.
DisabledByDefault: true

# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true

# Do not use braces for hash literals when they are the last argument of a
# method call.
Style/BracesAroundHashParameters:
Enabled: true

# Align `when` with `case`.
Style/CaseIndentation:
Enabled: true

# Align comments with method definitions.
Style/CommentIndentation:
Enabled: true

# No extra empty lines.
Style/EmptyLines:
Enabled: true

# In a regular class definition, no empty lines around the body.
Style/EmptyLinesAroundClassBody:
Enabled: true

# In a regular method definition, no empty lines around the body.
Style/EmptyLinesAroundMethodBody:
Enabled: true

# In a regular module definition, no empty lines around the body.
Style/EmptyLinesAroundModuleBody:
Enabled: true

# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
Style/HashSyntax:
Enabled: true

# Method definitions after `private` or `protected` isolated calls need one
# extra level of indentation.
Style/IndentationConsistency:
Enabled: true
EnforcedStyle: rails

# Two spaces, no tabs (for indentation).
Style/IndentationWidth:
Enabled: true

Style/SpaceAfterColon:
Enabled: true

Style/SpaceAfterComma:
Enabled: true

Style/SpaceAroundEqualsInParameterDefault:
Enabled: true

Style/SpaceAroundKeyword:
Enabled: true

Style/SpaceAroundOperators:
Enabled: true

Style/SpaceBeforeFirstArg:
Enabled: true

# Defining a method with parameters needs parentheses.
Style/MethodDefParentheses:
Enabled: true

# Use `foo {}` not `foo{}`.
Style/SpaceBeforeBlockBraces:
Enabled: true

# Use `foo { bar }` not `foo {bar}`.
Style/SpaceInsideBlockBraces:
Enabled: true

# Use `{ a: 1 }` not `{a:1}`.
Style/SpaceInsideHashLiteralBraces:
Enabled: true

Style/SpaceInsideParens:
Enabled: true

# Check quotes usage according to lint rule below.
Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes

# Detect hard tabs, no hard tabs.
Style/Tab:
Enabled: true

# Blank lines should not have any spaces.
Style/TrailingBlankLines:
Enabled: true

# No trailing whitespace.
Style/TrailingWhitespace:
Enabled: true

# Use quotes for string literals when they are enough.
Style/UnneededPercentQ:
Enabled: true

# Align `end` with the matching keyword or starting expression except for
# assignments, where it should be aligned with the LHS.
Lint/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: variable

# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
Lint/RequireParentheses:
Enabled: true
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sudo: false
language: ruby
rvm:
- 2.2.5
before_install:
- rvm @default,@global do gem uninstall bundler -a -x
- gem install bundler -v 1.10.5
deploy:
provider: rubygems
api_key:
secure: "ThMTLeJ1E2dLLAK1AIokfE+0GyfCKwaAstxETI/qFkOwL21REi6dgTfPIrBpgmrYATb/YgkgIf6Zl46R7vx9/dtgIGBmX7AXT3zsR38P3zfOGy5PzHGGK72ZmkC5UFSBsnQl5J0qQsUEMQfEy2g7dwn1d9aFLKhvnFblNHt4x5c="
on:
tags: true
9 changes: 4 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License in the project root for license information.

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

group :development do
group :development, :test do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
gem 'bundler', '~>1.10.5'
gem "vagrant", git: "https://github.com/mitchellh/vagrant.git", tag: "v1.9.2"
end

group :plugins do
gem 'vagrant-azure', path: '.'
gem "vagrant-azure", path: "."
end
122 changes: 73 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,18 @@
This is a [Vagrant](http://www.vagrantup.com) 1.7.3+ plugin that adds [Microsoft Azure](https://azure.microsoft.com)
provider to Vagrant, allowing Vagrant to control and provision machines in Microsoft Azure.

## Usage
## Getting Started

[Download Vagrant](http://www.vagrantup.com/downloads.html)

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:

```sh
& vagrant plugin install vagrant-azure --plugin-version '2.0.0.pre6'
...
$ vagrant up --provider=azure
...
```

You'll need an ```azure``` box before you can do ```vagrant up``` though.

## Quick Start

You can use the dummy box and specify all the required details manually in the ```config.vm.provider``` block in your ```Vagrantfile```. Add the dummy box with the name you want:

```sh
$ vagrant box add azure https://github.com/azure/vagrant-azure/raw/v2.0/dummy.box
...
```
[Install Vagrant](https://www.vagrantup.com/docs/installation/)

### 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.](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-application-objects.)
- [Install the Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
- run `az login` to log into Azure
- run `az ad sp create-for-rbac` to create an Azure Active Directory Application with access to Azure Resource Manager for the current Azure Subscription
- run `az ad sp create-for-rbac` to create an Azure Active Directory Application with access to Azure Resource Manager
for the current Azure Subscription
- If you want to run this for a different Azure Subscription, run `az account set --subscription 'your subscription name'`
- run `az account list --query "[?isDefault].id" -o tsv` to get your Azure Subscription Id.

Expand All @@ -54,6 +35,11 @@ The values `tenant`, `appId` and `password` map to the configuration values

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
```ruby
Vagrant.configure('2') do |config|
config.vm.box = 'azure'
Expand All @@ -72,8 +58,7 @@ Vagrant.configure('2') do |config|
end
```

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

#### Windows Vagrantfile
```ruby
Vagrant.configure('2') do |config|
config.vm.box = 'azure'
Expand All @@ -90,7 +75,6 @@ Vagrant.configure('2') do |config|
azure.instance_ready_timeout = 600
azure.vm_password = 'TopSecretPassw0rd'
azure.admin_username = "OctoAdmin"
azure.admin_password = 'TopSecretPassw0rd'
override.winrm.transport = :ssl
override.winrm.port = 5986
override.winrm.ssl_peer_verification = false # must be false if using a self signed cert
Expand All @@ -99,44 +83,75 @@ Vagrant.configure('2') do |config|
end
```

Now you can run
### 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:

```sh
$ vagrant box add azure https://github.com/azure/vagrant-azure/raw/v2.0/dummy.box --provider azure
& vagrant plugin install vagrant-azure --plugin-version '2.0.0.pre6'
$ 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 this 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.

## Azure Boxes
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```.

The vagrant-azure plugin provides the ability to use ```Azure``` boxes with Vagrant. Please see the example box provided in [example_box](https://github.com/azure/vagrant-azure/tree/v2.0/example_box) directory and follow the instructions there to build an ```azure``` box.

Please see [Vagrant Docs](http://docs.vagrantup.com/v2/) for more details.
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
### Mandatory Parameters
* `tenant_id`: Your Azure Active Directory Tenant Id.
* `client_id`: Your Azure Active Directory application client id.
* `client_secret`: Your Azure Active Directory application client secret.
* `subscription_id`: The Azure subscription Id you'd like to use.
*Note: to procure these values see: [Create an Azure Active Directory Application](#create-an-azure-active-directory-aad-application)*

### Optional

* `resource_group_name`: (Optional) Name of the resource group to use.
* `location`: (Optional) Azure location to build the VM -- defaults to `westus`
* `vm_name`: (Optional) Name of the virtual machine
### Optional VM Parameters
* `vm_name`: Name of the virtual machine
* `vm_password`: (Optional for *nix) Password for the VM -- This is not recommended for *nix deployments
* `vm_size`: (Optional) VM size to be used -- defaults to 'Standard_DS2_v2'. See sizes for [*nix](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-sizes/), [Windows](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-sizes/).
* `vm_image_urn`: (Optional) Name of the virtual machine image urn to use -- defaults to 'canonical:ubuntuserver:16.04-LTS:latest'. See documentation for [*nix](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-ps-findimage/), [Windows](https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-cli-ps-findimage).
* `vm_size`: VM size to be used -- defaults to 'Standard_DS2_v2'. See sizes for [*nix](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-sizes/), [Windows](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-sizes/).
* `admin_username`: The root/administrator username for the VM

### 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.
* `vm_image_urn`: Name of the virtual machine image urn to use -- defaults to 'canonical:ubuntuserver:16.04-LTS:latest'. See documentation for [*nix](https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-cli-ps-findimage/), [Windows](https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-cli-ps-findimage).
* `vm_vhd_uri`: URI to the custom VHD. If the VHD is not publicly accessible, provide a SAS token in the URI.
* `vm_operating_system`: (Mandatory) Must provide the OS if using a custom image ("Linux" or "Windows")
* `vm_vhd_storage_account_id`: (Manditory) The Storage Account Azure Resource Manager Id where the OS Image is stored
(like: /subscriptions/{subscription id}/resourceGroups/{resource group}/providers/Microsoft.Storage/storageAccounts/{account name}).
* `vm_managed_image_id`: Create a VM from a generalized VM that is stored as either a managed or unmanaged disk. See: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource

### Optional VM Data Disk Parameters (Preview)
The data disk functionality is preview and may change before the 2.0 release.
* `data_disks`: (Optional) Array of Data Disks to attach to the VM. For information on attaching the drive, See: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/classic/attach-disk.
```ruby
override.data_disks = [
# sample of creating empty data disk
{
name: "mydatadisk1",
size_gb: 30
},
# sample of attaching an existing VHD as a data disk
{
name: "mydatadisk2",
vhd_uri: "http://mystorage.blob.core.windows.net/vhds/mydatadisk2.vhd"
},
# sample of attaching a data disk from image
{
name: "mydatadisk3",
vhd_uri: "http://mystorage.blob.core.windows.net/vhds/mydatadisk3.vhd",
image: "http: //storagename.blob.core.windows.net/vhds/VMImageName-datadisk.vhd"
}]
```

### Optional Networking Parameters
* `virtual_network_name`: (Optional) Name of the virtual network resource
* `dns_name`: (Optional) DNS Label Prefix
* `nsg_name`: (Optional) Network Security Group Label Prefix
Expand All @@ -145,11 +160,20 @@ The vagrant-azure provide exposes Azure specific configuration options:
* an array `['8000-9000', '9100-9200']`,
* a single interval as `'8000-9000'`,
* a single port as `8000`.

### Optional Windows Parameters
* `winrm_install_self_signed_cert`: (Optional, Windows only) Whether to install a self-signed cert automatically to enable WinRM to communicate over HTTPS (5986). Only available when a custom `deployment_template` is not supplied. Default 'true'.

### Optional Provisioning Parameters
* `instance_ready_timeout`: (Optional) The timeout to wait for an instance to become ready -- default 120 seconds.
* `instance_check_interval`: (Optional) The interval to wait for checking an instance's state -- default 2 seconds.
* `endpoint`: (Optional) The Azure Management API endpoint -- default `ENV['AZURE_MANAGEMENT_ENDPOINT']` if exists, falls back to <https://management.azure.com>.
* `admin_username`: (Optional) The root/administrator username for the VM
* `admin_password`: (Optional, Windows only) The password to set for the windows administrator user
* `winrm_install_self_signed_cert`: (Optional, Windows only) Whether to install a self-signed cert automatically to enable WinRM to communicate over HTTPS (5986). Only available when a custom `deployment_template` is not supplied. Default 'true'.
* `deployment_template`: (Optional) A custom ARM template to use instead of the default template
* `wait_for_destroy`: (Optional) Wait for all resources to be deleted prior to completing Vagrant destroy -- default false.

### Optional Azure Parameters
* `endpoint`: (Optional) The Azure Management API endpoint -- default `ENV['AZURE_MANAGEMENT_ENDPOINT']` if exists, falls back to <https://management.azure.com>.
* `resource_group_name`: (Optional) Name of the resource group to use.
* `location`: (Optional) Azure location to build the VM -- defaults to `westus`

## [Extended Documentation](./docs/)
For more information on common scenarios and other features visit the [extended documentation](./docs/).

17 changes: 17 additions & 0 deletions docs/basic_linux/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

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"]
azure.location = "westus"
end

config.vm.provision "shell", inline: "echo Hello, World"
end
12 changes: 12 additions & 0 deletions docs/basic_linux/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Basic Linux Machine
This scenario will build an Ubuntu 16.04 machine.

Before you attempt this scenario, ensure you have followed the [getting started docs](../../readme.md#getting-started).

## Vagrant up
- In this directory, run the following
```bash
vagrant up --provider=azure
```

To clean up, run `vagrant destroy`
Loading

0 comments on commit fe4de98

Please sign in to comment.