cheese-chef-provisioning-azurerm 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +1 -0
- data/LICENSE.txt +201 -0
- data/README.md +188 -0
- data/lib/chef/provider/azure_network_interface.rb +159 -0
- data/lib/chef/provider/azure_public_ip_address.rb +72 -0
- data/lib/chef/provider/azure_resource_group.rb +40 -0
- data/lib/chef/provider/azure_resource_template.rb +127 -0
- data/lib/chef/provider/azure_storage_account.rb +98 -0
- data/lib/chef/provider/azure_virtual_network.rb +100 -0
- data/lib/chef/provisioning/azurerm/azure_provider.rb +59 -0
- data/lib/chef/provisioning/azurerm/azure_resource.rb +27 -0
- data/lib/chef/provisioning/azurerm/constants.rb +34 -0
- data/lib/chef/provisioning/azurerm/credentials.rb +32 -0
- data/lib/chef/provisioning/azurerm/driver.rb +554 -0
- data/lib/chef/provisioning/azurerm/version.rb +7 -0
- data/lib/chef/provisioning/azurerm.rb +17 -0
- data/lib/chef/provisioning/driver_init/azurerm.rb +2 -0
- data/lib/chef/resource/azure_network_interface.rb +39 -0
- data/lib/chef/resource/azure_public_ip_address.rb +19 -0
- data/lib/chef/resource/azure_resource_group.rb +14 -0
- data/lib/chef/resource/azure_resource_template.rb +17 -0
- data/lib/chef/resource/azure_storage_account.rb +19 -0
- data/lib/chef/resource/azure_virtual_network.rb +39 -0
- metadata +203 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e46d02c74aa1bca38bc1b1b2d8217c40b9f8935f
|
4
|
+
data.tar.gz: 464f2ec0d5a2e92a2b9f51266116990a9a290731
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ccdcfe0d51fd4eea33a43b5d7623ac5add998fb9791d38edd58052795235627eefd14422f17cb6f6f29852b94ecc786290e1bd170417ffcdac7579ea46a9251
|
7
|
+
data.tar.gz: 024a999c276bcd3db08a097f82126ef8c15d3c3dd7edc9e54046dc30f6b02be56d759f7a277b1ebf5668097780d7f3cb1a17e9abe22d58540870db3572e3bdb3
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# cheese-chef-provisioning-azurerm Changelog
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
# cheese-chef-provisioning-azurerm
|
2
|
+
|
3
|
+
```cheese-chef-provisioning-azurerm``` is an extension of ```chef-provisioning-azurerm``` driver to support some basic resources like ```machine``` for [chef-provisioning](https://github.com/chef/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](https://github.com/azure/azure-sdk-for-ruby).
|
4
|
+
|
5
|
+
The driver provides machine resource for Azure.
|
6
|
+
|
7
|
+
**Note:** If you are looking for a driver that works with the existing Microsoft Azure Service Management API please visit [chef-provisioning-azure](https://github.com/chef/chef-provisioning-azure)
|
8
|
+
Or original AzureRM driver please visit [chef-provisioning-azurerm](https://github.com/chef/chef-provisioning-azure)
|
9
|
+
|
10
|
+
## Quick-start
|
11
|
+
|
12
|
+
### Prerequisites
|
13
|
+
|
14
|
+
The plugin requires Chef Client 12.2.1 or higher.
|
15
|
+
|
16
|
+
### Installation
|
17
|
+
|
18
|
+
This plugin is distributed as a Ruby Gem. To install it, run:
|
19
|
+
|
20
|
+
```$ chef gem install cheese-chef-provisioning-azurerm```
|
21
|
+
|
22
|
+
### Configuration
|
23
|
+
|
24
|
+
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](https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/#authenticate-service-principal-with-password---azure-cli)
|
25
|
+
|
26
|
+
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
|
+
|
28
|
+
Using a text editor, open or create the file ```~/.azure/credentials``` and add the following section:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
[abcd1234-YOUR-GUID-HERE-abcdef123456]
|
32
|
+
client_id = "48b9bba3-YOUR-GUID-HERE-90f0b68ce8ba"
|
33
|
+
client_secret = "your-client-secret-here"
|
34
|
+
tenant_id = "9c117323-YOUR-GUID-HERE-9ee430723ba3"
|
35
|
+
```
|
36
|
+
|
37
|
+
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
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
AZURE_CLIENT_ID="48b9bba3-YOUR-GUID-HERE-90f0b68ce8ba"
|
41
|
+
AZURE_CLIENT_SECRET="your-client-secret-here"
|
42
|
+
AZURE_TENANT_ID="9c117323-YOUR-GUID-HERE-9ee430723ba3"
|
43
|
+
```
|
44
|
+
|
45
|
+
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.
|
46
|
+
|
47
|
+
### driver_url
|
48
|
+
```ruby
|
49
|
+
with_driver 'azurerm:abcd1234-YOUR-GUID-HERE-abcdef123456'
|
50
|
+
```
|
51
|
+
|
52
|
+
## Features
|
53
|
+
|
54
|
+
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.
|
55
|
+
|
56
|
+
The following resources are provided by `chef-provisioning-azurerm`
|
57
|
+
|
58
|
+
- azure_resource_group
|
59
|
+
- azure_resource_template
|
60
|
+
- azure_storage_account
|
61
|
+
- azure_virtual_network
|
62
|
+
- azure_network_interface
|
63
|
+
- azure_public_ip_address
|
64
|
+
|
65
|
+
`cheese-chef-provisioning-azurerm` offers
|
66
|
+
|
67
|
+
- azure_data_disk
|
68
|
+
|
69
|
+
# Machine Options
|
70
|
+
|
71
|
+
You can pass machine options that will be used by `machine` and `machine_batch` to
|
72
|
+
configure the machine.
|
73
|
+
|
74
|
+
These options are an extension of the [base options](https://github.com/chef/chef-provisioning#machine-options). Please see that for a list of the `machine_options` shared between drivers.
|
75
|
+
|
76
|
+
The full syntax available in the `bootstrap_options` hash is the hash expected by the Azure Virtual Machines [`create_or_update`](https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update) method. The options seen below in the example are the default options.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
with_machine_options({
|
80
|
+
:transport_address_location => :private_ip # only :private_ip supported with this version
|
81
|
+
:bootstrap_options => {
|
82
|
+
:location => "West US 2", # location for resource
|
83
|
+
:tags => {}, # Hash object of tags to be applied on machine
|
84
|
+
:resource_group_name => "resource-group", # resource group name for VM
|
85
|
+
:virtual_network_name => "virtual-network", # virtual network name for NIC of VM
|
86
|
+
:subnet_name => "network-az-us-west-2", # subnet where NIC will be created for VM
|
87
|
+
:network_security_group_name => "admin-sg", # security group to be applied on NIC
|
88
|
+
:key_name => "azure-key", # name of the key to be used to ssh into VM
|
89
|
+
:osProfile => { # OS profile as specified here https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#osprofile
|
90
|
+
:computerName => "test1", # hostname of VM
|
91
|
+
:adminUsername => "ubuntu", # username for VM
|
92
|
+
:linuxConfiguration => { # https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#bk_linuxconfig
|
93
|
+
:disablePasswordAuthentication => true,
|
94
|
+
:ssh => {
|
95
|
+
:publicKeys => [
|
96
|
+
{
|
97
|
+
:keyData => ""
|
98
|
+
}
|
99
|
+
]
|
100
|
+
}
|
101
|
+
},
|
102
|
+
},
|
103
|
+
:storageProfile => { # only imageReference is used under storage profile
|
104
|
+
:imageReference => { # https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#imageref
|
105
|
+
:publisher => "Canonical",
|
106
|
+
:offer => "UbuntuServer",
|
107
|
+
:sku => "14.04.5-LTS",
|
108
|
+
:version => "14.04.201703280"
|
109
|
+
},
|
110
|
+
:storage_account_type => "Standard_LRS" # this is used to create OS disk
|
111
|
+
},
|
112
|
+
:hardwareProfile => { # https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#hardware
|
113
|
+
:vmSize => "Standard_DS1_v2"
|
114
|
+
},
|
115
|
+
}
|
116
|
+
})
|
117
|
+
```
|
118
|
+
|
119
|
+
This options hash can be supplied to either `with_machine_options` at the recipe level or directly into the `machine_options`
|
120
|
+
attribute.
|
121
|
+
|
122
|
+
## location option
|
123
|
+
`location` for resource creation can be specified at 2 places.
|
124
|
+
This list is in the order of preference
|
125
|
+
- `machine_options[:bootstrap_options][:location]`
|
126
|
+
- `machine_options[:location]`
|
127
|
+
|
128
|
+
|
129
|
+
## Example Recipe - deployment of machine
|
130
|
+
The following recipe creates a new VM within your subscription (identified by the GUID on line 2).
|
131
|
+
|
132
|
+
|
133
|
+
### example1.rb
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
#
|
137
|
+
# Cookbook:: azure-provision
|
138
|
+
# Recipe:: default
|
139
|
+
#
|
140
|
+
# Copyright:: 2017, The Authors, All Rights Reserved.
|
141
|
+
|
142
|
+
require 'chef/provisioning/azurerm'
|
143
|
+
with_driver 'azurerm:abcd1234-YOUR-GUID-HERE-abcdef123456'
|
144
|
+
|
145
|
+
with_machine_options({
|
146
|
+
:bootstrap_options => {
|
147
|
+
:location => "West US 2",
|
148
|
+
:tags => {:business => "my business"},
|
149
|
+
:resource_group_name => "resource-group",
|
150
|
+
:virtual_network_name => "virtual-network",
|
151
|
+
:subnet_name => "network-az-us-west-2",
|
152
|
+
:network_security_group_name => "admin-sg",
|
153
|
+
:key_name => "azure-key",
|
154
|
+
:osProfile => {
|
155
|
+
:computerName => "test1",
|
156
|
+
:adminUsername => "ubuntu",
|
157
|
+
:linuxConfiguration => {
|
158
|
+
:disablePasswordAuthentication => true,
|
159
|
+
:ssh => {
|
160
|
+
:publicKeys => [
|
161
|
+
{
|
162
|
+
:keyData => "replace with your pub key"
|
163
|
+
}
|
164
|
+
]
|
165
|
+
}
|
166
|
+
},
|
167
|
+
},
|
168
|
+
:storageProfile => {
|
169
|
+
:imageReference => {
|
170
|
+
:publisher => "Canonical",
|
171
|
+
:offer => "UbuntuServer",
|
172
|
+
:sku => "14.04.5-LTS",
|
173
|
+
:version => "14.04.201703280"
|
174
|
+
},
|
175
|
+
:storage_account_type => "Standard_LRS"
|
176
|
+
},
|
177
|
+
:hardwareProfile => {
|
178
|
+
:vmSize => "Standard_DS1_v2"
|
179
|
+
},
|
180
|
+
}
|
181
|
+
})
|
182
|
+
|
183
|
+
|
184
|
+
machine "test1" do
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
```
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'chef/provisioning/azurerm/azure_provider'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Provider
|
5
|
+
class AzureNetworkInterface < Chef::Provisioning::AzureRM::AzureProvider
|
6
|
+
provides :azure_network_interface
|
7
|
+
|
8
|
+
def whyrun_supported?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
action :create do
|
13
|
+
network_interface_exists = does_network_interface_exist
|
14
|
+
if network_interface_exists
|
15
|
+
converge_by("update network interface #{new_resource.name}") do
|
16
|
+
# currently, we let ARM manage the idempotence, so crete and update are the same
|
17
|
+
new_resource.public_ip_resource.run_action(:create) if new_resource.public_ip_resource
|
18
|
+
create_or_update_network_interface # are create and update different (and should they be??)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
converge_by("create network interface #{new_resource.name}") do
|
22
|
+
new_resource.public_ip_resource.run_action(:create) if new_resource.public_ip_resource
|
23
|
+
create_or_update_network_interface
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
action :destroy do
|
29
|
+
converge_by("destroy network interface: #{new_resource.name}") do
|
30
|
+
if does_network_interface_exist
|
31
|
+
destroy_network_interface
|
32
|
+
new_resource.public_ip_resource.run_action(:destroy) if new_resource.public_ip_resource
|
33
|
+
else
|
34
|
+
action_handler.report_progress "network interface #{new_resource.name} was not found."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_current_resource
|
40
|
+
if new_resource.public_ip_resource
|
41
|
+
new_resource.public_ip_resource.location(new_resource.location)
|
42
|
+
new_resource.public_ip_resource.resource_group(new_resource.resource_group) unless new_resource.public_ip_resource.resource_group
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def does_network_interface_exist
|
47
|
+
network_interface_list = try_azure_operation('enumerating network interfaces') do
|
48
|
+
network_management_client.network_interfaces.list(new_resource.resource_group)
|
49
|
+
end
|
50
|
+
|
51
|
+
network_interface_list.value.each do |network_interface|
|
52
|
+
return true if network_interface.name == new_resource.name
|
53
|
+
end
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
57
|
+
def destroy_network_interface
|
58
|
+
action_handler.report_progress 'Destroying network interface...'
|
59
|
+
try_azure_operation 'destroying network interface' do
|
60
|
+
network_management_client.network_interfaces.delete(new_resource.resource_group, new_resource.name)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_or_update_network_interface
|
65
|
+
network_interface_params = create_network_interface_params
|
66
|
+
action_handler.report_progress 'Creating or Updating network interface...'
|
67
|
+
try_azure_operation 'Creating or Updating network interface' do
|
68
|
+
network_management_client.network_interfaces.create_or_update(new_resource.resource_group, new_resource.name, network_interface_params)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def create_network_interface_params
|
73
|
+
network_interface = create_network_interface(new_resource.name, new_resource.tags, new_resource.location)
|
74
|
+
|
75
|
+
new_resource.virtual_network_resource_group(new_resource.resource_group) unless new_resource.virtual_network_resource_group
|
76
|
+
subnet_ref = get_subnet_ref(new_resource.virtual_network_resource_group,
|
77
|
+
new_resource.virtual_network, new_resource.subnet)
|
78
|
+
|
79
|
+
if new_resource.public_ip_resource
|
80
|
+
public_ip_ref = get_public_ip(new_resource.public_ip_resource.resource_group, new_resource.public_ip_resource.name)
|
81
|
+
end
|
82
|
+
|
83
|
+
network_interface.properties = create_network_interface_properties(
|
84
|
+
new_resource.name, new_resource.private_ip_allocation_method,
|
85
|
+
new_resource.private_ip_address, subnet_ref, new_resource.dns_servers, public_ip_ref)
|
86
|
+
|
87
|
+
network_interface
|
88
|
+
end
|
89
|
+
|
90
|
+
def create_network_interface(name, tags, location)
|
91
|
+
network_interface = Azure::ARM::Network::Models::NetworkInterface.new
|
92
|
+
network_interface.name = name
|
93
|
+
network_interface.tags = tags
|
94
|
+
network_interface.location = location
|
95
|
+
|
96
|
+
network_interface
|
97
|
+
end
|
98
|
+
|
99
|
+
def create_network_interface_properties(interface_name, private_ip_type, private_ip, subnet_ref, dns_servers, public_ip_ref)
|
100
|
+
nic_properties = Azure::ARM::Network::Models::NetworkInterfacePropertiesFormat.new
|
101
|
+
|
102
|
+
nic_properties.dns_settings = create_network_interface_dns_settings(dns_servers) if dns_servers
|
103
|
+
|
104
|
+
ip_config = create_network_interface_ip_configuration("#{interface_name}-ipconfig", private_ip_type, private_ip, subnet_ref, public_ip_ref)
|
105
|
+
nic_properties.ip_configurations = [ip_config]
|
106
|
+
|
107
|
+
nic_properties
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_network_interface_dns_settings(dns_servers)
|
111
|
+
dns_settings = Azure::ARM::Network::Models::NetworkInterfaceDnsSettings.new
|
112
|
+
dns_settings.dns_servers = dns_servers
|
113
|
+
dns_settings
|
114
|
+
end
|
115
|
+
|
116
|
+
def create_network_interface_ip_configuration(ipconfig_name, private_ip_type, private_ip, subnet_ref, public_ip_ref)
|
117
|
+
ip_config = Azure::ARM::Network::Models::NetworkInterfaceIpConfiguration.new
|
118
|
+
ip_config.name = ipconfig_name
|
119
|
+
ip_config.properties = Azure::ARM::Network::Models::NetworkInterfaceIpConfigurationPropertiesFormat.new
|
120
|
+
ip_config.properties.private_ipallocation_method = private_ip_type if private_ip_type
|
121
|
+
ip_config.properties.private_ipaddress = private_ip if private_ip
|
122
|
+
|
123
|
+
if subnet_ref
|
124
|
+
ip_config.properties.subnet = Azure::ARM::Network::Models::Subnet.new
|
125
|
+
ip_config.properties.subnet.id = subnet_ref
|
126
|
+
end
|
127
|
+
|
128
|
+
if public_ip_ref
|
129
|
+
ip_config.properties.public_ipaddress = Azure::ARM::Network::Models::PublicIpAddress.new
|
130
|
+
ip_config.properties.public_ipaddress.id = public_ip_ref
|
131
|
+
end
|
132
|
+
|
133
|
+
ip_config
|
134
|
+
end
|
135
|
+
|
136
|
+
def get_public_ip(resource_group, resource_name)
|
137
|
+
result = try_azure_operation('getting public IP') do
|
138
|
+
network_management_client.public_ip_addresses.get(resource_group, resource_name)
|
139
|
+
end
|
140
|
+
|
141
|
+
public_ip = result
|
142
|
+
public_ip.id
|
143
|
+
end
|
144
|
+
|
145
|
+
def get_subnet_ref(resource_group_name, vnet_name, subnet_name)
|
146
|
+
[resource_group_name, vnet_name, subnet_name].each do |v|
|
147
|
+
return nil if v.nil? || v.empty?
|
148
|
+
end
|
149
|
+
|
150
|
+
result = try_azure_operation('getting subnet') do
|
151
|
+
network_management_client.subnets.get(resource_group_name, vnet_name, subnet_name)
|
152
|
+
end
|
153
|
+
subnet = result
|
154
|
+
|
155
|
+
subnet.id
|
156
|
+
end
|
157
|
+
end # class AzureNetworkInterface
|
158
|
+
end # class Provider
|
159
|
+
end # class Chef
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'chef/provisioning/azurerm/azure_provider'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Provider
|
5
|
+
class AzurePublicIPAddress < Chef::Provisioning::AzureRM::AzureProvider
|
6
|
+
provides :azure_public_ip_address
|
7
|
+
|
8
|
+
def whyrun_supported?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
action :create do
|
13
|
+
converge_by("create or update public IP address #{new_resource.name}") do
|
14
|
+
create_public_ip_address
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
action :destroy do
|
19
|
+
converge_by("destroy public IP address #{new_resource.name}") do
|
20
|
+
if public_ip_address_exists
|
21
|
+
destroy_public_ip_address
|
22
|
+
else
|
23
|
+
action_handler.report_progress "public IP address #{new_resource.name} was not found."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def public_ip_address_exists
|
29
|
+
public_ip_address_list = network_management_client.public_ip_addresses.list(new_resource.resource_group)
|
30
|
+
public_ip_address_list.value.each do |public_ip_address|
|
31
|
+
return true if public_ip_address.name == new_resource.name
|
32
|
+
end
|
33
|
+
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_public_ip_address
|
38
|
+
public_ip_address = Azure::ARM::Network::Models::PublicIpAddress.new
|
39
|
+
public_ip_address.location = new_resource.location
|
40
|
+
public_ip_address.tags = new_resource.tags
|
41
|
+
|
42
|
+
public_ip_address_properties = Azure::ARM::Network::Models::PublicIpAddressPropertiesFormat.new
|
43
|
+
public_ip_address_properties.public_ipallocation_method = new_resource.public_ip_allocation_method
|
44
|
+
public_ip_address_properties.idle_timeout_in_minutes = new_resource.idle_timeout_in_minutes
|
45
|
+
|
46
|
+
if new_resource.domain_name_label || new_resource.reverse_fqdn
|
47
|
+
public_ip_address_properties.dns_settings = create_public_ip_dns_settings(new_resource.domain_name_label, new_resource.reverse_fqdn)
|
48
|
+
end
|
49
|
+
|
50
|
+
public_ip_address.properties = public_ip_address_properties
|
51
|
+
|
52
|
+
try_azure_operation('creating or updating public ip') do
|
53
|
+
network_management_client.public_ip_addresses.create_or_update(new_resource.resource_group, new_resource.name, public_ip_address)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def destroy_public_ip_address
|
58
|
+
try_azure_operation('destroying public ip') do
|
59
|
+
network_management_client.public_ip_addresses.delete(new_resource.resource_group, new_resource.name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_public_ip_dns_settings(domain_name_label, reverse_fqdn)
|
64
|
+
dns_settings = Azure::ARM::Network::Models::PublicIpAddressDnsSettings.new
|
65
|
+
dns_settings.domain_name_label = domain_name_label
|
66
|
+
dns_settings.reverse_fqdn = reverse_fqdn
|
67
|
+
|
68
|
+
dns_settings
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'chef/provisioning/azurerm/azure_provider'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Provider
|
5
|
+
class AzureResourceGroup < Chef::Provisioning::AzureRM::AzureProvider
|
6
|
+
provides :azure_resource_group
|
7
|
+
|
8
|
+
def whyrun_supported?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
action :create do
|
13
|
+
converge_by("create or update Resource Group #{new_resource.name}") do
|
14
|
+
begin
|
15
|
+
resource_group = Azure::ARM::Resources::Models::ResourceGroup.new
|
16
|
+
resource_group.location = new_resource.location
|
17
|
+
resource_group.tags = new_resource.tags
|
18
|
+
result = resource_management_client.resource_groups.create_or_update(new_resource.name, resource_group)
|
19
|
+
Chef::Log.debug("result: #{result.inspect}")
|
20
|
+
rescue ::MsRestAzure::AzureOperationError => operation_error
|
21
|
+
Chef::Log.error operation_error.response.body
|
22
|
+
raise operation_error.response.inspect
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
action :destroy do
|
28
|
+
converge_by("destroy Resource Group #{new_resource.name}") do
|
29
|
+
resource_group_exists = resource_management_client.resource_groups.check_existence(new_resource.name)
|
30
|
+
if resource_group_exists
|
31
|
+
result = resource_management_client.resource_groups.delete(new_resource.name)
|
32
|
+
Chef::Log.debug("result: #{result.inspect}")
|
33
|
+
else
|
34
|
+
action_handler.report_progress "Resource Group #{new_resource.name} was not found."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|