Hello Amey Ambulgekar,
Welcome to microsoft Q&A, Thankyou for posting your query here.
you can create Azure VMs and other resources using Java Spring Boot microservices and the Azure SDK.
Include Azure SDK Dependencies
Configure Azure Credentials
Create a VM in Azure
Integrate with Spring Boot
<dependencies>
<!-- Azure Management Libraries -->
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-compute</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-network</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-resources</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.core.management.profile.AzureProfile;
import com.azure.core.management.Region;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.compute.models.KnownLinuxVirtualMachineImage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
public class AzureConfiguration {
public AzureResourceManager authenticateAzure() {
AzureProfile profile = new AzureProfile(AzureProfile.Environment.AZURE);
return AzureResourceManager.configure()
.authenticate(new DefaultAzureCredentialBuilder().build(), profile)
.withDefaultSubscription();
}
}
public class AzureVmService {
private final AzureResourceManager azureResourceManager;
public AzureVmService(AzureResourceManager azureResourceManager) {
this.azureResourceManager = azureResourceManager;
}
public void createVm() {
azureResourceManager.virtualMachines().define("myVM")
.withRegion(Region.US_EAST)
.withNewResourceGroup("myResourceGroup")
.withNewPrimaryNetwork("10.0.0.0/28")
.withPrimaryPrivateIPAddressDynamic()
.withoutPrimaryPublicIPAddress()
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_18_04_LTS)
.withRootUsername("adminuser")
.withSsh("ssh-rsa AAAAB3Nza...")
.withSize("Standard_D2as_v4")
.create();
}
}
public class AzureVmController {
private final AzureVmService azureVmService;
public AzureVmController(AzureVmService azureVmService) {
this.azureVmService = azureVmService;
}
@GetMapping("/create-vm")
public String createVm() {
azureVmService.createVm();
return "VM creation started!";
}
}
Hope this helps you
If an answer has been helpful, please consider accepting the answer to help increase visibility of this question for other members of the Microsoft Q&A community. If not, please let us know what is still needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!