@@ -29,10 +29,6 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
29
29
hddSize := int32 (d .Get ("instance_hdd_size" ).(int ))
30
30
spot := d .Get ("spot" ).(bool )
31
31
spotPrice := d .Get ("spot_price" ).(float64 )
32
- vmPriority := compute .Regular
33
- if spot {
34
- vmPriority = compute .Spot
35
- }
36
32
37
33
image := d .Get ("image" ).(string )
38
34
if image == "" {
@@ -187,66 +183,70 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
187
183
}
188
184
189
185
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 ),
205
198
},
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 ,
221
206
},
222
207
},
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 ) ,
234
219
},
235
220
},
236
221
},
237
222
},
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 ) ,
245
230
},
246
231
},
247
232
},
248
233
},
249
234
},
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 ,
250
250
)
251
251
if err != nil {
252
252
return err
0 commit comments