Last time we talked about how to onboard Azure lighthouse from Azure portal in this Blog Azure Lighthouse - Step by step guidance - Onboard customer to Lighthouse using sample template, now discuss about how to use Azure Java SDK to deploy Lighthouse templates.
You may follow my previous blog mentioned in above and please read this document about what is Azure lighthouse. Here we will not repeat the definitions and how to gather values.
Please also read this document Azure authentication with Java and Azure Identity and Authentication in Azure Management Libraries for Java(github.com), they explain the methods to login Azure through Java program. We will not explain about the authentication in details.
I used ClientSecretCredential in below simple code:
final AzureProfile profile = new AzureProfile(tenantId, subscriptionId, AzureEnvironment.AZURE);
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder() .clientId(clientId).clientSecret(clientSecret) .tenantId(tenantId).build();
// Azure SDK client builders accept the credential as a parameter AzureResourceManager azureResourceManager = AzureResourceManager.configure() .withLogLevel(HttpLogDetailLevel.BASIC).authenticate(clientSecretCredential, profile) .withSubscription(subId); |
Now, let’s start for the functions of Azure Lighthouse in Java programing.
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 resource in resource group “rgName” azureResourceManager.deployments().define(deploymentName) .withExistingResourceGroup(rgName) .withTemplate(templateJson) .withParameters(prameterJson) .withMode(DeploymentMode.INCREMENTAL) .create(); |
//A deployment name which shows in deployments. final String deploymentName = "sample-resourcegroup5";
//Get the template in local and convert to JsonNode JsonNode jsonNode = DeployUsingARMTemplate.getTemplateJson(azureResourceManager, "/multipleRgDelegatedResourceManagement.json");
//Covert parameter template to JsonNode. JsonNode jsonNodeParameter = DeployUsingARMTemplate.getTemplateJson(azureResourceManager, "/multipleRgDelegatedResourceManagement.parameters2.json");
//Deploy template to Subscription, it needs to use Incremental mode to deploy resources. azureResourceManager.deployments().manager().serviceClient().getDeployments() .createOrUpdateAtScope("/subscriptions/"+subId, deploymentName, new DeploymentInner().withLocation("eastus").withProperties(new DeploymentProperties().withTemplate(jsonNode) .withParameters(jsonNodeParameter) .withMode(DeploymentMode.INCREMENTAL))); |
For example:
azureResourceManager.deployments(rgName) .define(deploymentName) .withNewResourceGroup() .withTemplateLink(templateUri, templateContentVersion) .withParameters(params).withMode(DeploymentMode.INCREMENTAL).create() |
In short, Azure Lighthouse is onboard based on the ARM template, so we can use deployment scripts or Java SDK to deploy it. But please confirm the scope and find the correct method in the SDK.
Tell me which language SDK you are interested in. we may discuss it next time. :smiling_face_with_smiling_eyes:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.