Share via


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

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

前提条件

Note

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

重要

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

必要な依存関係を追加する

Azure Identity 依存関係と Azure Automanage 依存関係を pom.xml に追加します。

<!-- https://mvnrepository.com/artifact/com.azure/azure-identity -->
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-identity</artifactId>
    <version>1.6.0-beta.1</version>
    <scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.azure.resourcemanager/azure-resourcemanager-automanage -->
<dependency>
    <groupId>com.azure.resourcemanager</groupId>
    <artifactId>azure-resourcemanager-automanage</artifactId>
    <version>1.0.0-beta.1</version>
</dependency>

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

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

AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
TokenCredential credential = new DefaultAzureCredentialBuilder()
    .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
    .build();

AutomanageManager client = AutomanageManager
    .authenticate(credential, profile);

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

String configProfile = "/providers/Microsoft.Automanage/bestPractices/AzureBestPracticesProduction";

client
    .configurationProfileAssignments()
    .define("default") // name must be default
    .withExistingVirtualMachine("resourceGroupName", "vmName")
    .withProperties(
        new ConfigurationProfileAssignmentProperties()
            .withConfigurationProfile(configProfile))
    .create();

次のステップ

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