2022-04-23 02:15:31 +03:00
|
|
|
resource "azurerm_cosmosdb_gremlin_database" "this" {
|
|
|
|
for_each = var.gremlin_dbs
|
|
|
|
name = each.value.db_name
|
|
|
|
resource_group_name = data.azurerm_resource_group.this.name
|
|
|
|
account_name = azurerm_cosmosdb_account.this.name
|
|
|
|
throughput = each.value.db_max_throughput != null ? null : each.value.db_throughput
|
|
|
|
|
|
|
|
dynamic "autoscale_settings" {
|
|
|
|
for_each = each.value.db_max_throughput != null ? [1] : []
|
|
|
|
content {
|
|
|
|
max_throughput = each.value.db_max_throughput
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_cosmosdb_gremlin_graph" "this" {
|
|
|
|
for_each = var.gremlin_graphs
|
|
|
|
name = each.value.graph_name
|
|
|
|
resource_group_name = data.azurerm_resource_group.this.name
|
|
|
|
account_name = azurerm_cosmosdb_account.this.name
|
|
|
|
database_name = each.value.db_name
|
|
|
|
partition_key_path = each.value.partition_key_path
|
2022-05-26 14:33:50 +03:00
|
|
|
partition_key_version = each.value.partition_key_version != null ? each.value.partition_key_version : null
|
|
|
|
default_ttl = each.value.default_ttl_seconds != null ? each.value.default_ttl_seconds : null
|
2022-04-23 02:15:31 +03:00
|
|
|
throughput = each.value.graph_max_throughput != null ? null : each.value.graph_throughput
|
|
|
|
|
|
|
|
dynamic "autoscale_settings" {
|
|
|
|
for_each = each.value.graph_max_throughput != null ? [1] : []
|
|
|
|
content {
|
|
|
|
max_throughput = each.value.graph_max_throughput
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Index policy is required
|
2022-05-26 14:33:50 +03:00
|
|
|
dynamic "index_policy" {
|
|
|
|
for_each = length(each.value.index_policy_settings) > 0 ? [1] : []
|
2022-04-23 02:15:31 +03:00
|
|
|
content {
|
2022-05-26 14:33:50 +03:00
|
|
|
# Automatic indexing policy is optional
|
|
|
|
automatic = each.value.index_policy_settings.indexing_automatic != null ? each.value.index_policy_settings.indexing_automatic : null
|
|
|
|
# Indexing mode is required
|
|
|
|
indexing_mode = each.value.index_policy_settings.indexing_mode
|
|
|
|
# Included paths is optional
|
|
|
|
included_paths = each.value.index_policy_settings.included_paths != null ? each.value.index_policy_settings.included_paths : null
|
|
|
|
# Excluded paths is optional
|
|
|
|
excluded_paths = each.value.index_policy_settings.excluded_paths != null ? each.value.index_policy_settings.excluded_paths : null
|
|
|
|
|
|
|
|
# Composite index is optional
|
|
|
|
dynamic "composite_index" {
|
|
|
|
for_each = each.value.index_policy_settings.composite_indexes != null ? each.value.index_policy_settings.composite_indexes : {}
|
|
|
|
content {
|
|
|
|
dynamic "index" {
|
|
|
|
for_each = composite_index.value.indexes
|
|
|
|
content {
|
|
|
|
path = index.value.index_path
|
|
|
|
order = index.value.index_order
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Spatial Index is optional
|
|
|
|
dynamic "spatial_index" {
|
|
|
|
for_each = each.value.index_policy_settings.spatial_indexes != null ? each.value.index_policy_settings.spatial_indexes : {}
|
|
|
|
content {
|
|
|
|
path = spatial_index.value.spatial_index_path
|
|
|
|
}
|
|
|
|
}
|
2022-04-23 02:15:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-26 14:33:50 +03:00
|
|
|
# Unique Key is optional
|
|
|
|
unique_key {
|
|
|
|
paths = each.value.unique_key
|
|
|
|
}
|
|
|
|
|
|
|
|
# Conflict Resolution policy is optional
|
|
|
|
dynamic "conflict_resolution_policy" {
|
|
|
|
for_each = each.value.conflict_resolution_policy != null ? [1] : []
|
2022-04-23 02:15:31 +03:00
|
|
|
content {
|
2022-05-26 14:33:50 +03:00
|
|
|
mode = each.value.conflict_resolution_policy.conflict_resolution_mode
|
|
|
|
conflict_resolution_path = each.value.conflict_resolution_policy.conflict_resolution_mode == "LastWriterWins" ? each.value.conflict_resolution_policy.conflict_resolution_path : null
|
|
|
|
conflict_resolution_procedure = each.value.conflict_resolution_policy.conflict_resolution_mode == "Custom" ? each.value.conflict_resolution_policy.conflict_resolution_procedure : null
|
2022-04-23 02:15:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Depends on existence of Cosmos DB Gremlin API Database managed by module
|
|
|
|
depends_on = [
|
|
|
|
azurerm_cosmosdb_gremlin_database.this
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|