Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Adds documentation and example for mongodbatlas_flex_cluster resource and data source #2744

Merged
merged 17 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
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
86 changes: 86 additions & 0 deletions docs/data-sources/flex_cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Data Source: mongodbatlas_flex_cluster

`mongodbatlas_flex_cluster` describes a flex cluster.

## Example Usages
```terraform
resource "mongodbatlas_flex_cluster" "example-cluster" {
project_id = var.project_id
name = var.cluster_name
provider_settings = {
backing_provider_name = "AWS"
region_name = "US_EAST_1"
}
termination_protection_enabled = true
}

data "mongodbatlas_flex_cluster" "example-cluster" {
project_id = var.project_id
name = mongodbatlas_flex_cluster.example-cluster.name
}

data "mongodbatlas_flex_clusters" "example-clusters" {
project_id = var.project_id
}

output "mongodbatlas_flex_cluster" {
value = data.mongodbatlas_flex_cluster.example-cluster.name
}

output "mongodbatlas_flex_clusters_names" {
value = [for cluster in data.mongodbatlas_flex_clusters.example-clusters.results : cluster.name]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) Human-readable label that identifies the flex cluster.
- `project_id` (String) Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.

**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.

### Read-Only

- `backup_settings` (Attributes) Flex backup configuration (see [below for nested schema](#nestedatt--backup_settings))
- `cluster_type` (String) Flex cluster topology.
- `connection_strings` (Attributes) Collection of Uniform Resource Locators that point to the MongoDB database. (see [below for nested schema](#nestedatt--connection_strings))
- `create_date` (String) Date and time when MongoDB Cloud created this instance. This parameter expresses its value in ISO 8601 format in UTC.
- `id` (String) Unique 24-hexadecimal digit string that identifies the instance.
- `mongo_db_version` (String) Version of MongoDB that the instance runs.
- `provider_settings` (Attributes) Group of cloud provider settings that configure the provisioned MongoDB flex cluster. (see [below for nested schema](#nestedatt--provider_settings))
- `state_name` (String) Human-readable label that indicates the current operating condition of this instance.
- `tags` (Map of String) Map that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the instance.
- `termination_protection_enabled` (Boolean) Flag that indicates whether termination protection is enabled on the cluster. If set to `true`, MongoDB Cloud won't delete the cluster. If set to `false`, MongoDB Cloud will delete the cluster.
- `version_release_system` (String) Method by which the cluster maintains the MongoDB versions.

<a id="nestedatt--backup_settings"></a>
### Nested Schema for `backup_settings`

Read-Only:

- `enabled` (Boolean) Flag that indicates whether backups are performed for this flex cluster. Backup uses [TODO](TODO) for flex clusters.


<a id="nestedatt--connection_strings"></a>
### Nested Schema for `connection_strings`

Read-Only:

- `standard` (String) Public connection string that you can use to connect to this cluster. This connection string uses the mongodb:// protocol.
- `standard_srv` (String) Public connection string that you can use to connect to this flex cluster. This connection string uses the `mongodb+srv://` protocol.


<a id="nestedatt--provider_settings"></a>
### Nested Schema for `provider_settings`

Read-Only:

