chef-provisioning-azurerm 0.3.1 → 0.3.2

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: 7da0fd81aef0e92d574dc529def0eed41cda66ad
4
- data.tar.gz: dc963917313890dc4deca22f3654063e19993ac2
3
+ metadata.gz: e622074ff9caf91886b46f9ed52ea099edbe0a6a
4
+ data.tar.gz: 6a1295a76fda9698d7c7ee3a42c8b1492e621d8c
5
5
  SHA512:
6
- metadata.gz: 63fd59b7295bafbc79bd840e5752a81eef01a1fb57ed4014d9e4332bd920b9b3c044001d1cc5637336a768ce944f88ab9f47d754fa303f53e0c2556d8c4a80f4
7
- data.tar.gz: 72f6bcf3afde3b61a7787cab7a1d218ca8fc93842e86a232e03e7f8d434e2788ba99e17dc3f1198a3bc13b190f4aab4b626c791735134bd9069b3c1b94b84ff0
6
+ metadata.gz: af8e73f71ed1882a3c760101a55a4ed4cb91b5985edc7d60be0ede524c25a5d2afcef7e699b20059e67029e3cdc780221f6007ef98c2f84f9d4434db55c98fdd
7
+ data.tar.gz: a7ca2425c44dcf520bd37a564a5d015a7ac7e2e36c4d058138f3b11ae1fa06384c899a05a53176312383d7f47d7d73c03e37a3939ae4ad70a5e07d776541d006
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # chef-provisioning-azurerm Changelog
2
2
 
3
+ ## [0.3.2] - 2015-10-07
4
+ ### Changed
5
+ - References to Azure SDK updated, supports Linux
6
+ - Adding more resources
7
+
3
8
  ## [0.3.1] - 2015-09-05
4
9
  ### Changed
5
10
  - :destroy action on azure_resource_group now correctly detects existence of resource group before attempting deletion
data/README.md CHANGED
@@ -60,15 +60,15 @@ The following resources are provided:
60
60
  - azure_resource_group
61
61
  - azure_resource_template
62
62
  - azure_storage_account
63
+ - azure_virtual_network
64
+ - azure_network_interface
65
+ - azure_public_ip_address
63
66
 
64
67
  The following resources are planned (note: these resources may be renamed as they are implemented):
65
68
 
66
- - azure_virtual_network
67
69
  - azure_availability_set
68
70
  - azure_load_balancer
69
- - azure_network_interface
70
71
  - azure_network_security_group
71
- - azure_public_ip_address
72
72
  - azure_virtual_machine
73
73
  - PaaS resources such as TrafficManager, SQL Server etc.
74
74
 
@@ -141,6 +141,86 @@ azure_storage_account 'mystorageaccount02' do
141
141
  end
