Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow null priority to allow updating non-spot VM instances #969

Merged
merged 5 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Release Notes
=============
## 1.7.8
* VMs: Default to no priority

## 1.7.7
* NAT Gateways: Initial support for NAT Gateways.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/api-overview/resources/virtual-machine.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ In addition, every VM you create will add a SecureString parameter to the ARM te
|diagnostics_support_managed|Turns on diagnostics support using an Azure-managed storage account.|
|diagnostics_support_external|Turns on diagnostics support using an existing storage account.|
|vm_size|Sets the size of the VM.|
|priority|Sets the VM Priority. Only one `spot_instance` or `priority` setting is allowed per VM.|
|priority|Sets the VM Priority. Only one `spot_instance` or `priority` setting is allowed per VM. No priority is set by default. |
|spot_instance|Makes the VM a spot instance. Shorthand for `priority (Spot (<EvictionPolicy>, <maxPrice>)`. Only one `spot_instance` or `priority` setting is allowed per VM.|
|username|Sets the admin username of the VM (note: the password is supplied as a securestring parameter to the generated ARM template).|
|password_parameter|Sets the name of the parameter which contains the admin password for this VM. defaults to "password-for-<VM-name>"|
Expand Down
14 changes: 9 additions & 5 deletions src/Farmer/Arm/Compute.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type VirtualMachine =
DiagnosticsEnabled: bool option
StorageAccount: ResourceName option
Size: VMSize
Priority: Priority
Priority: Priority option
Credentials: {| Username: string
Password: SecureParameter |}
CustomData: string option
Expand Down Expand Up @@ -137,7 +137,10 @@ type VirtualMachine =

let properties =
{|
priority = this.Priority.ArmValue
priority =
match this.Priority with
| Some priority -> priority.ArmValue
| _ -> Unchecked.defaultof<_>
hardwareProfile = {| vmSize = this.Size.ArmValue |}
osProfile =
{|
Expand Down Expand Up @@ -260,9 +263,10 @@ type VirtualMachine =
this.Identity.ToArmJson
properties =
match this.Priority with
| Low
| Regular -> box properties
| Spot (evictionPolicy, maxPrice) ->
| None
| Some Low
| Some Regular -> box properties
| Some (Spot (evictionPolicy, maxPrice)) ->
{| properties with
evictionPolicy = evictionPolicy.ArmValue
billingProfile = {| maxPrice = maxPrice |}
Expand Down
2 changes: 1 addition & 1 deletion src/Farmer/Builders/Builders.Vm.fs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type VmConfig =
StorageAccount = this.DiagnosticsStorageAccount |> Option.map (fun r -> r.resourceId(this).Name)
NetworkInterfaceName = this.NicName.Name
Size = this.Size
Priority = this.Priority |> Option.defaultValue Regular
Priority = this.Priority
Credentials =
match this.Username with
| Some username ->
Expand Down
18 changes: 18 additions & 0 deletions src/Tests/VirtualMachine.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ let tests =
(resource.DiagnosticsProfile.BootDiagnostics.Enabled.GetValueOrDefault false)
"Boot Diagnostics should be enabled"
}

test "By default, VM does not include Priority" {
let template =
let myVm =
vm {
name "myvm"
username "me"
}

arm { add_resource myVm }

let jobj = Newtonsoft.Json.Linq.JObject.Parse(template.Template |> Writer.toJson)

let vmProperties =
jobj.SelectToken("resources[?(@.name=='myvm')].properties") :?> Newtonsoft.Json.Linq.JObject

Expect.isNull (vmProperties.Property "priority") "Priority should not be set by default"
}
test "Can create a basic virtual machine with managed boot diagnostics" {
let resource =
let myVm =
Expand Down
1 change: 0 additions & 1 deletion src/Tests/test-data/lots-of-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,6 @@
"adminUsername": "farmer-admin",
"computerName": "farmervm"
},
"priority": "Regular",
"storageProfile": {
"dataDisks": [
{
Expand Down
1 change: 0 additions & 1 deletion src/Tests/test-data/vm.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"adminUsername": "isaac",
"computerName": "isaacsVM"
},
"priority": "Regular",
"storageProfile": {
"dataDisks": [
{
Expand Down