kitchen-azurerm 0.2.6 → 0.3.1.pre

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: b24b970ab88760f88f81546dbb8809561f91120e
4
- data.tar.gz: 46bbfb0905c418c9b8676bfa7b1d40ef4d9291cf
3
+ metadata.gz: ec8f20a56864bfe1b156c1de219296fd7d989514
4
+ data.tar.gz: f1cd4d4df570fed5a7a38a30563d08fd5e0b7fae
5
5
  SHA512:
6
- metadata.gz: 433f0b5b6a9c5a420dc60c3a4db656ec54030b77a8cc63f0fb6446f6eacb39d1bed0790fca23ba0c4bbfae89f93cdc6db089b69ddd2a034512f8dba49729e6f4
7
- data.tar.gz: 24de08d4b408e9ab3380b56b64bdf5b191f577cc79d32d4a4cc7292e9a4c990f10f204cc6d1634d6fa6f39effa2fe743e2f0310e90a51a3cc2d9f48444cdbe36
6
+ metadata.gz: 558b375c9a445c4ba8000392e48e1eccd09b09c6c9c2c052bf754622d0ea0cbfa1c47bfe6bda34a3c7de3c59ac0e0cb65b0dcfaf7d0806a7506969533c992cdd
7
+ data.tar.gz: c2089548a61769a3dcaf44c90c7161f5f433cc5acf6a3e2e11e0912206694715de844fb60a13f1a0c15abc30ab1f4278c277d3337633d5c7c2ea4d7010fcf29f
@@ -1,5 +1,9 @@
1
1
  # kitchen-azurerm Changelog
2
2
 
3
+ ## [0.3.0] - 2016-02-29
4
+ - Breaking: Linux machines are now created using a temporary sshkey (~/.ssh/id_kitchen) instead of password (@stuartpreston)
5
+ - Real error message shown if credentials are incorrect (@stuartpreston)
6
+
3
7
  ## [0.2.4] - 2016-01-26
4
8
  - Support Premium Storage and Boot Diagnostics (@stuartpreston)
