@@ -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