Skip to content

Commit a9263e0

Browse files
Andrsmith/update automanage sdk docs (Azure#18778)
* Add examples to readme.md * Add examples.go * Add MIT license to examples.go * Remove example file, add error handling and consolidate parameters in readme. * Simplify Configuration Profile Create or Update example. * Add error handling in examples in README.md * remove unnecessary code from examples. Co-authored-by: andrew <[email protected]>
1 parent 3595686 commit a9263e0

File tree

1 file changed

+117
-5
lines changed
  • sdk/resourcemanager/automanage/armautomanage

1 file changed

+117
-5
lines changed

sdk/resourcemanager/automanage/armautomanage/README.md

Lines changed: 117 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@ The `armautomanage` module provides operations for working with Azure Automanage
1313
- an [Azure subscription](https://azure.microsoft.com/free/)
1414
- Go 1.18 or above
1515

16-
## Install the package
16+
## Install and import required packages
1717

1818
This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management.
1919

20-
Install the Azure Automanage module:
20+
Install the Azure Automanage and Azure Identity modules:
2121

2222
```sh
23-
go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/automanage/armautomanage
23+
go get "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/automanage/armautomanage"
24+
go get "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
25+
```
26+
27+
Import the Azure Automanage and Azure Identity modules:
28+
29+
```go
30+
import (
31+
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
32+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/automanage/armautomanage"
33+
)
2434
```
2535

2636
## Authorization
@@ -38,7 +48,9 @@ For more information on authentication, please see the documentation for `aziden
3848
Azure Automanage modules consist of one or more clients. A client groups a set of related APIs, providing access to its functionality within the specified subscription. Create one or more clients to access the APIs you require using your credential.
3949

4050
```go
41-
client, err := armautomanage.NewReportsClient(<subscription ID>, cred, nil)
51+
reportsClient, err := armautomanage.NewReportsClient("<subscription ID>", cred, nil)
52+
configProfilesClient, err := armautomanage.NewConfigurationProfilesClient("<subscription ID>", cred, nil)
53+
assignmentClient, err := armautomanage.NewConfigurationProfileAssignmentsClient("<subscription ID>", cred, nil)
4254
```
4355

4456
You can use `ClientOptions` in package `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` to set endpoint to connect with public and sovereign clouds as well as Azure Stack. For more information, please see the documentation for `azcore` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore).
@@ -49,9 +61,109 @@ options := arm.ClientOptions {
4961
Cloud: cloud.AzureChina,
5062
},
5163
}
52-
client, err := armautomanage.NewReportsClient(<subscription ID>, cred, &options)
64+
reportsClient, err := armautomanage.NewReportsClient("<subscription ID>", cred, &options)
65+
```
66+
67+
## Create or Update a Custom Automanage Configuration Profile
68+
69+
To update a profile, provide a value for all properties as if you were creating a configuration profile (ID, Name, Type, Location, Properties, Tags)
70+
71+
```go
72+
configuration := map[string]interface{}{
73+
"Antimalware/Enable": false,
74+
"AzureSecurityCenter/Enable": true,
75+
"Backup/Enable": false,
76+
"BootDiagnostics/Enable": true,
77+
"ChangeTrackingAndInventory/Enable": true,
78+
"GuestConfiguration/Enable": true,
79+
"LogAnalytics/Enable": true,
80+
"UpdateManagement/Enable": true,
81+
"VMInsights/Enable": true,
82+
}
83+
84+
properties := armautomanage.ConfigurationProfileProperties{
85+
Configuration: configuration,
86+
}
87+
88+
location := "eastus"
89+
environment := "dev"
90+
91+
// tags may be omitted
92+
tags := make(map[string]*string)
93+
tags["environment"] = &environment
94+
95+
profile := armautomanage.ConfigurationProfile{
96+
Location: &location,
97+
Properties: &properties,
98+
Tags: tags,
99+
}
100+
101+
newProfile, err := configProfilesClient.CreateOrUpdate(context.Background(), configurationProfileName, "resourceGroupName", profile, nil)
102+
```
103+
104+
105+
## Get an Automanage Configuration Profile
106+
107+
```go
108+
profile, err := configProfilesClient.Get(context.Background(), "configurationProfileName", "resourceGroupName", nil)
109+
data, err := json.MarshalIndent(profile, "", " ")
110+
111+
fmt.Println(string(data))
112+
```
113+
114+
115+
## Delete an Automanage Configuration Profile
116+
117+
```go
118+
_, err := configProfilesClient.Delete(context.Background(), "resourceGroupName", "configurationProfileName", nil)
119+
```
120+
121+
122+
## Get an Automanage Profile Assignment
123+
124+
```go
125+
assignment, err := assignmentClient.Get(context.Background(), "resourceGroupName", "default", "vmName", nil)
126+
data, err := json.MarshalIndent(assignment, "", " ")
127+
fmt.Println(string(data))
128+
```
129+
130+
131+
## Create an Assignment between a VM and an Automanage Best Practices Production Configuration Profile
132+
133+
```go
134+
configProfileId := "/providers/Microsoft.Automanage/bestPractices/AzureBestPracticesProduction"
135+
136+
properties := armautomanage.ConfigurationProfileAssignmentProperties{
137+
ConfigurationProfile: &configProfileId,
138+
}
139+
140+
assignment := armautomanage.ConfigurationProfileAssignment{
141+
Properties: &properties,
142+
}
143+
144+
// assignment name must be 'default'
145+
newAssignment, err = assignmentClient.CreateOrUpdate(context.Background(), "default", "resourceGroupName", "vmName", assignment, nil)
53146
```
54147

148+
149+
## Create an Assignment between a VM and a Custom Automanage Configuration Profile
150+
151+
```go
152+
configProfileId := "/subscriptions/<subscription ID>/resourceGroups/resourceGroupName/providers/Microsoft.Automanage/configurationProfiles/configurationProfileName"
153+
154+
properties := armautomanage.ConfigurationProfileAssignmentProperties{
155+
ConfigurationProfile: &configProfileId,
156+
}
157+
158+
assignment := armautomanage.ConfigurationProfileAssignment{
159+
Properties: &properties,
160+
}
161+
162+
// assignment name must be 'default'
163+
newAssignment, err = assignmentClient.CreateOrUpdate(context.Background(), "default", "resourceGroupName", "vmName", assignment, nil)
164+
```
165+
166+
55167
## Provide Feedback
56168

57169
If you encounter bugs or have suggestions, please

0 commit comments

Comments
 (0)