|
| 1 | +Description |
| 2 | +=========== |
| 3 | + |
| 4 | +This cookbook provides resources and providers to create an manage |
| 5 | +Windows Azure components. Currently supported resources are: |
| 6 | + |
| 7 | +* Storage Accounts ('azure_storage_account') |
| 8 | +* Blob Storage Containers ('azure_storage_container') |
| 9 | +* SQL Azure Servers ('azure_sql_db_server') |
| 10 | + |
| 11 | +**Note** This cookbook uses the `azure` RubyGem to interact with the |
| 12 | + Azure API. This gem requires `nokogiri` which requires compiling |
| 13 | + native extensions, which means build tools are required. |
| 14 | + |
| 15 | +Requirements |
| 16 | +============ |
| 17 | + |
| 18 | +Requires Chef 0.7.10 or higher for Lightweight Resource and Provider |
| 19 | +support. Chef 0.8+ is recommended. While this cookbook can be used in |
| 20 | +`chef-solo` mode, to gain the most flexibility, we recommend using |
| 21 | +`chef-client` with a Chef Server. |
| 22 | + |
| 23 | +A Windows Azure account is required. The Management Certificate and |
| 24 | +Subscriptoin ID are used to authenticate with Azure. |
| 25 | + |
| 26 | +Azure Credentials |
| 27 | +=============== |
| 28 | + |
| 29 | +In order to manage Azure components, authentication credentials need |
| 30 | +to be available to the node. There are a number of ways to handle |
| 31 | +this, such as node attributes or roles. We recommend storing these in |
| 32 | +a databag (Chef 0.8+), and loading them in the recipe where the |
| 33 | +resources are needed. |
| 34 | + |
| 35 | +DataBag recommendation: |
| 36 | + |
| 37 | + % knife data bag show azure main |
| 38 | + { |
| 39 | + "id": "main", |
| 40 | + "management_certificate": "YOUR PEM FILE CONTENTS", |
| 41 | + "subscription_id": "YOUR SUBSCRIPTION ID" |
| 42 | + } |
| 43 | + |
| 44 | +This can be loaded in a recipe with: |
| 45 | + |
| 46 | + azure = data_bag_item("azure", "main") |
| 47 | + |
| 48 | +And to access the values: |
| 49 | + |
| 50 | + azure['management_certificate'] |
| 51 | + azure['subscription_id'] |
| 52 | + |
| 53 | +We'll look at specific usage below. |
| 54 | + |
| 55 | +Recipes |
| 56 | +======= |
| 57 | + |
| 58 | +default.rb |
| 59 | +---------- |
| 60 | + |
| 61 | +The default recipe installs the `azure` RubyGem, which this cookbook |
| 62 | +requires in order to work with the Azure API. Make sure that the azure |
| 63 | +recipe is in the node or role `run_list` before any resources from |
| 64 | +this cookbook are used. |
| 65 | + |
| 66 | + "run_list": [ |
| 67 | + "recipe[azure]" |
| 68 | + ] |
| 69 | + |
| 70 | +The `gem_package` is created as a Ruby Object and thus installed |
| 71 | +during the Compile Phase of the Chef run. |
| 72 | + |
| 73 | +Resources and Providers |
| 74 | +======================= |
| 75 | + |
| 76 | +This cookbook provides three resources and corresponding providers. |
| 77 | + |
| 78 | +## storage_account.rb |
| 79 | + |
| 80 | + |
| 81 | +Manage Azure Storage Accounts with this resource. |
| 82 | + |
| 83 | +Actions: |
| 84 | + |
| 85 | +* `create` - create a new storage account |
| 86 | +* `delete` - delete the specified storage account |
| 87 | + |
| 88 | +Attribute Parameters: |
| 89 | + |
| 90 | +* `management_certificate` - PEM file contents of Azure management |
| 91 | + certificate, required. |
| 92 | +* `subscription_id` - ID of Azure subscription, required. |
| 93 | +* `management_endpoint` - Endpoint for Azure API, defaults to |
| 94 | + `management.core.windows.net`. |
| 95 | +* `location` - Azure location to create storate account. Either |
| 96 | + location or affinity group are required. |
| 97 | +* `affinity_group_name` - Affinity group to create account in. Either |
| 98 | + location or affinity group are required. |
| 99 | +* `geo_replication_enabled` - True or false, defaults to true. |
| 100 | + |
| 101 | +## storage_container.rb |
| 102 | + |
| 103 | +Manage Azure Blob Containers with this resource |
| 104 | + |
| 105 | +Actions: |
| 106 | + |
| 107 | +* `create` - create a new container |
| 108 | +* `delete` - delete the specified container |
| 109 | + |
| 110 | +Attribute Parameters: |
| 111 | + |
| 112 | +* `storage_account` - Account to create container in, required. |
| 113 | +* `access_key` - Access key for storage account, required. |
| 114 | + |
| 115 | +## sql_db_server.rb |
| 116 | + |
| 117 | +Actions: |
| 118 | + |
| 119 | +* `create` - create a new server. Use the Azure location as the `name` |
| 120 | + of the storage account. The server name is autogenerated. |
| 121 | + |
| 122 | +Attribute Parameters: |
| 123 | + |
| 124 | +* `management_certificate` - PEM file contents of Azure management |
| 125 | + certificate, required. |
| 126 | +* `subscription_id` - ID of Azure subscription, required. |
| 127 | +* `management_endpoint` - Endpoint for Azure API, defaults to |
| 128 | + `management.database.windows.net`. |
| 129 | +* `login` - Desired admin login for db server, required. |
| 130 | +* `password` - Desired admin password for db server, required. |
| 131 | +* `server_name` - This attribute is set by the provider, and can be |
| 132 | + used by consuming recipies. |
| 133 | + |
| 134 | +Usage |
| 135 | +===== |
| 136 | + |
| 137 | +The following examples assume that the recommended data bag item has |
| 138 | +been created and that the following has been included at the top of |
| 139 | +the recipe where they are used. |
| 140 | + |
| 141 | + include_recipe "azure" |
| 142 | + azure = data_bag_item("azure", "main") |
| 143 | + |
| 144 | +## azure_storage_accouint |
| 145 | + |
| 146 | +This will create an account named `new-account` in the `West US` |
| 147 | +location. |
| 148 | + |
| 149 | + azure_storage_account 'new-account' do |
| 150 | + management_certificate azure['management_certificate'] |
| 151 | + subscription_id azure['subscription_id'] |
| 152 | + location 'West US' |
| 153 | + action :create |
| 154 | + end |
| 155 | + |
| 156 | +This will create an account named `new-account` in the existing |
| 157 | +`my-ag` affinity group. |
| 158 | + |
| 159 | + azure_storage_account 'new-account' do |
| 160 | + management_certificate azure['management_certificate'] |
| 161 | + subscription_id azure['subscription_id'] |
| 162 | + affinity_group_name 'my-ag' |
| 163 | + action :create |
| 164 | + end |
| 165 | + |
| 166 | +## azure_storage_container |
| 167 | + |
| 168 | +This will create a container named `my-node` within the storage |
| 169 | +account `my-account`. |
| 170 | + |
| 171 | + azure_storage_container 'my-node' do |
| 172 | + storage_account 'my-account' |
| 173 | + access_key azure['access_key'] |
| 174 | + action :create |
| 175 | + end |
| 176 | + |
| 177 | +## azure_sql_db_server |
| 178 | + |
| 179 | +This will create a db server in the location `West US` with the login |
| 180 | +`admin` and password `password`. |
| 181 | + |
| 182 | + azure_sql_db_server 'West US' do |
| 183 | + management_certificate azure['management_certificate'] |
| 184 | + subscription_id azure['subscription_id'] |
| 185 | + login 'admin' |
| 186 | + password 'password' |
| 187 | + action :create |
| 188 | + end |
| 189 | + |
| 190 | +Here is an example of how you might retrieve the generated server |
| 191 | +name. |
| 192 | + |
| 193 | + file '/etc/db_server_info' do |
| 194 | + content lazy { |
| 195 | + db2 = resources("azure_sql_db_server[West US]") |
| 196 | + "Url: https://#{db2.server_name}.database.windows.net" |
| 197 | + } |
| 198 | + mode 0600 |
| 199 | + action :create |
| 200 | + end |
| 201 | + |
| 202 | + |
| 203 | +License and Author |
| 204 | +================== |
| 205 | + |
| 206 | +* Author:: Jeff Mendoza ( <[email protected]>) |
| 207 | + |
| 208 | +Copyright (c) Microsoft Open Technologies, Inc. |
| 209 | + |
| 210 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 211 | +you may not use this file except in compliance with the License. |
| 212 | +You may obtain a copy of the License at |
| 213 | + |
| 214 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 215 | + |
| 216 | +Unless required by applicable law or agreed to in writing, software |
| 217 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 218 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 219 | +See the License for the specific language governing permissions and |
| 220 | +limitations under the License. |
0 commit comments