Last active
September 19, 2022 09:37
-
-
Save tadelesh/9f0cc41bce8d6d0ef6acea6808337a92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/tree/main/specification/compute/resource-manager/Microsoft.Compute/stable/2022-03-01/ComputeRP/examples/virtualMachineExamples/VirtualMachine_Create_LinuxVmWithPatchSettingAssessmentModeOfImageDefault.json | |
func ExampleVirtualMachinesClient_BeginCreateOrUpdate() { | |
cred, err := azidentity.NewDefaultAzureCredential(nil) | |
if err != nil { | |
log.Fatalf("failed to obtain a credential: %v", err) | |
} | |
ctx := context.Background() | |
client, err := armcompute.NewVirtualMachinesClient("{subscription-id}", cred, nil) | |
if err != nil { | |
log.Fatalf("failed to create client: %v", err) | |
} | |
poller, err := client.BeginCreateOrUpdate(ctx, | |
"myResourceGroup", | |
"myVM", | |
armcompute.VirtualMachine{ | |
Location: to.Ptr("westus"), | |
Properties: &armcompute.VirtualMachineProperties{ | |
HardwareProfile: &armcompute.HardwareProfile{ | |
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes("Standard_D2s_v3")), | |
}, | |
NetworkProfile: &armcompute.NetworkProfile{ | |
NetworkInterfaces: []*armcompute.NetworkInterfaceReference{ | |
{ | |
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}"), | |
Properties: &armcompute.NetworkInterfaceReferenceProperties{ | |
Primary: to.Ptr(true), | |
}, | |
}}, | |
}, | |
OSProfile: &armcompute.OSProfile{ | |
AdminPassword: to.Ptr("{your-password}"), | |
AdminUsername: to.Ptr("{your-username}"), | |
ComputerName: to.Ptr("myVM"), | |
LinuxConfiguration: &armcompute.LinuxConfiguration{ | |
PatchSettings: &armcompute.LinuxPatchSettings{ | |
AssessmentMode: to.Ptr(armcompute.LinuxPatchAssessmentModeImageDefault), | |
}, | |
ProvisionVMAgent: to.Ptr(true), | |
}, | |
}, | |
StorageProfile: &armcompute.StorageProfile{ | |
ImageReference: &armcompute.ImageReference{ | |
Offer: to.Ptr("UbuntuServer"), | |
Publisher: to.Ptr("Canonical"), | |
SKU: to.Ptr("16.04-LTS"), | |
Version: to.Ptr("latest"), | |
}, | |
OSDisk: &armcompute.OSDisk{ | |
Name: to.Ptr("myVMosdisk"), | |
Caching: to.Ptr(armcompute.CachingTypesReadWrite), | |
CreateOption: to.Ptr(armcompute.DiskCreateOptionTypesFromImage), | |
ManagedDisk: &armcompute.ManagedDiskParameters{ | |
StorageAccountType: to.Ptr(armcompute.StorageAccountTypesPremiumLRS), | |
}, | |
}, | |
}, | |
}, | |
}, | |
nil) | |
if err != nil { | |
log.Fatalf("failed to finish the request: %v", err) | |
} | |
res, err := poller.PollUntilDone(ctx, nil) | |
if err != nil { | |
log.Fatalf("failed to pull the result: %v", err) | |
} | |
// TODO: use response item | |
_ = res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment