Now, let’s start for the functions of Azure Lighthouse in Java programing.
Deploy Azure Lighthouse templates
From last blog you may know, we use ARM templates to onboard Azure lighthouse, there are types of several templates depends on the scope. Here we are talking about “Azure Lighthouse-Subscription deployment”, “Azure Lighthouse-Resource Group Deployment” and “Azure Lighthouse-Multiple Resource Group Deployment” referred from Azure-Lighthouse-samples templates.
Deploy to resource group:
If you want to deploy resources to a resource group or using “Azure Lighthouse-Resource Group Deployment” to onboard Azure Lighthouse in resource group. we have a sample code from DeployUsingARMTemplate.java (github.com). Here I extract the key code in below.
And if you want to deploy on Azure Lighthouse to Subscription or Multiple resource groups. You can use this code in below. But deploying other resources require a resource group, this code may not be suitable for deployment of other resources.
//A deployment name which shows in deployments.
final String deploymentName = "sample-resourcegroup5";
//Get the template in local and convert to JsonNode
new DeploymentInner().withLocation("eastus").withProperties(new DeploymentProperties().withTemplate(jsonNode)
Explanation to above code:
Deployment name is a name when you deploy to Azure. You can follow the default deployment name in portal with resource type and datetime. Or a unique name for test. Please check the reference from here Deploy resources with Azure portal
My templates are in my Java project, so they need to covert Json file to JsonNode before adding in azureResourceManager. deployment.
azureResourceManager is from previous step that authenticated with clientSecretCredential.