azurermCosmosdbAccount
Manages a CosmosDB (formally DocumentDB) Account.
Example Usage
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
import * as random from "./.gen/providers/random";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm, random.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
this,
"example",
{
location: "West Europe",
name: "example-resource-group",
}
);
const randomIntegerRi = new random.integer.Integer(this, "ri", {
max: 99999,
min: 10000,
});
new azurerm.cosmosdbAccount.CosmosdbAccount(this, "db", {
capabilities: [
{
name: "EnableAggregationPipeline",
},
{
name: "mongoEnableDocLevelTTL",
},
{
name: "MongoDBv3.4",
},
{
name: "EnableMongo",
},
],
consistency_policy: [
{
consistency_level: "BoundedStaleness",
max_interval_in_seconds: 300,
max_staleness_prefix: 100000,
},
],
enable_automatic_failover: true,
geo_location: [
{
failover_priority: 1,
location: "eastus",
},
{
failover_priority: 0,
location: "westus",
},
],
kind: "MongoDB",
location: azurermResourceGroupExample.location,
name: `tfex-cosmos-db-\${${randomIntegerRi.result}}`,
offer_type: "Standard",
resource_group_name: azurermResourceGroupExample.name,
});
Argument Reference
The following arguments are supported:
-
name
- (Required) Specifies the name of the CosmosDB Account. Changing this forces a new resource to be created. -
resourceGroupName
- (Required) The name of the resource group in which the CosmosDB Account is created. Changing this forces a new resource to be created. -
location
- (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -
tags
- (Optional) A mapping of tags to assign to the resource. -
offerType
- (Required) Specifies the Offer Type to use for this CosmosDB Account; currently, this can only be set tostandard
. -
analyticalStorage
- (Optional) AnanalyticalStorage
block as defined below. -
capacity
- (Optional) Acapacity
block as defined below. -
createMode
- (Optional) The creation mode for the CosmosDB Account. Possible values aredefault
andrestore
. Changing this forces a new resource to be created.
\~> NOTE: createMode
only works when backupType
is continuous
.
-
defaultIdentityType
- (Optional) The default identity for accessing Key Vault. Possible values arefirstPartyIdentity
,systemAssignedIdentity
or start withuserAssignedIdentity
. -
kind
- (Optional) Specifies the Kind of CosmosDB to create - possible values areglobalDocumentDb
,mongoDb
andparse
. Defaults toglobalDocumentDb
. Changing this forces a new resource to be created. -
consistencyPolicy
- (Required) Specifies aconsistencyPolicy
resource, used to define the consistency policy for this CosmosDB account. -
geoLocation
- (Required) Specifies ageoLocation
resource, used to define where data should be replicated with thefailoverPriority
0 specifying the primary location. Value is ageoLocation
block as defined below. -
ipRangeFilter
- (Optional) CosmosDB Firewall Support: This value specifies the set of IP addresses or IP address ranges in CIDR form to be included as the allowed list of client IPs for a given database account. IP addresses/ranges must be comma separated and must not contain any spaces.
\~> NOTE: To enable the "Allow access from the Azure portal" behavior, you should add the IP addresses provided by the documentation to this list.
\~> NOTE: To enable the "Accept connections from within public Azure datacenters" behavior, you should add 0000
to the list, see the documentation for more details.
-
enableFreeTier
- (Optional) Enable the Free Tier pricing option for this Cosmos DB account. Defaults tofalse
. Changing this forces a new resource to be created. -
analyticalStorageEnabled
- (Optional) Enable Analytical Storage option for this Cosmos DB account. Defaults tofalse
. Enabling and then disabling analytical storage forces a new resource to be created. -
enableAutomaticFailover
- (Optional) Enable automatic failover for this Cosmos DB account. -
publicNetworkAccessEnabled
- (Optional) Whether or not public network access is allowed for this CosmosDB account. Defaults totrue
. -
capabilities
- (Optional) The capabilities which should be enabled for this Cosmos DB account. Value is acapabilities
block as defined below. -
isVirtualNetworkFilterEnabled
- (Optional) Enables virtual network filtering for this Cosmos DB account. -
keyVaultKeyId
- (Optional) A versionless Key Vault Key ID for CMK encryption. Changing this forces a new resource to be created.
\~> NOTE: When referencing an azurermKeyVaultKey
resource, use versionlessId
instead of id
\~> NOTE: In order to use a customKey
from Key Vault for encryption you must grant Azure Cosmos DB Service access to your key vault. For instructions on how to configure your Key Vault correctly please refer to the product documentation
-
virtualNetworkRule
- (Optional) Specifies avirtualNetworkRules
resource, used to define which subnets are allowed to access this CosmosDB account. -
enableMultipleWriteLocations
- (Optional) Enable multiple write locations for this Cosmos DB account. -
accessKeyMetadataWritesEnabled
- (Optional) Is write operations on metadata resources (databases, containers, throughput) via account keys enabled? Defaults totrue
. -
mongoServerVersion
- (Optional) The Server Version of a MongoDB account. Possible values are42
,40
,36
, and32
. -
networkAclBypassForAzureServices
- (Optional) If Azure services can bypass ACLs. Defaults tofalse
. -
networkAclBypassIds
- (Optional) The list of resource Ids for Network Acl Bypass for this Cosmos DB account. -
localAuthenticationDisabled
- (Optional) Disable local authentication and ensure only MSI and AAD can be used exclusively for authentication. Defaults tofalse
. Can be set only when using the SQL API. -
backup
- (Optional) Abackup
block as defined below. -
corsRule
- (Optional) AcorsRule
block as defined below. -
identity
- (Optional) Anidentity
block as defined below. -
restore
- (Optional) Arestore
block as defined below.
\~> NOTE: restore
should be set when createMode
is restore
.
The consistencyPolicy
block Configures the database consistency and supports the following:
-
consistencyLevel
- (Required) The Consistency Level to use for this CosmosDB Account - can be eitherboundedStaleness
,eventual
,session
,strong
orconsistentPrefix
. -
maxIntervalInSeconds
- (Optional) When used with the Bounded Staleness consistency level, this value represents the time amount of staleness (in seconds) tolerated. The accepted range for this value is5
-86400
(1 day). Defaults to5
. Required whenconsistencyLevel
is set toboundedStaleness
. -
maxStalenessPrefix
- (Optional) When used with the Bounded Staleness consistency level, this value represents the number of stale requests tolerated. The accepted range for this value is10
–2147483647
. Defaults to100
. Required whenconsistencyLevel
is set toboundedStaleness
.
\~> Note: maxIntervalInSeconds
and maxStalenessPrefix
can only be set to custom values when consistencyLevel
is set to boundedStaleness
- otherwise they will return the default values shown above.
The geoLocation
block Configures the geographic locations the data is replicated to and supports the following:
-
location
- (Required) The name of the Azure region to host replicated data. -
failoverPriority
- (Required) The failover priority of the region. A failover priority of0
indicates a write region. The maximum value for a failover priority = (total number of regions - 1). Failover priority values must be unique for each of the regions in which the database account exists. Changing this causes the location to be re-provisioned and cannot be changed for the location with failover priority0
. -
zoneRedundant
- (Optional) Should zone redundancy be enabled for this region? Defaults tofalse
.
A capabilities
block Configures the capabilities to be enabled for this Cosmos DB account:
name
- (Required) The capability to enable - Possible values areallowSelfServeUpgradeToMongo36
,disableRateLimitingResponses
,enableAggregationPipeline
,enableCassandra
,enableGremlin
,enableMongo
,enableMongo16MbDocumentSupport
,enableMongoRetryableWrites
,enableMongoRoleBasedAccessControl
,enableServerless
,enableTable
,enableUniqueCompoundNestedDocs
,mongoDBv34
andmongoEnableDocLevelTtl
.
\~> NOTE: Setting mongoDBv34
also requires setting enableMongo
.
\~> NOTE: Only allowSelfServeUpgradeToMongo36
, disableRateLimitingResponses
, enableAggregationPipeline
, mongoDBv34
, enableMongoRetryableWrites
, enableMongoRoleBasedAccessControl
, enableUniqueCompoundNestedDocs
, enableMongo16MbDocumentSupport
and mongoEnableDocLevelTtl
can be added to an existing Cosmos DB account.
\~> NOTE: Only disableRateLimitingResponses
and enableMongoRetryableWrites
can be removed from an existing Cosmos DB account.
The virtualNetworkRule
block Configures the virtual network subnets allowed to access this Cosmos DB account and supports the following:
id
- (Required) The ID of the virtual network subnet.ignoreMissingVnetServiceEndpoint
- (Optional) If set to true, the specified subnet will be added as a virtual network rule even if its CosmosDB service endpoint is not active. Defaults tofalse
.
An analyticalStorage
block supports the following:
schemaType
- (Required) The schema type of the Analytical Storage for this Cosmos DB account. Possible values arefullFidelity
andwellDefined
.
A capacity
block supports the following:
totalThroughputLimit
- (Required) The total throughput limit imposed on this Cosmos DB account (RU/s). Possible values are at least1
.1
means no limit.
A backup
block supports the following:
-
type
- (Required) The type of thebackup
. Possible values arecontinuous
andperiodic
. Migration ofperiodic
tocontinuous
is one-way, changingcontinuous
toperiodic
forces a new resource to be created. -
intervalInMinutes
- (Optional) The interval in minutes between two backups. This is configurable only whentype
isperiodic
. Possible values are between 60 and 1440. -
retentionInHours
- (Optional) The time in hours that each backup is retained. This is configurable only whentype
isperiodic
. Possible values are between 8 and 720. -
storageRedundancy
- (Optional) The storage redundancy is used to indicate the type of backup residency. This is configurable only whentype
isperiodic
. Possible values aregeo
,local
andzone
.
A corsRule
block supports the following:
-
allowedHeaders
- (Required) A list of headers that are allowed to be a part of the cross-origin request. -
allowedMethods
- (Required) A list of HTTP headers that are allowed to be executed by the origin. Valid options aredelete
,get
,head
,merge
,post
,options
,put
orpatch
. -
allowedOrigins
- (Required) A list of origin domains that will be allowed by CORS. -
exposedHeaders
- (Required) A list of response headers that are exposed to CORS clients. -
maxAgeInSeconds
- (Required) The number of seconds the client should cache a preflight response.
An identity
block supports the following:
-
type
- (Required) The Type of Managed Identity assigned to this Cosmos account. Possible values aresystemAssigned
,userAssigned
andsystemAssigned,UserAssigned
. -
identityIds
- (Optional) Specifies a list of User Assigned Managed Identity IDs to be assigned to this Cosmos Account.
A restore
block supports the following:
sourceCosmosdbAccountId
- (Required) The resource ID of the restorable database account from which the restore has to be initiated. The example is/subscriptions/{subscriptionId}/providers/microsoftDocumentDb/locations/{location}/restorableDatabaseAccounts/{restorableDatabaseAccountName}
. Changing this forces a new resource to be created.
\~> NOTE: Any database account with continuous
type (live account or accounts deleted in last 30 days) is a restorable database account and there cannot be Create/Update/Delete operations on the restorable database accounts. They can only be read and retrieved by azurermCosmosdbRestorableDatabaseAccounts
.
-
restoreTimestampInUtc
- (Required) The creation time of the database or the collection (Datetime Formatrfc3339
). Changing this forces a new resource to be created. -
database
- (Optional) Adatabase
block as defined below. Changing this forces a new resource to be created.
A database
block supports the following:
-
name
- (Required) The database name for the restore request. Changing this forces a new resource to be created. -
collectionNames
- (Optional) A list of the collection names for the restore request. Changing this forces a new resource to be created.
Attributes Reference
The following attributes are exported:
-
id
- The CosmosDB Account ID. -
endpoint
- The endpoint used to connect to the CosmosDB account. -
readEndpoints
- A list of read endpoints available for this CosmosDB account. -
writeEndpoints
- A list of write endpoints available for this CosmosDB account. -
primaryKey
- The Primary key for the CosmosDB Account. -
secondaryKey
- The Secondary key for the CosmosDB Account. -
primaryReadonlyKey
- The Primary read-only Key for the CosmosDB Account. -
secondaryReadonlyKey
- The Secondary read-only key for the CosmosDB Account. -
connectionStrings
- A list of connection strings available for this CosmosDB account.
An identity
block exports the following:
-
principalId
- The Principal ID associated with this Managed Service Identity. -
tenantId
- The Tenant ID associated with this Managed Service Identity.
Timeouts
The timeouts
block allows you to specify timeouts for certain actions:
create
- (Defaults to 180 minutes) Used when creating the CosmosDB Account.update
- (Defaults to 180 minutes) Used when updating the CosmosDB Account.read
- (Defaults to 5 minutes) Used when retrieving the CosmosDB Account.delete
- (Defaults to 180 minutes) Used when deleting the CosmosDB Account.
Import
CosmosDB Accounts can be imported using the resourceId
, e.g.