This example demonstrates the usage of Pulumi to create globally-distributed applications with Azure Cosmos DB as the backend and pluggable infrastrustructure as the web tier.
The application shows several notable features:
- Easy global deployments - a config setting provides a list of all the regions to deploy and a single execution deploys across them all.
- Abstraction - the
CosmosApp
component - abstracts away all the common logic for a global app with Cosmos DB multi-region data distribution and Traffic Manager for routing the traffic. - Multi-model - examples are provided for serverless functions, containers, and virtual machines, all fitting to the above abstraction.
The CosmosApp
defines a skeleton for the application. While not limiting the type of compute resources, it creates the multi-regional pieces of the infrastructure:
The application has three example of using this component with the following compute services:
- Azure Functions
- Azure Container Instances
- Azure VM Scale Sets + Azure Load Balancer
$ pulumi stack init dev
You will be prompted to do this during deployment if you forget this step.
$ az login
$ npm install
Run pulumi up
to preview and deploy changes:
$ pulumi up
Previewing changes:
+ azure-ts-cosmosapp-component-dev create
+ examples:azure:CosmosApp vms create
+ azure:network:VirtualNetwork vnet-westeurope create
+ azure:network:PublicIp pip-westeurope create
+ azure:trafficmanager:Profile tmvms create
+ azure:trafficmanager:Endpoint tmvmswesteurope create
+ azure:cosmosdb:Account cosmos-vms
...
Three endpoints are now available. For example,
$ pulumi stack output functionsEndpoint
http://functionscosmosfunc-rgcc15ea50.trafficmanager.net/api/cosmos
$ curl "$(pulumi stack output functionsEndpoint)"
Document 'cosmos' not found
Go to the Azure portal and add a document with the ID "cosmos" to receive a non-empty response.