Skip to content

Commit

Permalink
bugfix: zone feature
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Barnett <[email protected]>
  • Loading branch information
jasonwbarnett committed Mar 1, 2022
1 parent db329cd commit 75eab29
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 45 deletions.
4 changes: 1 addition & 3 deletions lib/kitchen/driver/azurerm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ class Azurerm < Kitchen::Driver::Base
false
end

default_config(:zone) do |_config|
"1"
end
default_config :zone, nil

def create(state)
state = validate_state(state)
Expand Down
91 changes: 64 additions & 27 deletions spec/unit/kitchen/driver/azurerm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
expect(default_config[:public_ip_sku]).to eq("Basic")
end

it "Should use 1 availability zone" do
expect(default_config[:zone]).to eq("1")
it "should set zone to nil" do
expect(default_config[:zone]).to eq(nil)
end

it "should set store_deployment_credentials_in_state to true" do
Expand Down Expand Up @@ -257,43 +257,78 @@
let(:parsed_json) { JSON.parse(subject) }
let(:vm_resource) { parsed_json["resources"].find { |x| x["type"] == "Microsoft.Compute/virtualMachines" } }

context "when plan config is provided" do
let(:plan_name) { "plan-abc" }
let(:plan_product) { "my-product" }
let(:plan_publisher) { "captain-america" }
let(:plan_promotion_code) { "50-percent-off" }

let(:plan) do
{
name: plan_name,
product: plan_product,
publisher: plan_publisher,
promotion_code: plan_promotion_code,
}
end

context "when vnet_id is not provided" do
let(:config) do
{
subscription_id: subscription_id,
location: location,
machine_size: machine_size,
vm_tags: vm_tags,
plan: plan,
image_urn: image_urn,
vm_name: vm_name,
}
end

it "includes plan information in deployment template" do
expect(vm_resource).to have_key("plan")
expect(vm_resource["plan"]["name"]).to eq(plan_name)
expect(vm_resource["plan"]["product"]).to eq(plan_product)
expect(vm_resource["plan"]["publisher"]).to eq(plan_publisher)
expect(vm_resource["plan"]["promotionCode"]).to eq(plan_promotion_code)
it 'uses public template' do
expect(driver).to receive(:virtual_machine_deployment_template_file).with("public.erb", any_args)
subject
end

context "when plan config is provided" do
let(:plan_name) { "plan-abc" }
let(:plan_product) { "my-product" }
let(:plan_publisher) { "captain-america" }
let(:plan_promotion_code) { "50-percent-off" }

let(:plan) do
{
name: plan_name,
product: plan_product,
publisher: plan_publisher,
promotion_code: plan_promotion_code,
}
end

let(:config) do
{
subscription_id: subscription_id,
location: location,
machine_size: machine_size,
vm_tags: vm_tags,
plan: plan,
image_urn: image_urn,
vm_name: vm_name,
}
end

it "includes plan information in deployment template" do
expect(vm_resource).to have_key("plan")
expect(vm_resource["plan"]["name"]).to eq(plan_name)
expect(vm_resource["plan"]["product"]).to eq(plan_product)
expect(vm_resource["plan"]["publisher"]).to eq(plan_publisher)
expect(vm_resource["plan"]["promotionCode"]).to eq(plan_promotion_code)
end
end

context "when plan config is not provided" do
let(:config) do
{
subscription_id: subscription_id,
location: location,
machine_size: machine_size,
vm_tags: vm_tags,
image_urn: image_urn,
vm_name: vm_name,
}
end

it "does not include plan information in deployment template" do
expect(vm_resource).not_to have_key("plan")
end
end
end

context "when plan config is not provided" do
context "when vnet_id is provided" do
let(:config) do
{
subscription_id: subscription_id,
Expand All @@ -302,11 +337,13 @@
vm_tags: vm_tags,
image_urn: image_urn,
vm_name: vm_name,
vnet_id: "vnet-1234",
}
end

it "does not include plan information in deployment template" do
expect(vm_resource).not_to have_key("plan")
it 'uses internal template' do
expect(driver).to receive(:virtual_machine_deployment_template_file).with("internal.erb", any_args)
subject
end
end
end
Expand Down
24 changes: 9 additions & 15 deletions templates/internal.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@
"description": "The location where the resources will be created."
}
},
"zone": {
"type": "string",
"defaultValue": "1",
"allowedValues": [
"1",
"2",
"3"
],
"metadata": {
"description": "Zone number for the virtual machine"
}
},
"vmSize": {
"type": "string",
"metadata": {
Expand Down Expand Up @@ -220,7 +208,9 @@
},
"variables": {
"location": "[parameters('location')]",
"zone": "[parameters('zone')]",
<% unless zone.nil? %>
"zone": "<%= zone -%>",
<% end %>
"OSDiskName": "osdisk",
"nicName": "[parameters('nicName')]",
"addressPrefix": "10.0.0.0/16",
Expand Down Expand Up @@ -272,9 +262,11 @@
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[variables('location')]",
<% unless zone.nil? %>
"zones": [
"[variables('zone')]"
"<%= zone -%>"
],
<% end %>
"sku": {
"name": "[parameters('publicIPSKU')]"
},
Expand Down Expand Up @@ -326,9 +318,11 @@
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[variables('location')]",
<% unless zone.nil? %>
"zones": [
"[variables('zone')]"
"<%= zone -%>"
],
<% end %>
"dependsOn": [
<%- unless use_managed_disks -%>
<%- if existing_storage_account_blob_url.empty? -%>
Expand Down

0 comments on commit 75eab29

Please sign in to comment.