142
142
  ```
143
143
 
144
+ ## Example Recipe 3 - deployment of Virtual Network
145
+ This example creates a virtual network named 'myvnet' in the pendrica-demo
146
+ resource group in the West US region. This virtual network contains 4 subnets
147
+ in the 10.123.123.0/24 CIDR block. The specified DNS servers will be used
148
+ used by VMs in this virtual network.
149
+
150
+ **Note that if dns_servers are not specified, the default azure dns will
151
+ be used.
152
+
153
+ ### example3.rb
154
+
155
+ ```ruby
156
+ require 'chef/provisioning/azurerm'
157
+ with_driver 'AzureRM:abcd1234-YOUR-GUID-HERE-abcdef123456'
158
+
159
+ azure_resource_group 'pendrica-demo' do
160
+ location 'West US'
161
+ end
162
+
163
+ azure_virtual_network 'myvnet' do
164
+ action :create
165
+ resource_group 'pendrica-demo'
166
+ location 'West US'
167
+ address_prefixes ['10.123.123.0/24' ]
168
+ subnets [
169
+ { name: 'infrastructure', address_prefix: '10.123.123.0/28' },
170
+ { name: 'data', address_prefix: '10.123.123.32/27' },
171
+ { name: 'app', address_prefix: '10.123.123.64/26' },
172
+ { name: 'web', address_prefix: '10.123.123.128/25' },
173
+ ]
174
+ dns_servers ['10.123.123.5', '10.123.123.6']
175
+ tags environment: 'test',
176
+ owner: 'jsmyth'
177
+ end
178
+
179
+
180
+ ```
181
+
182
+ ## Example Recipe 4 - deployment of Network Interface
183
+ This example creates a network interface named mynic2 on the 'web' subnet of a virtual network named 'myvnet'.
184
+
185
+ ### example4.rb
186
+
187
+ ```ruby
188
+ azure_network_interface 'mynic2' do
189
+ action :create
190
+ resource_group 'pendrica-demo'
191
+ location 'West US'
192
+ virtual_network 'myvnet'
193
+ subnet 'web'
194
+ end
195
+ ```
196
+
197
+ ## Example Recipe 5 - deployment of Network Interface with a private static address and a public IP
198
+ This example creates a network interface named mynic on the 'web' subnet of a virtual network named 'myvnet'. This interface
199
+ has a statically assigned IP address and dns servers, as well as a dynamically assigned Public IP address.
200
+
201
+ ### example5.rb
202
+
203
+ ```ruby
204
+ azure_network_interface 'mynic' do
205
+ action :create
206
+ resource_group 'pendrica-demo'
207
+ location 'West US'
208
+ virtual_network 'myvnet'
209
+ subnet 'web'
210
+ private_ip_allocation_method 'static'
211
+ private_ip_address '10.123.123.250'
212
+ dns_servers ['10.123.123.5', '10.123.123.6']
213
+ public_ip 'mynic-pip' do
214
+ public_ip_allocation_method 'dynamic'
215
+ domain_name_label 'mydnsname'
216
+ idle_timeout_in_minutes 15
217
+ tags environment: 'test',
218
+ owner: 'jsmyth'
219
+ end
220
+ end
221
+
222
+ ```
223
+
144
224
  ## Contributing
145
225
 
146
226
  Contributions to the project are welcome via submitting Pull Requests.
@@ -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).value!
49
+ end
50
+
51
+ network_interface_list.body.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).value!
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).value!
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).value!
139
+ end
140
+
141
+ public_ip = result.body
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).value!
152
+ end
153
+ subnet = result.body
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).value!
30
+ public_ip_address_list.body.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).value!
54
+ end
55
+ end
56
+
57
+ def destroy_public_ip_address
58
+ try_azure_operation('destroyinh public ip') do
59
+ network_management_client.public_ip_addresses.delete(new_resource.resource_group, new_resource.name).value!
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
@@ -15,6 +15,7 @@ class Chef
15
15
  resource_group.location = new_resource.location
16
16
  resource_group.tags = new_resource.tags
17
17
  result = resource_management_client.resource_groups.create_or_update(new_resource.name, resource_group).value!
18
+ Chef::Log.debug("result: #{result.body.inspect}")
18
19
  end
19
20
  end
20
21
 
@@ -23,6 +24,7 @@ class Chef
23
24
  resource_group_exists = resource_management_client.resource_groups.check_existence(new_resource.name).value!
24
25
  if resource_group_exists.body
25
26
  result = resource_management_client.resource_groups.delete(new_resource.name).value!
27
+ Chef::Log.debug("result: #{result.body.inspect}")
26
28
  else
27
29
  action_handler.report_progress "Resource Group #{new_resource.name} was not found."
28
30
  end
@@ -1,7 +1,5 @@
1
1
  require 'chef/provisioning/azurerm/azure_provider'
2
2
 
3
- # MSDN: https://msdn.microsoft.com/en-us/library/azure/mt163564.aspx
4
-
5
3
  class Chef
6
4
  class Provider
7
5
  class AzureStorageAccount < Chef::Provisioning::AzureRM::AzureProvider
@@ -12,28 +10,86 @@ class Chef
12
10
  end
13
11
 
14
12
  action :create do
15
- url = "https://management.azure.com/subscriptions/#{new_resource.subscription_id}/resourcegroups/" \
16
- "#{new_resource.resource_group}/providers/Microsoft.Storage/storageAccounts/#{new_resource.name}" \
17
- '?api-version=2015-05-01-preview'
18
- doc = {
19
- location: new_resource.location,
20
- tags: new_resource.tags,
21
- properties: {
22
- accountType: "#{new_resource.account_type}"
23
- }
24
- }
25
- converge_by("create or update Storage Account: #{new_resource.name}") do
26
- azure_call_until_expected_response(:put, url, doc.to_json, '201,200', 600)
13
+ # Does the storage account already exist in the specified resource group?
14
+ storage_account_exists = does_storage_account_exist
15
+
16
+ # If the storage account already exists, do an update
17
+ if storage_account_exists
18
+ converge_by("update Storage Account #{new_resource.name}") do
19
+ update_storage_account
20
+ end
21
+ else
22
+ # Create the storage account complete with tags and properties
23
+ converge_by("create Storage Account #{new_resource.name}") do
24
+ create_storage_account
25
+ # now update the resource with properties that are not settable in the create operation (e.g. create domain)
26
+ update_storage_account
27
+ end
27
28
  end
28
29
  end
29
30
 
30
31
  action :destroy do
31
- url = "https://management.azure.com/subscriptions/#{new_resource.subscription_id}/resourcegroups/" \
32
- "#{new_resource.resource_group}/providers/Microsoft.Storage/storageAccounts/#{new_resource.name}" \
33
- '?api-version=2015-05-01-preview'
34
32
  converge_by("destroy Storage Account: #{new_resource.name}") do
35
- azure_call_until_expected_response(:delete, url, nil, '404', 600)
33
+ storage_account_exists = does_storage_account_exist
34
+ if storage_account_exists
35
+ action_handler.report_progress 'destroying Storage Account'
36
+ storage_management_client.storage_accounts.delete(new_resource.resource_group, new_resource.name).value!
37
+ else
38
+ action_handler.report_progress "Storage Account #{new_resource.name} was not found."
39
+ end
40
+ end
41
+ end
42
+
43
+ def does_storage_account_exist
44
+ storage_account_list = storage_management_client.storage_accounts.list_by_resource_group(new_resource.resource_group).value!
45
+ storage_account_list.body.value.each do |storage_account|
46
+ return true if storage_account.name == new_resource.name
36
47
  end
48
+ false
49
+ end
50
+
51
+ def create_storage_account
52
+ storage_account = Azure::ARM::Storage::Models::StorageAccountCreateParameters.new
53
+ storage_account.location = new_resource.location
54
+ storage_account.tags = new_resource.tags
55
+ storage_account.properties = Azure::ARM::Storage::Models::StorageAccountPropertiesCreateParameters.new
56
+ storage_account.properties.account_type = new_resource.account_type
57
+ action_handler.report_progress 'creating Storage Account'
58
+ result = storage_management_client.storage_accounts.create(new_resource.resource_group, new_resource.name, storage_account).value!
59
+ Chef::Log.debug(result)
60
+ end
61
+
62
+ def update_storage_account
63
+ update_storage_account_tags
64
+ update_storage_account_account_type
65
+ update_storage_account_custom_domain
66
+ end
67
+
68
+ def update_storage_account_tags
69
+ storage_account = Azure::ARM::Storage::Models::StorageAccountUpdateParameters.new
70
+ storage_account.tags = new_resource.tags
71
+ storage_account.properties = Azure::ARM::Storage::Models::StorageAccountPropertiesUpdateParameters.new
72
+ action_handler.report_progress 'updating Tags'
73
+ result = storage_management_client.storage_accounts.update(new_resource.resource_group, new_resource.name, storage_account).value!
74
+ Chef::Log.debug(result)
75
+ end
76
+
77
+ def update_storage_account_account_type
78
+ storage_account = Azure::ARM::Storage::Models::StorageAccountUpdateParameters.new
79
+ storage_account.properties = Azure::ARM::Storage::Models::StorageAccountPropertiesUpdateParameters.new
80
+ storage_account.properties.account_type = new_resource.account_type
81
+ action_handler.report_progress 'updating Properties'
82
+ result = storage_management_client.storage_accounts.update(new_resource.resource_group, new_resource.name, storage_account).value!
83
+ Chef::Log.debug(result)
84
+ end
85
+
86
+ def update_storage_account_custom_domain
87
+ storage_account = Azure::ARM::Storage::Models::StorageAccountUpdateParameters.new
88
+ storage_account.properties = Azure::ARM::Storage::Models::StorageAccountPropertiesUpdateParameters.new
89
+ storage_account.properties.custom_domain = new_resource.custom_domain
90
+ action_handler.report_progress 'updating Custom Domain'
91
+ result = storage_management_client.storage_accounts.update(new_resource.resource_group, new_resource.name, storage_account).value!
92
+ Chef::Log.debug(result)
37
93
  end
38
94
  end
39
95
  end
@@ -0,0 +1,100 @@
1
+ require 'chef/provisioning/azurerm/azure_provider'
2
+
3
+ class Chef
4
+ class Provider
5
+ class AzureVirtualNetwork < Chef::Provisioning::AzureRM::AzureProvider
6
+ provides :azure_virtual_network
7
+
8
+ def whyrun_supported?
9
+ true
10
+ end
11
+
12
+ action :create do
13
+ virtual_network_exists = does_virtual_network_exist
14
+
15
+ if virtual_network_exists
16
+ converge_by("update virtual network #{new_resource.name}") do
17
+ # currently, we let ARM manage the idempotence, so crete and update are the same
18
+ create_or_update_virtual_network # are create and update different (and should they be??)
19
+ end
20
+ else
21
+ converge_by("create virtual network #{new_resource.name}") do
22
+ create_or_update_virtual_network
23
+ end
24
+ end
25
+ end
26
+
27
+ action :destroy do
28
+ converge_by("destroy virtual network: #{new_resource.name}") do
29
+ if does_virtual_network_exist
30
+ destroy_virtual_network
31
+ else
32
+ action_handler.report_progress "virtual network #{new_resource.name} was not found."
33
+ end
34
+ end
35
+ end
36
+
37
+ def does_virtual_network_exist
38
+ virtual_network_list = try_azure_operation('listing virtual networks') do
39
+ network_management_client.virtual_networks.list(new_resource.resource_group).value!
40
+ end
41
+
42
+ virtual_network_list.body.value.each do |virtual_network|
43
+ return true if virtual_network.name == new_resource.name
44
+ end
45
+ false
46
+ end
47
+
48
+ def destroy_virtual_network
49
+ action_handler.report_progress 'Destroying Virtual Network...'
50
+ try_azure_operation('destroying virtual network') do
51
+ network_management_client.virtual_networks.delete(new_resource.resource_group, new_resource.name).value!
52
+ end
53
+ end
54
+
55
+ def create_or_update_virtual_network
56
+ virtual_network = Azure::ARM::Network::Models::VirtualNetwork.new
57
+
58
+ virtual_network.tags = new_resource.tags
59
+ virtual_network.location = new_resource.location
60
+
61
+ virtual_network.properties = create_virtual_network_properties(
62
+ new_resource.address_prefixes, new_resource.subnets, new_resource.dns_servers)
63
+
64
+ action_handler.report_progress 'Creating or Updating Virtual Network...'
65
+
66
+ try_azure_operation('creating or updating network interface') do
67
+ network_management_client.virtual_networks.create_or_update(new_resource.resource_group, new_resource.name, virtual_network).value!
68
+ end
69
+ end
70
+
71
+ def create_virtual_network_properties(address_prefixes, subnets, dns_servers)
72
+ props = Azure::ARM::Network::Models::VirtualNetworkPropertiesFormat.new
73
+
74
+ props.address_space = Azure::ARM::Network::Models::AddressSpace.new
75
+ props.address_space.address_prefixes = address_prefixes
76
+
77
+ if dns_servers
78
+ props.dhcp_options = Azure::ARM::Network::Models::DhcpOptions.new
79
+ props.dhcp_options.dns_servers = dns_servers
80
+ end
81
+
82
+ props.subnets = []
83
+ subnets.each do |subnet|
84
+ props.subnets.push(create_subnet(subnet[:name], subnet[:address_prefix]))
85
+ end
86
+
87
+ props
88
+ end
89
+
90
+ def create_subnet(subnet_name, subnet_address)
91
+ subnet = Azure::ARM::Network::Models::Subnet.new
92
+ subnet.name = subnet_name
93
+ subnet.properties = Azure::ARM::Network::Models::SubnetPropertiesFormat.new
94
+ subnet.properties.address_prefix = subnet_address
95
+
96
+ subnet
97
+ end
98
+ end # class AzureVirtualNetwork
99
+ end # class Provider
100
+ end # class Chef
@@ -3,11 +3,14 @@ require 'chef/provisioning/version'
3
3
  require 'chef/provisioning/azurerm/driver'
4
4
  require 'chef/provisioning/azurerm/version'
5
5
  require 'azure_mgmt_resources'
6
+ require 'azure_mgmt_storage'
7
+ require 'azure_mgmt_compute'
8
+ require 'azure_mgmt_network'
6
9
 
7
10
  Chef::Log.info("chef-provisioning-azurerm #{Chef::Provisioning::AzureRM::VERSION}")
8
11
  Chef::Log.info("chef-provisioning #{Chef::Provisioning::VERSION}")
9
12
 
10
- resources = %w(resource_group resource_template storage_account)
13
+ resources = %w(resource_group resource_template storage_account virtual_network network_interface public_ip_address)
11
14
  resources.each do |r|
12
15
  require "chef/resource/azure_#{r}"
13
16
  require "chef/provider/azure_#{r}"
@@ -18,6 +18,41 @@ class Chef
18
18
  client.subscription_id = new_resource.subscription_id
19
19
  client
20
20
  end
21
+
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)
25
+ client.subscription_id = new_resource.subscription_id
26
+ client
27
+ end
28
+
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)
32
+ client.subscription_id = new_resource.subscription_id
33
+ client
34
+ end
35
+
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)
39
+ client.subscription_id = new_resource.subscription_id
40
+ client
41
+ end
42
+
43
+ def try_azure_operation(description, silently_continue_on_error = false)
44
+ begin
45
+ result = yield
46
+ rescue MsRestAzure::AzureOperationError => operation_error
47
+ unless silently_continue_on_error
48
+ error = operation_error.body['error']
49
+ Chef::Log.error "ERROR #{description} - #{error}"
50
+ raise operation_error
51
+ end
52
+ end
53
+
54
+ result
55
+ end
21
56
  end
22
57
  end
23
58
  end
@@ -1,7 +1,7 @@
1
1
  class Chef
2
2
  module Provisioning
3
3
  module AzureRM
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.2'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,39 @@
1
+ require 'chef/provisioning/azurerm/azure_resource'
2
+
3
+ class Chef
4
+ class Resource
5
+ class AzureNetworkInterface < Chef::Provisioning::AzureRM::AzureResource
6
+ resource_name :azure_network_interface
7
+
8
+ actions :create, :destroy, :nothing
9
+
10
+ default_action :create
11
+
12
+ attribute :name, kind_of: String, name_attribute: true, regex: /^[\w\-\(\)\.]{0,80}$+(?<!\.)$/i
13
+ attribute :resource_group, kind_of: String
14
+ attribute :location, kind_of: String, default: 'westus'
15
+ attribute :tags, kind_of: Hash
16
+ attribute :private_ip_allocation_method, kind_of: String, equal_to: %w(static dynamic), default: 'dynamic'
17
+ attribute :private_ip_address, kind_of: String, regex: /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
18
+ attribute :virtual_network, kind_of: String
19
+ attribute :virtual_network_resource_group, kind_of: String
20
+ attribute :subnet, kind_of: String
21
+ attribute :dns_servers, kind_of: Array, callbacks: {
22
+ 'should be an array of ip addresses' => lambda do |arg_array|
23
+ arg_array.each do |subnet|
24
+ return false unless subnet =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
25
+ end
26
+ return true
27
+ end
28
+ }
29
+
30
+ attr_reader :public_ip_resource
31
+
32
+ def public_ip(resource_name, &resource_block)
33
+ @public_ip_resource = Chef::Resource::AzurePublicIPAddress.new(resource_name.to_s, run_context)
34
+ @public_ip_resource.action :nothing
35
+ @public_ip_resource.instance_eval(&resource_block)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ require 'chef/provisioning/azurerm/azure_resource'
2
+
3
+ class Chef
4
+ class Resource
5
+ class AzurePublicIPAddress < Chef::Provisioning::AzureRM::AzureResource
6
+ resource_name :azure_public_ip_address
7
+ actions :create, :destroy, :nothing
8
+ default_action :create
9
+ attribute :name, kind_of: String, name_attribute: true
10
+ attribute :location, kind_of: String, default: 'westus'
11
+ attribute :tags, kind_of: Hash
12
+ attribute :resource_group, kind_of: String
13
+ attribute :public_ip_allocation_method, kind_of: String, equal_to: %w(dynamic static), default: 'dynamic'
14
+ attribute :domain_name_label, kind_of: String
15
+ attribute :reverse_fqdn, kind_of: String
16
+ attribute :idle_timeout_in_minutes, kind_of: Integer
17
+ end
18
+ end
19
+ end
@@ -13,6 +13,7 @@ class Chef
13
13
  attribute :location, kind_of: String, default: 'westus'
14
14
  attribute :tags, kind_of: Hash
15
15
  attribute :account_type, kind_of: String, equal_to: %w(Standard_LRS Standard_ZRS Standard_GRS Standard_RAGRS Premium_LRS), default: 'Standard_LRS'
16
+ attribute :custom_domain, kind_of: String
16
17
  end
17
18
  end
18
19
  end
@@ -0,0 +1,39 @@
1
+ require 'chef/provisioning/azurerm/azure_resource'
2
+
3
+ class Chef
4
+ class Resource
5
+ class AzureVirtualNetwork < Chef::Provisioning::AzureRM::AzureResource
6
+ resource_name :azure_virtual_network
7
+ actions :create, :destroy, :nothing
8
+ default_action :create
9
+ attribute :name, kind_of: String, name_attribute: true
10
+ attribute :resource_group, kind_of: String
11
+ attribute :location, kind_of: String, default: 'westus'
12
+ attribute :tags, kind_of: Hash
13
+ attribute :address_prefixes, kind_of: Array, callbacks: {
14
+ 'should be an array of subnets in CIDR format (nnn.nnn.nnn.nnn/nn)' => lambda do |arg_array|
15
+ arg_array.each do |subnet|
16
+ return false unless subnet =~ %r{^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$}
17
+ end
18
+ return true
19
+ end
20
+ }
21
+ attribute :subnets, kind_of: Array, callbacks: {
22
+ 'should be an array of subnet hashes, each with a :name and :address_prefix' => lambda do |arg_array|
23
+ arg_array.each do |subnet|
24
+ return false unless ([:name, :address_prefix].sort == subnet.keys.sort)
25
+ end
26
+ return true
27
+ end
28
+ }
29
+ attribute :dns_servers, kind_of: Array, callbacks: {
30
+ 'should be an array of ip addresses' => lambda do |arg_array|
31
+ arg_array.each do |subnet|
32
+ return false unless subnet =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
33
+ end
34
+ return true
35
+ end
36
+ }
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning-azurerm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Preston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-05 00:00:00.000000000 Z
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -82,16 +82,58 @@ dependencies:
82
82
  name: azure_mgmt_resources
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - "~>"
85
+ - - '='
86
86
  - !ruby/object:Gem::Version
87
- version: '0'
87
+ version: 0.1.1
88
88
  type: :runtime
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - "~>"
92
+ - - '='
93
+ - !ruby/object:Gem::Version
94
+ version: 0.1.1
95
+ - !ruby/object:Gem::Dependency
96
+ name: azure_mgmt_storage
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '='
100
+ - !ruby/object:Gem::Version
101
+ version: 0.1.1
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '='
107
+ - !ruby/object:Gem::Version
108
+ version: 0.1.1
109
+ - !ruby/object:Gem::Dependency
110
+ name: azure_mgmt_compute
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '='
114
+ - !ruby/object:Gem::Version
115
+ version: 0.1.1
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '='
121
+ - !ruby/object:Gem::Version
122
+ version: 0.1.1
123
+ - !ruby/object:Gem::Dependency
124
+ name: azure_mgmt_network
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '='
128
+ - !ruby/object:Gem::Version
129
+ version: 0.1.1
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '='
93
135
  - !ruby/object:Gem::Version
94
- version: '0'
136
+ version: 0.1.1
95
137
  - !ruby/object:Gem::Dependency
96
138
  name: bundler
97
139
  requirement: !ruby/object:Gem::Requirement
@@ -130,9 +172,12 @@ files:
130
172
  - CHANGELOG.md
131
173
  - LICENSE.txt
132
174
  - README.md
175
+ - lib/chef/provider/azure_network_interface.rb
176
+ - lib/chef/provider/azure_public_ip_address.rb
133
177
  - lib/chef/provider/azure_resource_group.rb
134
178
  - lib/chef/provider/azure_resource_template.rb
135
179
  - lib/chef/provider/azure_storage_account.rb
180
+ - lib/chef/provider/azure_virtual_network.rb
136
181
  - lib/chef/provisioning/azurerm.rb
137
182
  - lib/chef/provisioning/azurerm/azure_provider.rb
138
183
  - lib/chef/provisioning/azurerm/azure_resource.rb
@@ -140,9 +185,12 @@ files:
140
185
  - lib/chef/provisioning/azurerm/driver.rb
141
186
  - lib/chef/provisioning/azurerm/version.rb
142
187
  - lib/chef/provisioning/driver_init/azurerm.rb
188
+ - lib/chef/resource/azure_network_interface.rb
189
+ - lib/chef/resource/azure_public_ip_address.rb
143
190
  - lib/chef/resource/azure_resource_group.rb
144
191
  - lib/chef/resource/azure_resource_template.rb
145
192
  - lib/chef/resource/azure_storage_account.rb
193
+ - lib/chef/resource/azure_virtual_network.rb
146
194
  homepage: https://github.com/pendrica/chef-provisioning-azurerm
147
195
  licenses:
148
196
  - Apache-2.0
@@ -163,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
211
  version: '0'
164
212
  requirements: []
165
213
  rubyforge_project:
166
- rubygems_version: 2.4.4
214
+ rubygems_version: 2.4.8
167
215
  signing_key:
168
216
  specification_version: 4
169
217
  summary: Chef Provisioner for the Azure Resource Management (ARM) REST API.