- `backing_provider_name` (String) Cloud service provider on which MongoDB Cloud provisioned the flex cluster.
- `disk_size_gb` (Number) Storage capacity available to the flex cluster expressed in gigabytes.
- `provider_name` (String) Human-readable label that identifies the cloud service provider.
- `region_name` (String) Human-readable label that identifies the geographic location of your MongoDB flex cluster. The region you choose can affect network latency for clients accessing your databases. For a complete list of region names, see [AWS](https://docs.atlas.mongodb.com/reference/amazon-aws/#std-label-amazon-aws), [GCP](https://docs.atlas.mongodb.com/reference/google-gcp/), and [Azure](https://docs.atlas.mongodb.com/reference/microsoft-azure/).

For more information see: [MongoDB Atlas API - Flex Cluster](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Flex-Clusters/operation/getFlexCluster) Documentation.
96 changes: 96 additions & 0 deletions docs/data-sources/flex_clusters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Data Source: mongodbatlas_flex_clusters

`mongodbatlas_flex_clusters` returns all flex clusters in a project.

## Example Usages
```terraform
resource "mongodbatlas_flex_cluster" "example-cluster" {
project_id = var.project_id
name = var.cluster_name
provider_settings = {
backing_provider_name = "AWS"
region_name = "US_EAST_1"
}
termination_protection_enabled = true
}

data "mongodbatlas_flex_cluster" "example-cluster" {
project_id = var.project_id
name = mongodbatlas_flex_cluster.example-cluster.name
}

data "mongodbatlas_flex_clusters" "example-clusters" {
project_id = var.project_id
}

output "mongodbatlas_flex_cluster" {
value = data.mongodbatlas_flex_cluster.example-cluster.name
}

output "mongodbatlas_flex_clusters_names" {
value = [for cluster in data.mongodbatlas_flex_clusters.example-clusters.results : cluster.name]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `project_id` (String) Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.

**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.

### Read-Only

- `results` (Attributes List) List of returned documents that MongoDB Cloud provides when completing this request. (see [below for nested schema](#nestedatt--results))

<a id="nestedatt--results"></a>
### Nested Schema for `results`

Read-Only:

- `backup_settings` (Attributes) Flex backup configuration (see [below for nested schema](#nestedatt--results--backup_settings))
- `cluster_type` (String) Flex cluster topology.
- `connection_strings` (Attributes) Collection of Uniform Resource Locators that point to the MongoDB database. (see [below for nested schema](#nestedatt--results--connection_strings))
- `create_date` (String) Date and time when MongoDB Cloud created this instance. This parameter expresses its value in ISO 8601 format in UTC.
- `id` (String) Unique 24-hexadecimal digit string that identifies the instance.
- `mongo_db_version` (String) Version of MongoDB that the instance runs.
- `name` (String) Human-readable label that identifies the flex cluster.
- `project_id` (String) Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.

**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.
- `provider_settings` (Attributes) Group of cloud provider settings that configure the provisioned MongoDB flex cluster. (see [below for nested schema](#nestedatt--results--provider_settings))
- `state_name` (String) Human-readable label that indicates the current operating condition of this instance.
- `tags` (Map of String) Map that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the instance.
- `termination_protection_enabled` (Boolean) Flag that indicates whether termination protection is enabled on the cluster. If set to `true`, MongoDB Cloud won't delete the cluster. If set to `false`, MongoDB Cloud will delete the cluster.
- `version_release_system` (String) Method by which the cluster maintains the MongoDB versions.

<a id="nestedatt--results--backup_settings"></a>
### Nested Schema for `results.backup_settings`

Read-Only:

- `enabled` (Boolean) Flag that indicates whether backups are performed for this flex cluster. Backup uses [TODO](TODO) for flex clusters.


<a id="nestedatt--results--connection_strings"></a>
### Nested Schema for `results.connection_strings`

Read-Only:

- `standard` (String) Public connection string that you can use to connect to this cluster. This connection string uses the mongodb:// protocol.
- `standard_srv` (String) Public connection string that you can use to connect to this flex cluster. This connection string uses the `mongodb+srv://` protocol.


<a id="nestedatt--results--provider_settings"></a>
### Nested Schema for `results.provider_settings`

Read-Only:

- `backing_provider_name` (String) Cloud service provider on which MongoDB Cloud provisioned the flex cluster.
- `disk_size_gb` (Number) Storage capacity available to the flex cluster expressed in gigabytes.
- `provider_name` (String) Human-readable label that identifies the cloud service provider.
- `region_name` (String) Human-readable label that identifies the geographic location of your MongoDB flex cluster. The region you choose can affect network latency for clients accessing your databases. For a complete list of region names, see [AWS](https://docs.atlas.mongodb.com/reference/amazon-aws/#std-label-amazon-aws), [GCP](https://docs.atlas.mongodb.com/reference/google-gcp/), and [Azure](https://docs.atlas.mongodb.com/reference/microsoft-azure/).

For more information see: [MongoDB Atlas API - Flex Clusters](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Streams/operation/listFlexClusters) Documentation.
65 changes: 65 additions & 0 deletions docs/guides/flex-cluster-to-dedicated-cluster-migraton-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
page_title: "Migration Guide: Flex Cluster to Dedicated Cluster"
---

# Migration Guide: Flex Cluster to Dedicated Cluster

**Objective**: This guide explains how to replace the `mongodbatlas_flex_cluster` resource with the `mongodbatlas_advanced_cluster` resource.

Currently, the only method to migrate your Flex cluster to a Dedicated cluster is via the Atlas UI.

<!-- Noting that implementation of flex_cluster as a part of mongodb_advanced_cluster in January 2025 will create new migration journey -->

## Best Practices Before Migrating
Before doing any migration, create a backup of your [Terraform state file](https://developer.hashicorp.com/terraform/cli/commands/state).

### Procedure


See [Modify a Cluster](https://www.mongodb.com/docs/atlas/scale-cluster/) for how to migrate via the Atlas UI.

Complete the following procedure to resolves the configuration drift in Terraform. This does not affect the underlying cluster infrastructure.

1. Find the import IDs of the new Dedicated cluster your Flex cluster has migrated to: `{PROJECT_ID}-{CLUSTER_NAME}`, such as `664619d870c247237f4b86a6-clusterName`
2. Add an import block to one of your `.tf` files:
```terraform
import {
to = mongodbatlas_advanced_cluster.this
id = "664619d870c247237f4b86a6-clusterName" # from step 1
}
```
3. Run `terraform plan -generate-config-out=adv_cluster.tf`. This should generate a `adv_cluster.tf` file.
EspenAlbert marked this conversation as resolved.
Show resolved Hide resolved
4. Run `terraform apply`. You should see the resource imported: `Apply complete! Resources: 1 imported, 0 added, 0 changed, 0 destroyed.`
5. Remove the "default" fields. Many fields of this resource are optional. Look for fields with a `null` or `0` value or blocks you didn't specify before. Required fields have been outlined in the below example resource block:
``` terraform
resource "mongodbatlas_advanced_cluster" "this" {
cluster_type = "REPLICASET"
name = "clusterName"
project_id = "664619d870c247237f4b86a6"
replication_specs {
zone_name = "Zone 1"
region_configs {
priority = 7
provider_name = "AWS"
region_name = "EU_WEST_1"
analytics_specs {
instance_size = "M10"
node_count = 0
}
electable_specs {
instance_size = "M10"
node_count = 3
}
}
}
}
```
6. Re-use existing [Terraform expressions](https://developer.hashicorp.com/terraform/language/expressions). All fields in the generated configuration have static values. Look in your previous configuration for:
- variables, for example: `var.project_id`
- Terraform keywords, for example: `for_each`, `count`, and `depends_on`
7. Re-run `terraform apply` to ensure you have no planned changes: `No changes. Your infrastructure matches the configuration.`
8. Update the references from your previous cluster resource: `mongodbatlas_flex_cluster.this.X` to the new `mongodbatlas_advanced_cluster.this.X`.
9. Update any data source blocks to refer to `mongodbatlas_advanced_cluster`.
10. Replace your existing clusters with the ones from `adv_cluster.tf` and run `terraform state rm mongodbatlas_flex_cluster.this`. Without this step, Terraform creates a plan to delete your existing cluster.
11. Remove the import block created in step 2.
12. Re-run `terraform apply` to ensure you have no planned changes: `No changes. Your infrastructure matches the configuration.`
97 changes: 97 additions & 0 deletions docs/resources/flex_cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Resource: mongodbatlas_flex_cluster

`mongodbatlas_flex_cluster` provides a Flex Cluster resource. The resource lets you create, update, delete and import a flex cluster.

## Example Usages

```terraform
resource "mongodbatlas_flex_cluster" "example-cluster" {
project_id = var.project_id
name = var.cluster_name
provider_settings = {
backing_provider_name = "AWS"
region_name = "US_EAST_1"
}
termination_protection_enabled = true
}

data "mongodbatlas_flex_cluster" "example-cluster" {
project_id = var.project_id
name = mongodbatlas_flex_cluster.example-cluster.name
}

data "mongodbatlas_flex_clusters" "example-clusters" {
project_id = var.project_id
}

output "mongodbatlas_flex_cluster" {
value = data.mongodbatlas_flex_cluster.example-cluster.name
}

output "mongodbatlas_flex_clusters_names" {
value = [for cluster in data.mongodbatlas_flex_clusters.example-clusters.results : cluster.name]
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) Human-readable label that identifies the instance.
- `project_id` (String) Unique 24-hexadecimal character string that identifies the project.
- `provider_settings` (Attributes) Group of cloud provider settings that configure the provisioned MongoDB flex cluster. (see [below for nested schema](#nestedatt--provider_settings))

### Optional

- `tags` (Map of String) Map that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the instance.
- `termination_protection_enabled` (Boolean) Flag that indicates whether termination protection is enabled on the cluster. If set to `true`, MongoDB Cloud won't delete the cluster. If set to `false`, MongoDB Cloud will delete the cluster.

### Read-Only

- `backup_settings` (Attributes) Flex backup configuration (see [below for nested schema](#nestedatt--backup_settings))
- `cluster_type` (String) Flex cluster topology.
Copy link
Collaborator

@EspenAlbert EspenAlbert Nov 7, 2024

Choose a reason for hiding this comment

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

Do we have any more details about cluster_type?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is what was generated from the API.

- `connection_strings` (Attributes) Collection of Uniform Resource Locators that point to the MongoDB database. (see [below for nested schema](#nestedatt--connection_strings))
- `create_date` (String) Date and time when MongoDB Cloud created this instance. This parameter expresses its value in ISO 8601 format in UTC.
- `id` (String) Unique 24-hexadecimal digit string that identifies the instance.
- `mongo_db_version` (String) Version of MongoDB that the instance runs.
- `state_name` (String) Human-readable label that indicates the current operating condition of this instance.
- `version_release_system` (String) Method by which the cluster maintains the MongoDB versions.

<a id="nestedatt--provider_settings"></a>
### Nested Schema for `provider_settings`

Required:

- `backing_provider_name` (String) Cloud service provider on which MongoDB Cloud provisioned the flex cluster.
- `region_name` (String) Human-readable label that identifies the geographic location of your MongoDB flex cluster. The region you choose can affect network latency for clients accessing your databases. For a complete list of region names, see [AWS](https://docs.atlas.mongodb.com/reference/amazon-aws/#std-label-amazon-aws), [GCP](https://docs.atlas.mongodb.com/reference/google-gcp/), and [Azure](https://docs.atlas.mongodb.com/reference/microsoft-azure/).

Read-Only:

- `disk_size_gb` (Number) Storage capacity available to the flex cluster expressed in gigabytes.
- `provider_name` (String) Human-readable label that identifies the cloud service provider.


<a id="nestedatt--backup_settings"></a>
### Nested Schema for `backup_settings`

Read-Only:

- `enabled` (Boolean) Flag that indicates whether backups are performed for this flex cluster. Backup uses [TODO](TODO) for flex clusters.


<a id="nestedatt--connection_strings"></a>
### Nested Schema for `connection_strings`

Read-Only:

- `standard` (String) Public connection string that you can use to connect to this cluster. This connection string uses the mongodb:// protocol.
- `standard_srv` (String) Public connection string that you can use to connect to this flex cluster. This connection string uses the `mongodb+srv://` protocol.

# Import
You can import the Flex Cluster resource by using the Project ID and Flex Cluster name, in the format `PROJECT_ID-FLEX_CLUSTER_NAME`. For example:
```
$ terraform import mongodbatlas_flex_cluster.test 6117ac2fe2a3d04ed27a987v-yourFlexClusterName
```

For more information see: [MongoDB Atlas API - Flex Cluster](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Flex-Clusters/operation/createFlexcluster) Documentation.
8 changes: 8 additions & 0 deletions examples/mongodbatlas_flex_cluster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# MongoDB Atlas Provider -- Atlas Flex Cluster
This example creates one flex cluster in a project.

Variables Required to be set:
- `public_key`: Atlas public key
- `private_key`: Atlas private key
- `project_id`: Project ID where flex cluster will be created
- `cluster_name`: Name of flex cluster that will be created
26 changes: 26 additions & 0 deletions examples/mongodbatlas_flex_cluster/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "mongodbatlas_flex_cluster" "example-cluster" {
project_id = var.project_id
name = var.cluster_name
provider_settings = {
backing_provider_name = "AWS"
region_name = "US_EAST_1"
}
termination_protection_enabled = true
}

data "mongodbatlas_flex_cluster" "example-cluster" {
project_id = var.project_id
name = mongodbatlas_flex_cluster.example-cluster.name
}

data "mongodbatlas_flex_clusters" "example-clusters" {
project_id = var.project_id
}

output "mongodbatlas_flex_cluster" {
value = data.mongodbatlas_flex_cluster.example-cluster.name
}

output "mongodbatlas_flex_clusters_names" {
value = [for cluster in data.mongodbatlas_flex_clusters.example-clusters.results : cluster.name]
}
4 changes: 4 additions & 0 deletions examples/mongodbatlas_flex_cluster/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider "mongodbatlas" {
public_key = var.public_key
private_key = var.private_key
}
Loading