Get-CmAzService

An implementation of the Service Locator pattern in PowerShell using Azure Tags to identify services.

Finds Azure Resources based on the tag value of “cm-service”, alongside additional filters for service type and region. Service names can be anything, and can therefore be shaped to a specific organisation’s context and uses.

The service locator pattern provides a canonical naming mechanism for Azure Resources which allows a component-based deployments, where each component is responsible for locating its own dependencies. A deployment may then fail if its dependencies are not deployed.

This command is part of the common command tooling.

Parameters

-Service

Required. (String) Represents the service name to search for.

-ServiceKey

Required. (String) Represents the service key to search for. By default, this is "cm-service", but it can be overridden. Do so with caution, as this breaks a fundamental convention used in the Cloudmarque framework.

-Region

Required. (String) A region to search within - allows the same service to be deployed in multiple regions, or other commands to validate that the service is available in the specified region.

-IsResourceGroup

Required. (SwitchParameter) Indicates whether the resource to be located is a resource group.

-ThrowIfUnavailable

Required. (SwitchParameter) Indicates that an exception should be thrown if the specified resource is unavailable. This is useful in scripts where dependencies are mandatory prior to provisioning. By default this is false, no service will be returned but a "not found" message will be written in verbose mode.

-ThrowIfMultiple

Required. (SwitchParameter) Indicates that an exception should be thrown if multiple resources are returned, by default this is false.

Examples

Example 1

1
2
3
4
    Find a single keyvault
$keyVault = Get-CmAzService -Service "core-keys" -Region "USEast" -ThrowIfMultiple
    
  

Example 2

1
2
3
4
    Find a single storage account for NSG logs
$storageAccount = Get-CmAzService -Service "core-monitoring-logs-nsg" -Region "USEast" -ThrowIfMultiple
    
  

Example 3

1
2
3
4
    Find a set of vms
$vms = Get-CmAzService -Service "core.mySetOfVms" -Region "UKSouth"