Skip to content

Commit 99e953b

Browse files
committed
Release azure-resourcemanager 2.0.0
1 parent f095eff commit 99e953b

File tree

5 files changed

+1707
-1470
lines changed

5 files changed

+1707
-1470
lines changed

Diff for: README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extensions:
2020

2121
To run this sample:
2222

23-
Set the environment variable `AZURE_AUTH_LOCATION` with the full path for an auth file. See [how to create an auth file](https://github.com/Azure/azure-libraries-for-java/blob/master/AUTH.md).
23+
See [DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/identity/azure-identity#defaultazurecredential) and prepare the authentication works best for you. For more details on authentication, please refer to [AUTH.md](https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/resourcemanager/docs/AUTH.md).
2424

2525
git clone https://github.com/Azure-Samples/compute-java-manage-vm-from-vm-with-msi-credentials.git
2626

@@ -30,9 +30,11 @@ Set the environment variable `AZURE_AUTH_LOCATION` with the full path for an aut
3030

3131
## More information ##
3232

33-
[http://azure.com/java](http://azure.com/java)
33+
For general documentation as well as quickstarts on how to use Azure Management Libraries for Java, please see [here](https://aka.ms/azsdk/java/mgmt).
3434

35-
If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212)
35+
Start to develop applications with Java on Azure [here](http://azure.com/java).
36+
37+
If you don't have a Microsoft Azure subscription you can get a FREE trial account [here](http://go.microsoft.com/fwlink/?LinkId=330212).
3638

3739
---
3840

Diff for: pom.xml

+15-19
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
<artifactId>exec-maven-plugin</artifactId>
1616
<version>1.4.0</version>
1717
<configuration>
18-
<mainClass>com.microsoft.azure.management.compute.samples.ManageVirtualMachineFromMSIEnabledVirtualMachine</mainClass>
18+
<mainClass>com.azure.resourcemanager.compute.samples.ManageVirtualMachineFromMSIEnabledVirtualMachine</mainClass>
19+
<cleanupDaemonThreads>false</cleanupDaemonThreads>
1920
</configuration>
2021
</plugin>
2122
<plugin>
2223
<artifactId>maven-compiler-plugin</artifactId>
23-
<version>3.0</version>
24+
<version>3.8.1</version>
2425
<configuration>
25-
<source>1.7</source>
26-
<target>1.7</target>
26+
<source>1.8</source>
27+
<target>1.8</target>
2728
</configuration>
2829
</plugin>
2930
<plugin>
@@ -40,7 +41,7 @@
4041
</descriptorRefs>
4142
<archive>
4243
<manifest>
43-
<mainClass>com.microsoft.azure.management.compute.samples.ManageVirtualMachineFromMSIEnabledVirtualMachine.java</mainClass>
44+
<mainClass>com.azure.resourcemanager.compute.samples.ManageVirtualMachineFromMSIEnabledVirtualMachine.java</mainClass>
4445
</manifest>
4546
</archive>
4647
</configuration>
@@ -51,24 +52,19 @@
5152
</build>
5253
<dependencies>
5354
<dependency>
54-
<groupId>com.microsoft.azure</groupId>
55-
<artifactId>azure</artifactId>
56-
<version>1.36.3</version>
55+
<groupId>com.azure.resourcemanager</groupId>
56+
<artifactId>azure-resourcemanager</artifactId>
57+
<version>2.0.0</version>
5758
</dependency>
5859
<dependency>
59-
<groupId>commons-net</groupId>
60-
<artifactId>commons-net</artifactId>
61-
<version>3.3</version>
62-
</dependency>
63-
<dependency>
64-
<groupId>commons-lang</groupId>
65-
<artifactId>commons-lang</artifactId>
66-
<version>2.6</version>
60+
<groupId>com.azure</groupId>
61+
<artifactId>azure-identity</artifactId>
62+
<version>1.1.3</version>
6763
</dependency>
6864
<dependency>
69-
<groupId>org.apache.commons</groupId>
70-
<artifactId>commons-lang3</artifactId>
71-
<version>3.7</version>
65+
<groupId>commons-net</groupId>
66+
<artifactId>commons-net</artifactId>
67+
<version>3.6</version>
7268
</dependency>
7369
</dependencies>
7470
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.resourcemanager.compute.samples;
5+
6+
import com.azure.core.http.policy.HttpLogDetailLevel;
7+
import com.azure.core.management.AzureEnvironment;
8+
import com.azure.core.management.profile.AzureProfile;
9+
import com.azure.identity.ManagedIdentityCredential;
10+
import com.azure.identity.ManagedIdentityCredentialBuilder;
11+
import com.azure.resourcemanager.AzureResourceManager;
12+
import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage;
13+
import com.azure.resourcemanager.compute.models.VirtualMachine;
14+
import com.azure.core.management.Region;
15+
import com.azure.resourcemanager.samples.Utils;
16+
17+
/**
18+
* Azure Compute sample for managing virtual machine from Managed Service Identity (MSI) enabled virtual machine -
19+
* - Create a virtual machine using MSI credentials from System assigned or User Assigned MSI enabled VM.
20+
*/
21+
public final class ManageVirtualMachineFromMSIEnabledVirtualMachine {
22+
/**
23+
* Main entry point.
24+
*
25+
* @param args the parameters
26+
*/
27+
public static void main(String[] args) {
28+
final Region region = Region.US_WEST_CENTRAL;
29+
30+
// This sample required to be run from a ManagedIdentityCredential (User Assigned or System Assigned) enabled virtual
31+
// machine with role based contributor access to the resource group specified as the second command line argument.
32+
//
33+
// see https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview
34+
//
35+
36+
final String usage = "Usage: mvn clean compile exec:java -Dexec.args=\"<subscription-id> <rg-name> [<client-id>]\"";
37+
if (args.length < 2) {
38+
throw new IllegalArgumentException(usage);
39+
}
40+
41+
final String subscriptionId = args[0];
42+
final String resourceGroupName = args[1];
43+
final String clientId = args.length > 2 ? args[2] : null;
44+
final String linuxVMName = "yourVirtualMachineName";
45+
final String userName = "tirekicker";
46+
final String password = Utils.password();
47+
48+
//=============================================================
49+
// ManagedIdentityCredential Authenticate
50+
51+
ManagedIdentityCredential credential = new ManagedIdentityCredentialBuilder()
52+
.clientId(clientId)
53+
.build();
54+
55+
AzureProfile profile = new AzureProfile(null, subscriptionId, AzureEnvironment.AZURE);
56+
57+
AzureResourceManager azure = AzureResourceManager.configure()
58+
.withLogLevel(HttpLogDetailLevel.BASIC)
59+
.authenticate(credential, profile)
60+
.withSubscription(subscriptionId);
61+
62+
// Print selected subscription
63+
System.out.println("Selected subscription: " + azure.subscriptionId());
64+
65+
//=============================================================
66+
// Create a Linux VM using MSI credentials
67+
68+
System.out.println("Creating a Linux VM using ManagedIdentityCredential.");
69+
70+
VirtualMachine virtualMachine = azure.virtualMachines()
71+
.define(linuxVMName)
72+
.withRegion(region)
73+
.withExistingResourceGroup(resourceGroupName)
74+
.withNewPrimaryNetwork("10.0.0.0/28")
75+
.withPrimaryPrivateIPAddressDynamic()
76+
.withoutPrimaryPublicIPAddress()
77+
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
78+
.withRootUsername(userName)
79+
.withRootPassword(password)
80+
.create();
81+
82+
System.out.println("Created virtual machine using ManagedIdentityCredential.");
83+
Utils.print(virtualMachine);
84+
85+
System.out.println("Deleting resource group: " + resourceGroupName);
86+
azure.resourceGroups().deleteByName(resourceGroupName);
87+
System.out.println("Deleted resource group: " + resourceGroupName);
88+
}
89+
90+
private ManageVirtualMachineFromMSIEnabledVirtualMachine() {
91+
}
92+
}

0 commit comments

Comments
 (0)