Async template deployments with Java AzureResourceManager

Viewed 34

I'm writing a service that submits ARM templates to spin up various Azure resources via the Azure Java client API, for example:

Mono<Deployment> deploymentMono = arm.deployments()
  .define(deploymentName)
  .withNewResourceGroup(resourceGroup, Region.US_WEST2)
  .withTemplate(templateJson)
  .withParameters(parametersJson)
  .withMode(DeploymentMode.INCREMENTAL)
  .createAsync();

I want to run it in Azure Functions, but some of these deployments take a long time.

Ideally I'd like to submit a deployment and get back an immediate ok (or error) from the server, with an ID I can use to check the status later. However I only see these options with the client API:

  1. Use create() and block for the whole thing to finish (obviously not what I want).

  2. Use createAsync() and wait for an event. However the only events that look useful are doOnSubscribe (which is called too early), and doOnNext (which isn't called until after the whole thing completes).

I can call subscribe() and then poll the deployment state:

Deployment deployment = arm.deployments().getByResourceGroup(resourceGroup, deploymentName);
if (deployment.provisioningState().equals("Running"))...

but it seems like I must be missing something. There's got to be a method that lets me just submit an ARM template, get confirmation that the Resource Manager is doing its thing, and not wait around for completion, right?

1 Answers

I found it - it's the beginCreate() method on the Deployment.DefinitionStages.WithCreate interface.

Boy, I really hate fluent APIs sometimes. Having docs spread out over 50 objects when you could have a few simple factory methods isn't a step forward in usability, imho.

Related