Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 45 additions & 26 deletions fast/project-templates/data-mongodb/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,29 @@
*/

locals {
psc_endpoint_key = "${var.name}-0"
region = regex(
"projects/[^/]+/regions/([^/]+)/subnetworks/[^/]+$",
var.vpc_config.subnetwork_id
)[0]
# shortcut for output references to avoid >79-char lines
_cluster_region_config = (
mongodbatlas_advanced_cluster.default.replication_specs[0].region_configs[0]
)
}

module "addresses" {
source = "../../../modules/net-address"
project_id = var.project_id
psc_addresses = {
for i in range(50) : "${var.name}-${i}" => {
address = cidrhost(var.vpc_config.psc_cidr_block, i)
(local.psc_endpoint_key) = {
# Avoid the network base address; GCP reserves early host addresses.
address = cidrhost(var.vpc_config.psc_cidr_block, 4)
region = local.region
subnet_self_link = var.vpc_config.subnetwork_id
service_attachment = {
psc_service_attachment_link = (
mongodbatlas_privatelink_endpoint.default.service_attachment_names[i]
mongodbatlas_privatelink_endpoint.default.service_attachment_names[0]
)
global_access = true
}
Expand All @@ -44,32 +50,45 @@ resource "mongodbatlas_project" "default" {
org_id = var.atlas_config.organization_id
}

resource "mongodbatlas_cluster" "default" {
project_id = mongodbatlas_project.default.id
name = var.atlas_config.cluster_name
provider_name = "GCP"
provider_instance_size_name = var.atlas_config.instance_size
provider_region_name = var.atlas_config.region
mongo_db_major_version = var.atlas_config.database_version
resource "mongodbatlas_advanced_cluster" "default" {
project_id = mongodbatlas_project.default.id
name = var.atlas_config.cluster_name
cluster_type = "REPLICASET"
mongo_db_major_version = var.atlas_config.database_version

replication_specs = [{
region_configs = [{
provider_name = "GCP"
region_name = var.atlas_config.region
priority = 7
electable_specs = {
instance_size = var.atlas_config.instance_size
node_count = 3
}
}]
}]
}

moved {
from = mongodbatlas_cluster.default
to = mongodbatlas_advanced_cluster.default
Comment on lines +73 to +74

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using moved blocks between different resource types requires explicit support from the provider. Does the mongodbatlas support this?

}

resource "mongodbatlas_privatelink_endpoint" "default" {
project_id = mongodbatlas_project.default.id
provider_name = "GCP"
region = var.atlas_config.region
project_id = mongodbatlas_project.default.id
provider_name = "GCP"
region = var.atlas_config.region
port_mapping_enabled = true
}

resource "mongodbatlas_privatelink_endpoint_service" "default" {
project_id = mongodbatlas_privatelink_endpoint.default.project_id
private_link_id = mongodbatlas_privatelink_endpoint.default.private_link_id
provider_name = "GCP"
endpoint_service_id = var.vpc_config.network_name
gcp_project_id = var.project_id
dynamic "endpoints" {
for_each = module.addresses.psc
content {
ip_address = endpoints.value.address.address
endpoint_name = endpoints.value.forwarding_rule.name
}
}
}
project_id = mongodbatlas_privatelink_endpoint.default.project_id
private_link_id = mongodbatlas_privatelink_endpoint.default.private_link_id
provider_name = "GCP"
endpoint_service_id = module.addresses.psc[local.psc_endpoint_key].forwarding_rule.name
private_endpoint_ip_address = module.addresses.psc[local.psc_endpoint_key].address.address
gcp_project_id = var.project_id

# Wait for the GCP PSC forwarding rule before registering it in Atlas.
depends_on = [module.addresses]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this depends_on is unnecessary and redundant.

}
Loading