5
9
  - If deployment fails, show the message from the failing operation (@stuartpreston)
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/kitchen-azurerm.svg)](http://badge.fury.io/rb/kitchen-azurerm) [![Build Status](https://travis-ci.org/pendrica/kitchen-azurerm.svg)](https://travis-ci.org/pendrica/kitchen-azurerm)
6
6
 
7
- This version has been tested on Windows, OS/X and Ubuntu. If you encounter a problem on your platform, please raise an issue.
7
+ This version has been tested on Windows, OS/X and Ubuntu. If you encounter a problem on your platform, please raise an issue.
8
8
 
9
9
  ## Quick-start
10
10
  ### Installation
@@ -16,11 +16,18 @@ Note if you are running the ChefDK you may need to prefix the command with chef,
16
16
 
17
17
  ### Configuration
18
18
 
19
- 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 Organizational (AAD) 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)
19
+ 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 Organizational (AAD) account and related password is no longer supported. To create a Service Principal and apply the correct permissions, you will need to [create and authenticate a service principal](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/#authenticate-service-principal-with-password---azure-cli) using the [Azure CLI](https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-install/). Make sure you stay within the section titled 'Authenticate service principal with password - Azure CLI'.
20
20
 
21
- You will essentially need 4 parameters from the above article to configure kitchen-azurerm: **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.
21
+ You will also need to ensure you have an active Azure subscription (you can get started [for free](https://azure.microsoft.com/en-us/free/) or use your [MSDN Subscription](https://azure.microsoft.com/en-us/pricing/member-offers/msdn-benefits/)).
22
22
 
23
- Using a text editor, open or create the file ```~/.azure/credentials``` and add the following section, noting there is one section per Subscription ID. **Make sure you save the file with UTF-8 encoding**
23
+ You are now ready to configure kitchen-azurerm to use the credentials from the service principal you created above. You will use four elements from the steps in that article:
24
+
25
+ 1. **Subscription ID**: available from the azure portal
26
+ 2. **Client ID**: this will be the Application Id from the application in step 2.
27
+ 3. **Client Secret/Password**: this will be the password you supplied in the command in step 2.
28
+ 4. **Tenant ID**: listed after the command in step 5.
29
+
30
+ Using a text editor, open or create the file ```~/.azure/credentials``` and add the following section, noting there is one section per Subscription ID. **Make sure you save the file with UTF-8 encoding**
24
31
 
25
32
  ```ruby
26
33
  [abcd1234-YOUR-SUBSCRIPTION-ID-HERE-abcdef123456]
@@ -41,7 +48,7 @@ Note that the environment variables, if set, take preference over the values in
41
48
 
42
49
  ### .kitchen.yml example 1 - Linux/Ubuntu
43
50
 
44
- Here's an example ```.kitchen.yml``` file that provisions 3 different types of Ubuntu Server, using Chef Zero as the provisioner and SSH as the transport.
51
+ Here's an example ```.kitchen.yml``` file that provisions 3 different types of Ubuntu Server, using Chef Zero as the provisioner and SSH as the transport. Note that if the key does not exist at the specified location, it will be created.
45
52
 
46
53
  ```yml
47
54
  ---
@@ -53,6 +60,9 @@ driver_config:
53
60
  location: 'West Europe'
54
61
  machine_size: 'Standard_D1'
55
62
 
63
+ transport:
64
+ ssh_key: ~/.ssh/id_kitchen-azurerm
65
+
56
66
  provisioner:
57
67
  name: chef_zero
58
68
 
@@ -4,6 +4,8 @@ require 'securerandom'
4
4
  require 'azure_mgmt_resources'
5
5
  require 'azure_mgmt_network'
6
6
  require 'base64'
7
+ require 'sshkey'
8
+ require 'fileutils'
7
9
 
8
10
  module Kitchen
9
11
  module Driver
@@ -80,7 +82,7 @@ module Kitchen
80
82
  info "Creating Resource Group: #{state[:azure_resource_group_name]}"
81
83
  resource_management_client.resource_groups.create_or_update(state[:azure_resource_group_name], resource_group).value!
82
84
  rescue ::MsRestAzure::AzureOperationError => operation_error
83
- info operation_error.body['error']
85
+ info operation_error
84
86
  raise operation_error
85
87
  end
86
88
 
@@ -142,9 +144,40 @@ module Kitchen
142
144
  end
143
145
  template['resources'] << JSON.parse(custom_script_extension_template(command))
144
146
  end
147
+
148
+ if instance.transport.name.casecmp('ssh') == 0 && !instance.transport[:ssh_key].nil?
149
+ info "Adding public key from #{File.expand_path(instance.transport[:ssh_key])}.pub to the deployment."
150
+ public_key = public_key_for_deployment(File.expand_path(instance.transport[:ssh_key]))
151
+ template['resources'].select { |h| h['type'] == 'Microsoft.Compute/virtualMachines' }.each do |resource|
152
+ resource['properties']['osProfile']['linuxConfiguration'] = JSON.parse(custom_linux_configuration(public_key))
153
+ end
154
+ end
145
155
  template.to_json
146
156
  end
147
157
 
158
+ def public_key_for_deployment(private_key_filename)
159
+ if File.file?(private_key_filename) == false
160
+ k = SSHKey.generate
161
+
162
+ ::FileUtils.mkdir_p(File.dirname(private_key_filename))
163
+
164
+ private_key_file = File.new(private_key_filename, 'w')
165
+ private_key_file.syswrite(k.private_key)
166
+ private_key_file.chmod(0600)
167
+ private_key_file.close
168
+
169
+ public_key_file = File.new("#{private_key_filename}.pub", 'w')
170
+ public_key_file.syswrite(k.ssh_public_key)
171
+ public_key_file.chmod(0600)
172
+ public_key_file.close
173
+
174
+ output = k.ssh_public_key
175
+ else
176
+ output = File.read("#{private_key_filename}.pub")
177
+ end
178
+ output
179
+ end
180
+
148
181
  def deployment(parameters)
149
182
  template = template_for_transport_name
150
183
  deployment = ::Azure::ARM::Resources::Models::Deployment.new
@@ -180,7 +213,7 @@ module Kitchen
180
213
  failed_operations = resource_management_client.deployment_operations.list(resource_group, deployment_name).value!
181
214
  failed_operations.body.value.each do |val|
182
215
  resource_code = val.properties.status_code
183
- fail val.properties.status_message.inspect.to_s if resource_code != 'OK'
216
+ raise val.properties.status_message.inspect.to_s if resource_code != 'OK'
184
217
  end
185
218
  end
186
219
 
@@ -238,6 +271,22 @@ New-NetFirewallRule -DisplayName "Windows Remote Management (HTTP-In)" -Name "Wi
238
271
  'copy /y c:\\\\azuredata\\\\customdata.bin c:\\\\azuredata\\\\customdata.ps1 && powershell.exe -ExecutionPolicy Unrestricted -Command \\"start-process powershell.exe -verb runas -argumentlist c:\\\\azuredata\\\\customdata.ps1\\"'
239
272
  end
240
273
 
274
+ def custom_linux_configuration(public_key)
275
+ <<-EOH
276
+ {
277
+ "disablePasswordAuthentication": "true",
278
+ "ssh": {
279
+ "publicKeys": [
280
+ {
281
+ "path": "[concat('/home/',parameters('adminUsername'),'/.ssh/authorized_keys')]",
282
+ "keyData": "#{public_key}"
283
+ }
284
+ ]
285
+ }
286
+ }
287
+ EOH
288
+ end
289
+
241
290
  def custom_script_extension_template(command)
242
291
  <<-EOH
243
292
  {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-azurerm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.1.pre
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-01-26 00:00:00.000000000 Z
11
+ date: 2016-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inifile
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: sshkey
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -135,9 +149,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
149
  version: '0'
136
150
  required_rubygems_version: !ruby/object:Gem::Requirement
137
151
  requirements:
138
- - - ">="
152
+ - - ">"
139
153
  - !ruby/object:Gem::Version
140
- version: '0'
154
+ version: 1.3.1
141
155
  requirements: []
142
156
  rubyforge_project:
143
157
  rubygems_version: 2.4.8