chef-provisioning-azurerm 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42463ec1cf6179ddd12dc6b5187c71e7ff369bfb
4
- data.tar.gz: 09e49c85dfc2c180cd4ff3a1f67f47fbf5ac49a2
3
+ metadata.gz: e48881cce59c913418c7e5a629be6152b42997f8
4
+ data.tar.gz: 6ee46df17040d68108ca49da6360faab8c2ab568
5
5
  SHA512:
6
- metadata.gz: 55994c329df15108b24a815e386d9e430d83779508e30e420474a602151674e36bb5aaf529a2c1fb8056668988f29625e949fe00c71654c594e50f853e1b6b84
7
- data.tar.gz: ecbfab9b582c27d63c3cace35fbf7350c835e4ddfeb1edb071050b7278a301fa40f879ce9b5225e9f235ce1b9d6bf023a71838521367c78a17a14e5c32c5fed7
6
+ metadata.gz: bcaa0448d4f51d03cb557870e6778d165f3911a93dc33ca04fee95300b8337c1f35760ff738835ecae82a2f1dad1ba28521cc337a08a242299af6d39fe962969
7
+ data.tar.gz: 297e1d3b7d1a644206a3d188079b934a1aa53ac25953730fa7a6d0212b78656bc099e37ff746b72f03d317c97288e5f86f242d7ef05962215a4571eceafbf8e0
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
  # chef-provisioning-azurerm Changelog
2
+
3
+ ## [0.5.0] - 2017-04-29
4
+ - Support for AzureUSGovernment, AzureChina and AzureGermanyCloud environments (@stuartpreston)
5
+
2
6
  ## [0.4.0] - 2016-10-02
3
7
  - BREAKING CHANGE: No longer assume ARM template_source points to a location within the Chef Repo, users must now specify the complete path to the file (@stuartpreston)
4
8
  - Removing gem dependency on json, chef-provisioning in attempt to maintain compat with <2.0 versions (@stuartpreston)
data/README.md CHANGED
@@ -12,7 +12,7 @@ The driver provides a way to deploy Azure Resource Manager templates using Chef
12
12
 
13
13
  ### Prerequisites
14
14
 
15
- The plugin requires Chef Client 12.2.1 or higher.
15
+ The plugin requires Chef Client 12.5.1 or higher.
16
16
 
17
17
  ### Installation
18
18
 
@@ -22,9 +22,9 @@ This plugin is distributed as a Ruby Gem. To install it, run:
22
22
 
23
23
  ### Configuration
24
24
 
