cheese-chef-provisioning-azurerm
cheese-chef-provisioning-azurerm
is an extension of chef-provisioning-azurerm
driver to support some basic resources like machine
for chef-provisioning that allows Microsoft Azure resources to be provisioned by Chef. This driver uses the new Microsoft Azure Resource Management REST API via the azure-sdk-for-ruby.
The driver provides machine resource for Azure.
Note: If you are looking for a driver that works with the existing Microsoft Azure Service Management API please visit chef-provisioning-azure
Or original AzureRM driver please visit chef-provisioning-azurerm
Quick-start
Prerequisites
The plugin requires Chef Client 12.2.1 or higher.
Installation
This plugin is distributed as a Ruby Gem. To install it, run:
$ chef gem install cheese-chef-provisioning-azurerm
Configuration
For the driver to interact with the Microsoft Azure Resource management REST API, a Service Principal needs to be configured with Owner rights against the specific subscription being targeted. To create a Service Principal and apply the correct permissions, follow the instructions in the article: Authenticating a service principal with Azure Resource Manager
You will essentially need 4 parameters from the above article to configure Chef Provisioning: Subscription ID, Client ID, Client Secret/Password and Tenant ID. These can be easily obtained using the azure-cli tools (v0.9.8 or higher) on any platform.
Using a text editor, open or create the file ~/.azure/credentials
and add the following section:
[abcd1234-YOUR-GUID-HERE-abcdef123456]
client_id = "48b9bba3-YOUR-GUID-HERE-90f0b68ce8ba"
client_secret = "your-client-secret-here"
tenant_id = "9c117323-YOUR-GUID-HERE-9ee430723ba3"
If preferred, you may also set the following environment variables on the "provisioning node", replacing the values with those obtained when you configured the service principal
AZURE_CLIENT_ID="48b9bba3-YOUR-GUID-HERE-90f0b68ce8ba"
AZURE_CLIENT_SECRET="your-client-secret-here"
AZURE_TENANT_ID="9c117323-YOUR-GUID-HERE-9ee430723ba3"
Note that the environment variables, if set, take preference over the values in a configuration file. The subscription id will be taken from the recipe.
driver_url
with_driver 'azurerm:abcd1234-YOUR-GUID-HERE-abcdef123456'
Features
Unlike a fully-featured chef-provisioning driver, the chef-provisioning-azurerm driver only offers a way to interact with machine, machine_batch and load_balancer resources.
The following resources are provided by chef-provisioning-azurerm
- azure_resource_group
- azure_resource_template
- azure_storage_account
- azure_virtual_network
- azure_network_interface
- azure_public_ip_address
cheese-chef-provisioning-azurerm
offers
- azure_data_disk
Machine Options
You can pass machine options that will be used by machine
and machine_batch
to
configure the machine.
These options are an extension of the base options. Please see that for a list of the machine_options
shared between drivers.
The full syntax available in the bootstrap_options
hash is the hash expected by the Azure Virtual Machines create_or_update
method. The options seen below in the example are the default options.
with_machine_options({
:transport_address_location => :private_ip # only :private_ip supported with this version
:bootstrap_options => {
:location => "West US 2", # location for resource
:tags => {}, # Hash object of tags to be applied on machine
:resource_group_name => "resource-group", # resource group name for VM
:virtual_network_name => "virtual-network", # virtual network name for NIC of VM
:subnet_name => "network-az-us-west-2", # subnet where NIC will be created for VM
:network_security_group_name => "admin-sg", # security group to be applied on NIC
:key_name => "azure-key", # name of the key to be used to ssh into VM
:osProfile => { # OS profile as specified here https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#osprofile
:computerName => "test1", # hostname of VM
:adminUsername => "ubuntu", # username for VM
:linuxConfiguration => { # https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#bk_linuxconfig
:disablePasswordAuthentication => true,
:ssh => {
:publicKeys => [
{
:keyData => ""
}
]
}
},
},
:storageProfile => { # only imageReference is used under storage profile
:imageReference => { # https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#imageref
:publisher => "Canonical",
:offer => "UbuntuServer",
:sku => "14.04.5-LTS",
:version => "14.04.201703280"
},
:storage_account_type => "Standard_LRS" # this is used to create OS disk
},
:hardwareProfile => { # https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#hardware
:vmSize => "Standard_DS1_v2"
},
}
})
This options hash can be supplied to either with_machine_options
at the recipe level or directly into the machine_options
attribute.
location option
location
for resource creation can be specified at 2 places.
This list is in the order of preference
machine_options[:bootstrap_options][:location]
machine_options[:location]
Example Recipe - deployment of machine
The following recipe creates a new VM within your subscription (identified by the GUID on line 2).
example1.rb
#
# Cookbook:: azure-provision
# Recipe:: default
#
# Copyright:: 2017, The Authors, All Rights Reserved.
require 'chef/provisioning/azurerm'
with_driver 'azurerm:abcd1234-YOUR-GUID-HERE-abcdef123456'
({
:bootstrap_options => {
:location => "West US 2",
:tags => {:business => "my business"},
:resource_group_name => "resource-group",
:virtual_network_name => "virtual-network",
:subnet_name => "network-az-us-west-2",
:network_security_group_name => "admin-sg",
:key_name => "azure-key",
:osProfile => {
:computerName => "test1",
:adminUsername => "ubuntu",
:linuxConfiguration => {
:disablePasswordAuthentication => true,
:ssh => {
:publicKeys => [
{
:keyData => "replace with your pub key"
}
]
}
},
},
:storageProfile => {
:imageReference => {
:publisher => "Canonical",
:offer => "UbuntuServer",
:sku => "14.04.5-LTS",
:version => "14.04.201703280"
},
:storage_account_type => "Standard_LRS"
},
:hardwareProfile => {
:vmSize => "Standard_DS1_v2"
},
}
})
machine "test1" do
end