-
Notifications
You must be signed in to change notification settings - Fork 11
/
CloudService_Create_WithSingleRole.go
68 lines (65 loc) · 2.44 KB
/
CloudService_Create_WithSingleRole.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package armcompute_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/tree/main/specification/compute/resource-manager/Microsoft.Compute/CloudserviceRP/stable/2022-04-04/examples/CloudService_Create_WithSingleRole.json
func ExampleCloudServicesClient_BeginCreateOrUpdate_createNewCloudServiceWithSingleRole() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
client, err := armcompute.NewCloudServicesClient("{subscription-id}", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := client.BeginCreateOrUpdate(ctx, "ConstosoRG", "{cs-name}", armcompute.CloudService{
Location: to.Ptr("westus"),
Properties: &armcompute.CloudServiceProperties{
Configuration: to.Ptr("{ServiceConfiguration}"),
NetworkProfile: &armcompute.CloudServiceNetworkProfile{
LoadBalancerConfigurations: []*armcompute.LoadBalancerConfiguration{
{
Name: to.Ptr("myLoadBalancer"),
Properties: &armcompute.LoadBalancerConfigurationProperties{
FrontendIPConfigurations: []*armcompute.LoadBalancerFrontendIPConfiguration{
{
Name: to.Ptr("myfe"),
Properties: &armcompute.LoadBalancerFrontendIPConfigurationProperties{
PublicIPAddress: &armcompute.SubResource{
ID: to.Ptr("/subscriptions/{subscription-id}/resourceGroups/ConstosoRG/providers/Microsoft.Network/publicIPAddresses/myPublicIP"),
},
},
}},
},
}},
},
PackageURL: to.Ptr("{PackageUrl}"),
RoleProfile: &armcompute.CloudServiceRoleProfile{
Roles: []*armcompute.CloudServiceRoleProfileProperties{
{
Name: to.Ptr("ContosoFrontend"),
SKU: &armcompute.CloudServiceRoleSKU{
Name: to.Ptr("Standard_D1_v2"),
Capacity: to.Ptr[int64](1),
Tier: to.Ptr("Standard"),
},
}},
},
UpgradeMode: to.Ptr(armcompute.CloudServiceUpgradeModeAuto),
},
}, 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
}