Azure Cosmos DB, an API connection, and a Logic App
An example of creating a CosmosDB container through a Azure's Cosmos SDK and deploying a Logic App and an API Connection
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set azure-py-cosmosdb-logicappcd pulumi-examples/azure-py-cosmosdb-logicappWith the native Azure provider we can directly use the Azure resource manager API to define API connections and linking it to a logic app. The resulting experience is much faster in comparison to performing the same operation through ARM templates.
Prerequisites#
Deploying the example#
-
Create a new stack:
Terminal window pulumi stack init dev -
Log in to the Azure CLI (you will be prompted to do this during deployment if you forget this step):
Terminal window az login -
Set the Azure region to deploy into:
Terminal window pulumi config set azure-native:location westeurope -
Install dependencies:
Terminal window python3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Deploy the stack:
Terminal window pulumi upType Name Status+ pulumi:pulumi:Stack azure-cosmosdb-logicapp-dev created+ ├─ azure-native:resources:ResourceGroup logicappdemo-rg created+ ├─ azure-native:storage:StorageAccount logicappdemosa created+ ├─ azure-native:documentdb:DatabaseAccount logicappdemo-cdb created+ ├─ azure-native:documentdb:SqlResourceSqlDatabase db created+ ├─ azure-native:web:Connection cosmosdbConnection created+ ├─ azure-native:documentdb:SqlResourceSqlContainer container created+ └─ azure-native:logic:Workflow workflow createdResources:+ 8 createdDuration: 3m16s -
At this point, you have a Cosmos DB collection and a Logic App listening to HTTP requests. Trigger the Logic App with a
curlcommand:Terminal window curl -X POST "$(pulumi stack output endpoint)" -d '"Hello World"' -H 'Content-Type: application/json'The POST body will be saved into a new document in the Cosmos DB collection.
Cleaning up#
Once you are finished, you can destroy your stack and remove it to avoid incurring any additional cost:
pulumi destroypulumi stack rm