Share via


クイックスタート: GO を使用して仮想マシンに対して Azure Automanage を有効にする

Azure Automanage を使用すると、ユーザーは、仮想マシンに Azure のベスト プラクティスをシームレスに適用できます。 このクイックスタート ガイドは、azure-sdk-for-go リポジトリを使用して、既存の仮想マシンにベスト プラクティス構成プロファイルを適用するのに役立ちます。

前提条件

Note

無料試用版アカウントでは、このチュートリアルで使用されている仮想マシンを利用できません。 従量課金制サブスクリプションにアップグレードしてください。

重要

Automanage を有効にするには、VM を含むリソース グループの共同作成者ロールが必要です。 サブスクリプションで初めて Automanage を有効にする場合は、次のアクセス許可が必要です: サブスクリプションでの所有者ロール、または共同作成者ロールとユーザー アクセス管理者ロールの併用。

必要なパッケージをインストールする

このデモでは、Azure Identity パッケージと Azure Automanage パッケージの両方が必要です。

go get "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/automanage/armautomanage"
go get "github.com/Azure/azure-sdk-for-go/sdk/azidentity"

パッケージをインポートする

Azure Identity パッケージと Azure Automanage パッケージをスクリプトにインポートします。

import (
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/automanage/armautomanage"
)

Azure に対して認証を行い、Automanage クライアントを作成する

Azure Identity パッケージを使用して Azure に対して認証を行い、その後、Automanage クライアントを作成します。

credential, err := azidentity.NewDefaultAzureCredential(nil)
configProfilesClient, err := armautomanage.NewConfigurationProfilesClient("<subscription ID>", credential, nil)

既存の仮想マシンに対してベスト プラクティス構成プロファイルを有効にする

configProfileId := "/providers/Microsoft.Automanage/bestPractices/AzureBestPracticesProduction"

properties := armautomanage.ConfigurationProfileAssignmentProperties{
    ConfigurationProfile: &configProfileId,
}

assignment := armautomanage.ConfigurationProfileAssignment{
    Properties: &properties,
}

// assignment name must be 'default'
newAssignment, err = assignmentClient.CreateOrUpdate(context.Background(), "default", "resourceGroupName", "vmName", assignment, nil)

次のステップ

azure-sdk-for-go repo にアクセスして、GO Automanage クライアントで多くの操作を実行する方法について学習してください。