25
- 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. Using an Organization account and related password is no longer supported. To create a Service Principal and apply the correct permissions, follow the instructions in the article: [Authenticating a service principal with Azure Resource Manager](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/#authenticate-service-principal-with-password---azure-cli)
25
+ For the driver to interact with the Microsoft Azure Resource management REST API, a Service Principal needs to be configured with Contributor rights against the specific subscription being targeted. Using an Organization account and related password is no longer supported. To create a Service Principal and apply the correct permissions, follow the instructions in the article: [Create an Azure service principal with Azure CLI 2.0](https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli?toc=%2fazure%2fazure-resource-manager%2ftoc.json)
26
26
 
27
- 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.
27
+ You will essentially need 4 parametersto configure Chef Provisioning: **Subscription ID**, **Client ID/ID**, **Client Secret/Password** and **Tenant ID/Tenant**.
28
28
 
29
29
  Using a text editor, open or create the file ```~/.azure/credentials``` and add the following section:
30
30
 
@@ -35,6 +35,8 @@ client_secret = "your-client-secret-here"
35
35
  tenant_id = "9c117323-YOUR-GUID-HERE-9ee430723ba3"
36
36
  ```
37
37
 
38
+ Ensure you save the file as using UTF-8 encoding.
39
+
38
40
  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
39
41
 
40
42
  ```ruby
@@ -49,26 +51,21 @@ Note that the environment variables, if set, take preference over the values in
49
51
 
50
52
  Unlike a fully-featured **chef-provisioning** driver that fully utilises the **machine**, **machine_batch**, **machine_image** and **load_balancer** resources, the **chef-provisioning-azurerm** driver offers a lightweight way to interact with resources and providers in the Azure Resource Manager framework directly.
51
53
 
52
- To work around the issue of storing chef-provisioning driver info in the Chef server:
54
+ To work around the issue of storing chef-provisioning driver info in the Chef server:
53
55
  - The Chef VM extension will automatically be configured to point at the same Chef server as the provisioning node. This can be overridden in a recipe by using the following line: ```with_chef_server 'http://your.chef.server.url/yourorg'```
54
56
 
55
- The following resources are provided:
57
+ The following resources are provided:
56
58
 
57
59
  - azure_resource_group
58
60
  - azure_resource_template
61
+
62
+ The following resources are _deprecated_ and will be removed in a future version - if you want to provision individual resources in Azure you should consider alternative tooling, such as [Terraform](https://terraform.io)
63
+
59
64
  - azure_storage_account
60
65
  - azure_virtual_network
61
66
  - azure_network_interface
62
67
  - azure_public_ip_address
63
68
 
64
- The following resources are planned (note: these resources may be renamed as they are implemented):
65
-
66
- - azure_availability_set
67
- - azure_load_balancer
68
- - azure_network_security_group
69
- - azure_virtual_machine
70
- - PaaS resources such as TrafficManager, SQL Server etc.
71
-
72
69
  ## Limitations
73
70
  - As the nodes self-register, there are no "managed entries" created on the Chef server other than for resources of type Microsoft.Compute.
74
71
  - Bootstrap over SSH or WinRM is not implemented
@@ -76,14 +73,14 @@ The following resources are planned (note: these resources may be renamed as the
76
73
  - machine, machine_batch, machine_image and load_balancer resources are not implemented
77
74
  - Azure resources that can only be created through the Service Management (ASM) API are not implemented
78
75
  - The path to the validation keys must be provided within the recipe (i.e. they must be in the chef-repo you are working with)
79
- - **Local mode** is not currently supported - the Chef VM extensions can only register themselves with a 'real' Chef server.
80
-
76
+ - **Local mode** is not supported - Chef VM extensions can only register themselves with a 'real' Chef server.
77
+
81
78
  ## Example Recipe 1 - deployment of Resource Manager template
82
- The following recipe creates a new Resource Group within your subscription (identified by the GUID on line 2). It will then execute a resource template by merging the content at the given uri with the parameters specified.
79
+ The following recipe creates a new Resource Group within your subscription (identified by the GUID on line 2). It will then deploy a resource template by merging the content with the parameters specified.
83
80
 
84
- A ```deployment_template.json``` is required to be copied to ```cookbooks/provision/templates/default/recipes``` - many examples of a Resource Manager deployment template can be found at the [Azure QuickStart Templates Gallery on GitHub](https://github.com/Azure/azure-quickstart-templates).
81
+ An ```azure_deploy.json``` is required to be copied to ```cookbooks/provision/templates/default/recipes``` - many examples of a Resource Manager deployment template can be found at the [Azure QuickStart Templates Gallery on GitHub](https://github.com/Azure/azure-quickstart-templates).
85
82
 
86
- For our example, we'll need the azure_deploy.json from [here](https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-simple-windows-vm/azuredeploy.json) and copy it to a path in our repo. Make sure you amend the path appropriately.
83
+ For our example, we'll need the azure_deploy.json from [here](https://github.com/Azure/azure-quickstart-templates/blob/master/101-vm-simple-windows/azuredeploy.json) and copy it to a path in our repo. Make sure you amend the path appropriately.
87
84
 
88
85
  ### example1.rb
89
86
 
@@ -92,13 +89,13 @@ require 'chef/provisioning/azurerm'
92
89
  with_driver 'AzureRM:abcd1234-YOUR-GUID-HERE-abcdef123456'
93
90
 
94
91
  azure_resource_group 'pendrica-demo' do
95
- location 'West US' # optional, default: 'West US'
96
- tags businessUnit: 'IT' # optional
92
+ location 'West US'
93
+ tags businessUnit: 'IT'
97
94
  end
98
95
 
99
96
  azure_resource_template 'my-deployment' do
100
97
  resource_group 'pendrica-demo'
101
- template_source 'cookbooks/provision/files/default/azure_deploy.json'
98
+ template_source "#{Chef::Config[:cookbook_path]}/provision/files/default/azure_deploy.json"
102
99
  parameters newStorageAccountName: "mystorageaccount01",
103
100
  adminUsername: 'stuart',
104
101
  adminPassword: 'P2ssw0rd',
@@ -107,12 +104,13 @@ azure_resource_template 'my-deployment' do
107
104
  chef_extension client_type: 'ChefClient',
108
105
  version: '1210.12',
109
106
  runlist: 'role[webserver]'
107
+ environment: '_default'
110
108
  end
111
109
  ```
112
110
 
113
- **Note: If no chef_extension configuration is specified, the ARM template will imported without enabling the Azure Chef VM Extension.**
111
+ **Note: If no chef_extension configuration is specified, the ARM template will be deployed without enabling the Azure Chef VM Extension.**
114
112
 
115
- The Chef Server URL, Validation Client name and Validation Key content are not currently exposed parameters but can be overridden via setting the following Chef::Config parameters (via modifying ```c:\chef\client.rb``` or specifying ```-c path\to\client.rb``` on the ```chef-client``` command line).
113
+ The Chef Server URL, Validation Client name and Validation Key content are not currently exposed parameters but are either inherited from the running configuration or can be overridden via setting the following Chef::Config parameters (via modifying ```c:\chef\client.rb``` or specifying ```-c path\to\client.rb``` on the ```chef-client``` command line).
116
114
 
117
115
  ```ruby
118
116
  Chef::Config[:chef_server_url]
@@ -120,102 +118,26 @@ Chef::Config[:validation_client_name]
120
118
  Chef::Config[:validation_key]
121
119
  ```
122
120
 
123
- ## Example Recipe 2 - deployment of locally replicated Storage Account
124
- ### example2.rb
121
+ ## Support for AzureUSGovernment, AzureChina, AzureGermanCloud environments
122
+
123
+ The driver will automatically use the correct token provider and management endpoints for the relevant cloud environment. The default driver format for the Azure public cloud is:
125
124
 
126
125
  ```ruby
127
- require 'chef/provisioning/azurerm'
128
126
  with_driver 'AzureRM:abcd1234-YOUR-GUID-HERE-abcdef123456'
129
-
130
- azure_resource_group 'pendrica-demo' do
131
- location 'West US'
132
- end
133
-
134
- azure_storage_account 'mystorageaccount02' do
135
- resource_group 'pendrica-demo'
136
- location 'West US'
137
- account_type 'Standard_LRS'
138
- end
139
127
  ```
140
-
141
- ## Example Recipe 3 - deployment of Virtual Network
142
- This example creates a virtual network named 'myvnet' in the pendrica-demo
143
- resource group in the West US region. This virtual network contains 4 subnets
144
- in the 10.123.123.0/24 CIDR block. The specified DNS servers will be used
145
- used by VMs in this virtual network.
146
-
147
- **Note that if dns_servers are not specified, the default azure dns will
148
- be used.
149
128
 
150
- ### example3.rb
129
+ This can be changed to one of the following formats:
151
130
 
152
131
  ```ruby
153
- require 'chef/provisioning/azurerm'
154
- with_driver 'AzureRM:abcd1234-YOUR-GUID-HERE-abcdef123456'
155
-
156
- azure_resource_group 'pendrica-demo' do
157
- location 'West US'
158
- end
159
-
160
- azure_virtual_network 'myvnet' do
161
- action :create
162
- resource_group 'pendrica-demo'
163
- location 'West US'
164
- address_prefixes ['10.123.123.0/24' ]
165
- subnets [
166
- { name: 'infrastructure', address_prefix: '10.123.123.0/28' },
167
- { name: 'data', address_prefix: '10.123.123.32/27' },
168
- { name: 'app', address_prefix: '10.123.123.64/26' },
169
- { name: 'web', address_prefix: '10.123.123.128/25' },
170
- ]
171
- dns_servers ['10.123.123.5', '10.123.123.6']
172
- tags environment: 'test',
173
- owner: 'jsmyth'
174
- end
175
-
176
-
132
+ with_driver 'AzureUSGovernment:abcd1234-YOUR-GUID-HERE-abcdef123456'
177
133
  ```
178
134
 
179
- ## Example Recipe 4 - deployment of Network Interface
180
- This example creates a network interface named mynic2 on the 'web' subnet of a virtual network named 'myvnet'.
181
-
182
- ### example4.rb
183
-
184
135
  ```ruby
185
- azure_network_interface 'mynic2' do
186
- action :create
187
- resource_group 'pendrica-demo'
188
- location 'West US'
189
- virtual_network 'myvnet'
190
- subnet 'web'
191
- end
136
+ with_driver 'AzureChina:abcd1234-YOUR-GUID-HERE-abcdef123456'
192
137
  ```
193
138
 
194
- ## Example Recipe 5 - deployment of Network Interface with a private static address and a public IP
195
- This example creates a network interface named mynic on the 'web' subnet of a virtual network named 'myvnet'. This interface
196
- has a statically assigned IP address and dns servers, as well as a dynamically assigned Public IP address.
197
-
198
- ### example5.rb
199
-
200
139
  ```ruby
201
- azure_network_interface 'mynic' do
202
- action :create
203
- resource_group 'pendrica-demo'
204
- location 'West US'
205
- virtual_network 'myvnet'
206
- subnet 'web'
207
- private_ip_allocation_method 'static'
208
- private_ip_address '10.123.123.250'
209
- dns_servers ['10.123.123.5', '10.123.123.6']
210
- public_ip 'mynic-pip' do
211
- public_ip_allocation_method 'dynamic'
212
- domain_name_label 'mydnsname'
213
- idle_timeout_in_minutes 15
214
- tags environment: 'test',
215
- owner: 'jsmyth'
216
- end
217
- end
218
-
140
+ with_driver 'AzureGermanCloud:abcd1234-YOUR-GUID-HERE-abcdef123456'
219
141
  ```
220
142
 
221
143
  ## Contributing
@@ -13,33 +13,48 @@ class Chef
13
13
  end
14
14
 
15
15
  def resource_management_client
16
- credentials = Credentials.new.azure_credentials_for_subscription(new_resource.subscription_id)
17
- client = Azure::ARM::Resources::ResourceManagementClient.new(credentials)
16
+ credentials = Credentials.new.azure_credentials_for_subscription(new_resource.subscription_id, new_resource.driver_name)
17
+ client = Azure::ARM::Resources::ResourceManagementClient.new(credentials, resource_manager_endpoint_url(new_resource.driver_name))
18
18
  client.subscription_id = new_resource.subscription_id
19
19
  client
20
20
  end
21
21
 
22
22
  def storage_management_client
23
- credentials = Credentials.new.azure_credentials_for_subscription(new_resource.subscription_id)
24
- client = Azure::ARM::Storage::StorageManagementClient.new(credentials)
23
+ credentials = Credentials.new.azure_credentials_for_subscription(new_resource.subscription_id, new_resource.driver_name)
24
+ client = Azure::ARM::Storage::StorageManagementClient.new(credentials, resource_manager_endpoint_url(new_resource.driver_name))
25
25
  client.subscription_id = new_resource.subscription_id
26
26
  client
27
27
  end
28
28
 
29
29
  def compute_management_client
30
- credentials = Credentials.new.azure_credentials_for_subscription(new_resource.subscription_id)
31
- client = Azure::ARM::Compute::ComputeManagementClient.new(credentials)
30
+ credentials = Credentials.new.azure_credentials_for_subscription(new_resource.subscription_id, new_resource.driver_name)
31
+ client = Azure::ARM::Compute::ComputeManagementClient.new(credentials, resource_manager_endpoint_url(new_resource.driver_name))
32
32
  client.subscription_id = new_resource.subscription_id
33
33
  client
34
34
  end
35
35
 
36
36
  def network_management_client
37
- credentials = Credentials.new.azure_credentials_for_subscription(new_resource.subscription_id)
38
- client = Azure::ARM::Network::NetworkResourceProviderClient.new(credentials)
37
+ credentials = Credentials.new.azure_credentials_for_subscription(new_resource.subscription_id, new_resource.driver_name)
38
+ client = Azure::ARM::Network::NetworkResourceProviderClient.new(credentials, resource_manager_endpoint_url(new_resource.driver_name))
39
39
  client.subscription_id = new_resource.subscription_id
40
40
  client
41
41
  end
42
42
 
43
+ def resource_manager_endpoint_url(azure_environment)
44
+ case azure_environment.downcase
45
+ when 'azureusgovernment'
46
+ MsRestAzure::AzureEnvironments::AzureUSGovernment.resource_manager_endpoint_url
47
+ when 'azurechina'
48
+ MsRestAzure::AzureEnvironments::AzureChina.resource_manager_endpoint_url
49
+ when 'azuregermancloud'
50
+ MsRestAzure::AzureEnvironments::AzureGermanCloud.resource_manager_endpoint_url
51
+ when 'azurerm'
52
+ MsRestAzure::AzureEnvironments::Azure.resource_manager_endpoint_url
53
+ when 'azure'
54
+ MsRestAzure::AzureEnvironments::Azure.resource_manager_endpoint_url
55
+ end
56
+ end
57
+
43
58
  def try_azure_operation(description, silently_continue_on_error = false)
44
59
  begin
45
60
  result = yield
@@ -15,14 +15,35 @@ class Chef
15
15
  end
16
16
  end
17
17
 
18
- def azure_credentials_for_subscription(subscription_id)
18
+ def azure_credentials_for_subscription(subscription_id, azure_environment)
19
19
  tenant_id = ENV['AZURE_TENANT_ID'] || @credentials[subscription_id]['tenant_id']
20
20
  client_id = ENV['AZURE_CLIENT_ID'] || @credentials[subscription_id]['client_id']
21
21
  client_secret = ENV['AZURE_CLIENT_SECRET'] || @credentials[subscription_id]['client_secret']
22
- token_provider = MsRestAzure::ApplicationTokenProvider.new(tenant_id, client_id, client_secret)
22
+ token_provider = MsRestAzure::ApplicationTokenProvider.new(tenant_id, client_id, client_secret, settings_for_azure_environment(azure_environment))
23
23
  MsRest::TokenCredentials.new(token_provider)
24
24
  end
25
25
 
26
+ #
27
+ # Retrieves a [MsRestAzure::ActiveDirectoryServiceSettings] object representing the settings for the given cloud.
28
+ # @param azure_environment [String] The Azure environment to retrieve settings for.
29
+ #
30
+ # @return [MsRestAzure::ActiveDirectoryServiceSettings] Settings to be used for subsequent requests
31
+ #
32
+ def settings_for_azure_environment(azure_environment)
33
+ case azure_environment.downcase
34
+ when 'azureusgovernment'
35
+ ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_us_government_settings
36
+ when 'azurechina'
37
+ ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_china_settings
38
+ when 'azuregermancloud'
39
+ ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_germany_settings
40
+ when 'azurerm'
41
+ ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings
42
+ when 'azure'
43
+ ::MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings
44
+ end
45
+ end
46
+
26
47
  def self.singleton
27
48
  @credentials ||= Credentials.new
28
49
  end
@@ -1,7 +1,7 @@
1
1
  class Chef
2
2
  module Provisioning
3
3
  module AzureRM
4
- VERSION = '0.4.0'.freeze
4
+ VERSION = '0.5.0'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning-azurerm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Preston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-17 00:00:00.000000000 Z
11
+ date: 2017-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '12'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 13.0.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ">="
27
+ - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: '0'
29
+ version: '12'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 13.0.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: chef-provisioning
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '0'
39
+ version: '2.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 2.3.0
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - ">="
47
+ - - "~>"
39
48
  - !ruby/object:Gem::Version
40
- version: '0'
49
+ version: '2.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.0
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: azure_mgmt_resources
43
55
  requirement: !ruby/object:Gem::Requirement
@@ -195,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
207
  version: '0'
196
208
  requirements: []
197
209
  rubyforge_project:
198
- rubygems_version: 2.6.7
210
+ rubygems_version: 2.6.10
199
211
  signing_key:
200
212
  specification_version: 4
201
213
  summary: Chef Provisioner for the Azure Resource Management (ARM) REST API.