Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as azure from "@pulumi/azure";
import * as pulumi from "@pulumi/pulumi";
const config = new pulumi.Config();
// Read a list of target locations from the config file:
// Expecting a comma-separated list, e.g., "westus,eastus,westeurope"
const locations = config.require("locations").split(",");
// The first location is considered primary
const primaryLocation = locations[0];
const resourceGroup = new azure.core.ResourceGroup("UrlShorterner", {
location: primaryLocation,
});
// Cosmos DB with a single write region (primary location) and multiple read replicas
const account = new azure.cosmosdb.Account("UrlStore", {
resourceGroupName: resourceGroup.name,
location: primaryLocation,
geoLocations: locations.map((location, failoverPriority) => ({ location, failoverPriority })),
offerType: "Standard",
consistencyPolicy: {
consistencyLevel: "Session",
maxIntervalInSeconds: 300,
maxStalenessPrefix: 100000,
},
});
// Define a database under the Cosmos DB Account
const database = new azure.cosmosdb.SqlDatabase("Database", {
resourceGroupName: resourceGroup.name,
accountName: account.name,
});offerType: "Standard",
consistencyPolicy: {
consistencyLevel: "Session",
maxIntervalInSeconds: 300,
maxStalenessPrefix: 100000,
},
});
// Define a database under the Cosmos DB Account
const database = new azure.cosmosdb.SqlDatabase("Database", {
resourceGroupName: resourceGroup.name,
accountName: account.name,
});
// Define a SQL Collection under the Cosmos DB Database
const collection = new azure.cosmosdb.SqlContainer("Urls", {
resourceGroupName: resourceGroup.name,
accountName: account.name,
databaseName: database.name,
});
// Traffic Manager as a global HTTP endpoint
const profile = new azure.trafficmanager.Profile("UrlShortEndpoint", {
resourceGroupName: resourceGroup.name,
trafficRoutingMethod: "Performance",
dnsConfigs: [{
// Subdomain must be globally unique, so we default it with the full resource group name
relativeName: resourceGroup.name,
ttl: 60,
}],
monitorConfigs: [{
protocol: "HTTP",// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as azure from "@pulumi/azure";
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
import { config } from "./config";
import * as mongoHelpers from "./mongoHelpers";
const name = pulumi.getProject();
// Define a separate resource group for app services.
const resourceGroup = new azure.core.ResourceGroup(name);
// Create a MongoDB-flavored instance of CosmosDB.
const cosmosdb = new azure.cosmosdb.Account("k8s-az-mongodb", {
resourceGroupName: resourceGroup.name,
kind: "MongoDB",
consistencyPolicy: {
consistencyLevel: "Session",
},
offerType: "Standard",
geoLocations: [
{ location: resourceGroup.location, failoverPriority: 0 },
],
});
// A k8s provider instance of the cluster.
const provider = new k8s.Provider(`${name}-aks`, {
kubeconfig: config.kubeconfig,
});constructor(name: string,
args: CosmosAppArgs,
opts: pulumi.ComponentResourceOptions = {}) {
super("examples:azure:CosmosApp", name, args, opts);
const resourceGroup = args.resourceGroup;
const locations = pulumi.output(args.locations);
const primaryLocation = locations[0];
const parentOpts = { parent: this, ...opts };
// Cosmos DB Account with multiple replicas
const cosmosAccount = new azure.cosmosdb.Account(`cosmos-${name}`, {
resourceGroupName: resourceGroup.name,
location: primaryLocation,
geoLocations: locations.apply(ls => ls.map((location, failoverPriority) => ({ location, failoverPriority }))),
offerType: "Standard",
consistencyPolicy: {
consistencyLevel: "Session",
maxIntervalInSeconds: 300,
maxStalenessPrefix: 100000,
},
enableMultipleWriteLocations: args.enableMultiMaster,
}, parentOpts);
const database = new azure.cosmosdb.SqlDatabase(`db-${name}`, {
resourceGroupName: resourceGroup.name,
accountName: cosmosAccount.name,
name: args.databaseName,// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as azure from "@pulumi/azure";
import * as k8s from "@pulumi/kubernetes";
import * as config from "./config";
import * as mongoHelpers from "./mongoHelpers";
// Create an AKS cluster.
import { k8sCluster, k8sProvider } from "./cluster";
// Create a MongoDB-flavored instance of CosmosDB.
const cosmosdb = new azure.cosmosdb.Account("cosmosDb", {
kind: "MongoDB",
resourceGroupName: config.resourceGroup.name,
consistencyPolicy: {
consistencyLevel: "BoundedStaleness",
maxIntervalInSeconds: 10,
maxStalenessPrefix: 200,
},
offerType: "Standard",
enableAutomaticFailover: true,
geoLocations: [
{ location: config.location, failoverPriority: 0 },
{ location: config.failoverLocation, failoverPriority: 1 },
],
});
// Create secret from MongoDB connection string.offerType: "Standard",
consistencyPolicy: {
consistencyLevel: "Session",
maxIntervalInSeconds: 300,
maxStalenessPrefix: 100000,
},
enableMultipleWriteLocations: args.enableMultiMaster,
}, parentOpts);
const database = new azure.cosmosdb.SqlDatabase(`db-${name}`, {
resourceGroupName: resourceGroup.name,
accountName: cosmosAccount.name,
name: args.databaseName,
}, opts);
const container = new azure.cosmosdb.SqlContainer(`sql-${name}`, {
resourceGroupName: resourceGroup.name,
accountName: cosmosAccount.name,
databaseName: database.name,
}, opts);
// Traffic Manager as a global HTTP endpoint
const profile = new azure.trafficmanager.Profile(`tm${name}`, {
resourceGroupName: resourceGroup.name,
trafficRoutingMethod: "Performance",
dnsConfigs: [{
// Subdomain must be globally unique, so we default it with the full resource group name
relativeName: pulumi.interpolate`${name}${resourceGroup.name}`,
ttl: 60,
}],
monitorConfigs: [{
protocol: "HTTP",import * as azure from "@pulumi/azure";
import * as pulumi from "@pulumi/pulumi";
// Create an Azure Resource Group
const resourceGroup = new azure.core.ResourceGroup("logicappdemo-rg");
// Create an Azure resource (Storage Account)
const storageAccount = new azure.storage.Account("logicappdemosa", {
resourceGroupName: resourceGroup.name,
accountReplicationType: "LRS",
accountTier: "Standard",
accountKind: "StorageV2",
});
// Cosmos DB Account
const cosmosdbAccount = new azure.cosmosdb.Account("logicappdemo-cdb", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
offerType: "Standard",
geoLocations: [{ location: resourceGroup.location, failoverPriority: 0 }],
consistencyPolicy: {
consistencyLevel: "Session",
},
});
// Cosmos DB Database
const db = new azure.cosmosdb.SqlDatabase("db", {
resourceGroupName: resourceGroup.name,
accountName: cosmosdbAccount.name,
});
// Cosmos DB SQL ContaineraccountKind: "StorageV2",
});
// Cosmos DB Account
const cosmosdbAccount = new azure.cosmosdb.Account("logicappdemo-cdb", {
resourceGroupName: resourceGroup.name,
location: resourceGroup.location,
offerType: "Standard",
geoLocations: [{ location: resourceGroup.location, failoverPriority: 0 }],
consistencyPolicy: {
consistencyLevel: "Session",
},
});
// Cosmos DB Database
const db = new azure.cosmosdb.SqlDatabase("db", {
resourceGroupName: resourceGroup.name,
accountName: cosmosdbAccount.name,
});
// Cosmos DB SQL Container
const dbContainer = new azure.cosmosdb.SqlContainer("container", {
resourceGroupName: resourceGroup.name,
accountName: cosmosdbAccount.name,
databaseName: db.name,
});
/*
* API Connection to be used in a Logic App
*/
// Calculate the subscription path