Skip to content

Commit b02292b

Browse files
committed
fix azure non spot
1 parent b6f7825 commit b02292b

File tree

2 files changed

+94
-52
lines changed

2 files changed

+94
-52
lines changed

examples/main.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
terraform {
2+
required_providers {
3+
iterative = {
4+
versions = ["0.6"]
5+
source = "github.com/iterative/iterative"
6+
}
7+
8+
# iterative = {
9+
# source = "iterative/iterative"
10+
# version = "0.5.7"
11+
# }
12+
}
13+
}
14+
15+
provider "iterative" {}
16+
17+
18+
resource "iterative_cml_runner" "runner-gl-aws" {
19+
name = "gitlabrunner2"
20+
token = "arszDpb3xtNdKaXmQ6vN"
21+
repo = "https://gitlab.com/DavidGOrtega/3_tensorboard"
22+
driver = "gitlab"
23+
labels = "tf"
24+
25+
cloud = "azure"
26+
region = "us-west"
27+
instance_type = "m"
28+
spot = true
29+
#spot_price = 0.09
30+
}
31+
32+
# resource "iterative_cml_runner" "runner-gh-aws" {
33+
# name = "githubrunner2"
34+
# token = "a0b56d03294f0908f4ee7290be2ea53051d227d3"
35+
# repo = "https://github.com/DavidGOrtega/3_tensorboard"
36+
# driver = "github"
37+
# labels = "tf"
38+
39+
# cloud = "aws"
40+
# region = "us-east-2"
41+
# instance_type = "t2.micro"
42+
# }

iterative/azure/provider.go

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
2929
hddSize := int32(d.Get("instance_hdd_size").(int))
3030
spot := d.Get("spot").(bool)
3131
spotPrice := d.Get("spot_price").(float64)
32-
vmPriority := compute.Regular
33-
if spot {
34-
vmPriority = compute.Spot
35-
}
3632

3733
image := d.Get("image").(string)
3834
if image == "" {
@@ -187,66 +183,70 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
187183
}
188184

189185
vmClient, _ := getVMClient(subscriptionID)
190-
futureVM, err := vmClient.CreateOrUpdate(
191-
ctx,
192-
gpName,
193-
vmName,
194-
compute.VirtualMachine{
195-
196-
Location: to.StringPtr(region),
197-
VirtualMachineProperties: &compute.VirtualMachineProperties{
198-
EvictionPolicy: compute.Delete,
199-
Priority: vmPriority,
200-
BillingProfile: &compute.BillingProfile{
201-
MaxPrice: to.Float64Ptr(spotPrice),
202-
},
203-
HardwareProfile: &compute.HardwareProfile{
204-
VMSize: compute.VirtualMachineSizeTypes(instanceType),
186+
vmSettings := compute.VirtualMachine{
187+
Location: to.StringPtr(region),
188+
VirtualMachineProperties: &compute.VirtualMachineProperties{
189+
HardwareProfile: &compute.HardwareProfile{
190+
VMSize: compute.VirtualMachineSizeTypes(instanceType),
191+
},
192+
StorageProfile: &compute.StorageProfile{
193+
ImageReference: &compute.ImageReference{
194+
Publisher: to.StringPtr(publisher),
195+
Offer: to.StringPtr(offer),
196+
Sku: to.StringPtr(sku),
197+
Version: to.StringPtr(version),
205198
},
206-
StorageProfile: &compute.StorageProfile{
207-
ImageReference: &compute.ImageReference{
208-
Publisher: to.StringPtr(publisher),
209-
Offer: to.StringPtr(offer),
210-
Sku: to.StringPtr(sku),
211-
Version: to.StringPtr(version),
212-
},
213-
OsDisk: &compute.OSDisk{
214-
Name: to.StringPtr(fmt.Sprintf(vmName + "-hdd")),
215-
Caching: compute.CachingTypesReadWrite,
216-
CreateOption: compute.DiskCreateOptionTypesFromImage,
217-
DiskSizeGB: to.Int32Ptr(hddSize),
218-
ManagedDisk: &compute.ManagedDiskParameters{
219-
StorageAccountType: compute.StorageAccountTypesStandardLRS,
220-
},
199+
OsDisk: &compute.OSDisk{
200+
Name: to.StringPtr(fmt.Sprintf(vmName + "-hdd")),
201+
Caching: compute.CachingTypesReadWrite,
202+
CreateOption: compute.DiskCreateOptionTypesFromImage,
203+
DiskSizeGB: to.Int32Ptr(hddSize),
204+
ManagedDisk: &compute.ManagedDiskParameters{
205+
StorageAccountType: compute.StorageAccountTypesStandardLRS,
221206
},
222207
},
223-
OsProfile: &compute.OSProfile{
224-
CustomData: to.StringPtr(customData),
225-
ComputerName: to.StringPtr("iterative"),
226-
AdminUsername: to.StringPtr(username),
227-
LinuxConfiguration: &compute.LinuxConfiguration{
228-
SSH: &compute.SSHConfiguration{
229-
PublicKeys: &[]compute.SSHPublicKey{
230-
{
231-
Path: to.StringPtr(fmt.Sprintf("/home/%s/.ssh/authorized_keys", username)),
232-
KeyData: to.StringPtr(keyPublic),
233-
},
208+
},
209+
OsProfile: &compute.OSProfile{
210+
CustomData: to.StringPtr(customData),
211+
ComputerName: to.StringPtr("iterative"),
212+
AdminUsername: to.StringPtr(username),
213+
LinuxConfiguration: &compute.LinuxConfiguration{
214+
SSH: &compute.SSHConfiguration{
215+
PublicKeys: &[]compute.SSHPublicKey{
216+
{
217+
Path: to.StringPtr(fmt.Sprintf("/home/%s/.ssh/authorized_keys", username)),
218+
KeyData: to.StringPtr(keyPublic),
234219
},
235220
},
236221
},
237222
},
238-
NetworkProfile: &compute.NetworkProfile{
239-
NetworkInterfaces: &[]compute.NetworkInterfaceReference{
240-
{
241-
ID: nic.ID,
242-
NetworkInterfaceReferenceProperties: &compute.NetworkInterfaceReferenceProperties{
243-
Primary: to.BoolPtr(true),
244-
},
223+
},
224+
NetworkProfile: &compute.NetworkProfile{
225+
NetworkInterfaces: &[]compute.NetworkInterfaceReference{
226+
{
227+
ID: nic.ID,
228+
NetworkInterfaceReferenceProperties: &compute.NetworkInterfaceReferenceProperties{
229+
Primary: to.BoolPtr(true),
245230
},
246231
},
247232
},
248233
},
249234
},
235+
}
236+
237+
if spot {
238+
vmSettings.EvictionPolicy = compute.Delete
239+
vmSettings.Priority = compute.Spot
240+
vmSettings.BillingProfile = &compute.BillingProfile{
241+
MaxPrice: to.Float64Ptr(spotPrice),
242+
}
243+
}
244+
245+
futureVM, err := vmClient.CreateOrUpdate(
246+
ctx,
247+
gpName,
248+
vmName,
249+
vmSettings,
250250
)
251251
if err != nil {
252252
return err

0 commit comments

Comments
 (0)