Skip to content

Instantly share code, notes, and snippets.

@markjbrown
Created September 27, 2020 17:05
Show Gist options
  • Save markjbrown/08d165dc15870bce0c4c92362ada3424 to your computer and use it in GitHub Desktop.
Save markjbrown/08d165dc15870bce0c4c92362ada3424 to your computer and use it in GitHub Desktop.
Pulumi Cosmos DB Quickstart Stack
using Pulumi;
using Pulumi.AzureNextGen.Resources.Latest;
using Pulumi.AzureNextGen.DocumentDB.Latest;
using Pulumi.AzureNextGen.DocumentDB.Latest.Inputs;
using System.Collections.Generic;
using System.Collections.Immutable;
class MyStack : Stack
{
public MyStack()
{
var resourceGroup = new ResourceGroup("mjbPulumi", new ResourceGroupArgs
{
ResourceGroupName = "mjbPulumi",
Location = "westus2"
});
var databaseAccount = new DatabaseAccount("mjbPulumi-Account", new DatabaseAccountArgs
{
AccountName = "mjbPulumi-Account",
Location = "westus2",
ResourceGroupName = "mjbPulumi2",
DatabaseAccountOfferType = "Standard",
ConsistencyPolicy = new ConsistencyPolicyArgs { DefaultConsistencyLevel = "Session" },
EnableAutomaticFailover = true,
Locations =
{
new LocationArgs
{
FailoverPriority = 0,
IsZoneRedundant = false,
LocationName = "westus2"
},
new LocationArgs
{
FailoverPriority = 1,
IsZoneRedundant = false,
LocationName = "eastus2"
}
}
});
var sqlDatabase = new SqlResourceSqlDatabase("database1", new SqlResourceSqlDatabaseArgs
{
AccountName = databaseAccount.Name,
DatabaseName = "database1",
ResourceGroupName = "mjbPulumi2",
Resource = new SqlDatabaseResourceArgs
{
Id = "database1",
},
Options = new CreateUpdateOptionsArgs()
});
var sqlContainer = new SqlResourceSqlContainer("container1", new SqlResourceSqlContainerArgs
{
AccountName = databaseAccount.Name,
DatabaseName = sqlDatabase.Name,
ContainerName = "container1",
ResourceGroupName = "mjbPulumi2",
Resource = new SqlContainerResourceArgs
{
Id = "container1",
PartitionKey = new ContainerPartitionKeyArgs
{
Kind = "Hash",
Paths = { "/myPartitionKey" },
Version = 1
},
IndexingPolicy = new IndexingPolicyArgs
{
Automatic = true,
IndexingMode = "Consistent",
IncludedPaths = new IncludedPathArgs
{
Path = "/*"
},
ExcludedPaths = new ExcludedPathArgs
{
Path = "/myPathToExclude/?"
},
SpatialIndexes =
{
new SpatialSpecArgs
{
Path = "/mySpatialProperty",
Types = new List<string> { "Point", "LineString", "Polygon", "MultiPolygon" }
}
},
CompositeIndexes =
{
new[]
{
new CompositePathArgs { Path = "myOrderByPath1", Order = "Ascending" },
new CompositePathArgs { Path = "myOrderByPath2", Order = "Descending" }
}.ToImmutableArray()
}
},
UniqueKeyPolicy = new UniqueKeyPolicyArgs
{
UniqueKeys =
{
new UniqueKeyArgs
{
Paths =
{
"/uniqueKey1",
"/uniqueKey2"
}
}
}
}
},
Options = new CreateUpdateOptionsArgs
{
AutoscaleSettings = new AutoscaleSettingsArgs
{
MaxThroughput = 1000
}
}
});
}
[Output]
public Output<string> ConnectionString { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment