Skip to content

Commit

Permalink
Update the Cosmos App example (pulumi#745)
Browse files Browse the repository at this point in the history
* Tests and policy

* Fix
  • Loading branch information
mikhailshilkov committed Jul 20, 2020
1 parent 9cb78d2 commit c6bbe3a
Show file tree
Hide file tree
Showing 12 changed files with 582 additions and 20 deletions.
18 changes: 17 additions & 1 deletion azure-ts-cosmosapp-component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,20 @@ $ 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.
Go to the Azure portal and add a document with the ID "cosmos" to receive a non-empty response.

## Running Unit Tests

The `unittests.ts` file contains two sample unit tests that can be run with Mocha:

```
mocha -r ts-node/register unittests.ts
```

## Running Policy Pack

The `policy` folder contains two sample policies that can be applied with the `policy-pack` argument:

```
pulumi up --policy-pack policy
```
10 changes: 5 additions & 5 deletions azure-ts-cosmosapp-component/cosmosApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ export class CosmosApp extends pulumi.ComponentResource {
resourceGroupName: resourceGroup.name,
accountName: cosmosAccount.name,
name: args.databaseName,
}, opts);
}, { parent: cosmosAccount, ...opts });

const container = new azure.cosmosdb.SqlContainer(`sql-${name}`, {
resourceGroupName: resourceGroup.name,
accountName: cosmosAccount.name,
databaseName: database.name,
}, opts);
}, { parent: cosmosAccount, ...opts });

// Traffic Manager as a global HTTP endpoint
const profile = new azure.trafficmanager.Profile(`tm${name}`, {
const profile = new azure.network.TrafficManagerProfile(`tm${name}`, {
resourceGroupName: resourceGroup.name,
trafficRoutingMethod: "Performance",
dnsConfig: {
Expand All @@ -95,7 +95,7 @@ export class CosmosApp extends pulumi.ComponentResource {
const app = buildLocation({ location });

// An endpoint per region for Traffic Manager, link to the corresponding instance
return new azure.trafficmanager.Endpoint(`tm${name}${location}`.substring(0, 16), {
return new azure.network.TrafficManagerEndpoint(`tm${name}${location}`.substring(0, 16), {
resourceGroupName: resourceGroup.name,
profileName: profile.name,
type: app.id ? "azureEndpoints" : "externalEndpoints",
Expand All @@ -105,7 +105,7 @@ export class CosmosApp extends pulumi.ComponentResource {
}, { parent: profile, deleteBeforeReplace: true, ...opts });
}));

this.endpoint = pulumi.interpolate`http:https://${profile.fqdn}`;
this.endpoint = endpoints.apply(_ => pulumi.interpolate`http:https://${profile.fqdn}`);

this.registerOutputs();
}
Expand Down
20 changes: 10 additions & 10 deletions azure-ts-cosmosapp-component/functionApp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
// Copyright 2016-2020, Pulumi Corporation. All rights reserved.

import { CosmosClient } from "@azure/cosmos";
import * as azure from "@pulumi/azure";
Expand All @@ -13,9 +13,17 @@ const resourceGroup = new azure.core.ResourceGroup("cosmosfunc-rg", {
location: locations[0],
});

export const functions = new CosmosApp("functions", {
resourceGroup,
locations,
databaseName: "productsdb",
containerName: "products",
factory: buildFunctionApp,
});

function buildFunctionApp({ cosmosAccount, database, container, opts }: GlobalContext) {
return ({ location }: RegionalContext) => {
const fn = new azure.appservice.HttpEventSubscription(`GetUrl-${location}`, {
const fn = new azure.appservice.HttpEventSubscription(`geturl-${location}`, {
resourceGroup,
location,
route: "{key}",
Expand Down Expand Up @@ -51,11 +59,3 @@ function buildFunctionApp({ cosmosAccount, database, container, opts }: GlobalCo
};
};
}

export const functions = new CosmosApp("functions", {
resourceGroup,
locations,
databaseName: "productsdb",
containerName: "products",
factory: buildFunctionApp,
});
6 changes: 5 additions & 1 deletion azure-ts-cosmosapp-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"name": "azure-ts-cosmosapp-component",
"version": "1.0.0",
"devDependencies": {
"@types/node": "^10.3.3"
"@types/node": "^10.3.3",
"@types/mocha": "^5.2.7",
"mocha": "^7.0.0",
"ts-node": "^8.6.2"

},
"dependencies": {
"@azure/cosmos": "latest",
Expand Down
2 changes: 2 additions & 0 deletions azure-ts-cosmosapp-component/policy/PulumiPolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
description: PaC-based integration tests to validate an Azure Cosmos DB deployments.
runtime: nodejs
Loading

0 comments on commit c6bbe3a

Please sign in to comment.