diff --git a/docs/guides/advanced-cluster-new-sharding-schema.md b/docs/guides/advanced-cluster-new-sharding-schema.md index 3d2d5e3f03..4b5a2bc7ec 100644 --- a/docs/guides/advanced-cluster-new-sharding-schema.md +++ b/docs/guides/advanced-cluster-new-sharding-schema.md @@ -1,28 +1,32 @@ --- -page_title: "Migration Guide: Advanced Cluster New Sharding Configurations" +page_title: "Guide: Advanced Cluster New Sharding Configurations" --- -# Migration Guide: Advanced Cluster New Sharding Configurations -**Objective**: Use this guide to migrate your existing `mongodbatlas_advanced_cluster` resources that may be using the legacy sharding schema _(i.e. using `num_shards` which was deprecated in v1.18.0 and removed in 2.0.0)_ to support the new sharding configurations instead. The new sharding configurations allow you to scale shards independently. Additionally, compute auto-scaling supports scaling instance sizes independently for each shard when using the new sharding configuration. +**Objective**: This guide explains the new sharding configuration for `mongodbatlas_advanced_cluster` that allows you to scale shards independently, hence, you may also come across the term "Independent shard scaling configuration" in our documentation. +Additionally, compute auto-scaling supports scaling instance sizes independently for each shard when using the new sharding configuration. -Note: Once applied, the `mongodbatlas_advanced_cluster` resource making use of the new sharding configuration will not be able to transition back to the old sharding configuration. +**You may find this guide useful if:** +- You are considering upgrading from v1.x of our provider to v2.0.0 or later which ONLY supports this new configuration. +- You currently use the legacy sharding schema (i.e. using `num_shards` which was deprecated in v1.18.0 and removed in 2.0.0). +- You want to understand the new sharding configuration and how a `replication_specs` element now represents each shard individually, allowing you to scale or modify each shard independently. +- You are considering upgrading to a sharded cluster and you want to understand the new sharding configuration. -- [Prerequisites](#prerequisites) -- [Migration Guide: Advanced Cluster New Sharding Configurations](#migration-guide-advanced-cluster-new-sharding-schema) - - [Changes Overview](#changes-overview) + +If you are still using the deprecated `mongodbatlas_cluster` resource, use [Migration Guide: Cluster → Advanced Cluster instead](./cluster-to-advanced-cluster-migration-guide.md). + +If you are already using `mongodbatlas_advanced_cluster` and want to upgrade to our Terraform Provider v2.0.0 or later from v1.x, also review [Migration Guide: Moving to Advanced Cluster v2.0.0](./migrate-to-advanced-cluster-2.0.md) +--- + +- [Changes Overview](#changes-overview) - [Migrate advanced\_cluster type `SHARDED`](#migrate-advanced_cluster-type-sharded) - [Migrate advanced\_cluster type `GEOSHARDED`](#migrate-advanced_cluster-type-geosharded) - - [Migrate advanced\_cluster type `REPLICASET`](#migrate-advanced_cluster-type-replicaset) + - [Upgrade type `REPLICASET` to `SHARDED`](#migrate-advanced_cluster-type-replicaset) - [Use Independent Shard Scaling](#use-independent-shard-scaling) - [Use Auto-Scaling Per Shard](#use-auto-scaling-per-shard) - [Resources and Data Sources Impacted by Independent Shard Scaling](#resources-and-data-sources-impacted-by-independent-shard-scaling) - [Data Source Transition for Asymmetric Clusters](#data-source-transition-for-asymmetric-clusters) -## Prerequisites -- Upgrade to MongoDB Atlas Terraform Provider 2.0.0 or later -- Ensure `mongodbatlas_advanced_cluster` resources configuration is updated to use the latest syntax changes as per **Step 1 & 2** of [Migration Guide: Advanced Cluster (v1.x → v2.0.0)](migrate-to-advanced-cluster-2.0.md#how-to-migrate). **Note:** Syntax changes in [Migration Guide: Advanced Cluster (v1.x → v2.0.0)](migrate-to-advanced-cluster-2.0.md#how-to-migrate) and the changes in this guide should be applied together in one go **once the plan is empty** i.e. you should not make these updates separately. - ## Changes Overview @@ -189,7 +193,7 @@ resource "mongodbatlas_advanced_cluster" "test" { } ``` -### Migrate advanced_cluster type `REPLICASET` +### Upgrade type `REPLICASET` to `SHARDED` To learn more, see the documentation on [transitioning from a replica set to a sharded cluster](https://www.mongodb.com/docs/atlas/scale-cluster/#scale-your-replica-set-to-a-sharded-cluster). @@ -424,6 +428,7 @@ While the example initially defines 2 symmetric shards, auto-scaling of `electab -> **NOTE:** See the table [below](#resources-and-data-sources-impacted-by-independent-shard-scaling) for other impacted resources when a cluster transitions to independently scaled shards. + ## Resources and Data Sources Impacted by Independent Shard Scaling Name | Changes | Transition Guide diff --git a/docs/guides/cluster-to-advanced-cluster-migration-guide.md b/docs/guides/cluster-to-advanced-cluster-migration-guide.md index fd0f8cee95..e702d92d20 100644 --- a/docs/guides/cluster-to-advanced-cluster-migration-guide.md +++ b/docs/guides/cluster-to-advanced-cluster-migration-guide.md @@ -4,7 +4,9 @@ page_title: "Migration Guide: Cluster to Advanced Cluster" # Migration Guide: Cluster to Advanced Cluster -**Objective**: This guide explains how to replace the deprecated `mongodbatlas_cluster` resource with the `mongodbatlas_advanced_cluster` resource. For data source migrations, refer to the [output changes](#output-changes) section. If you're transitioning to independent sharding, additional guidance is available in the [Advanced Cluster New Sharding Configurations Migration Guide](advanced-cluster-new-sharding-schema#data-source-transition-for-asymmetric-clusters). +**Objective**: This guide explains how to replace the deprecated `mongodbatlas_cluster` resource with the `mongodbatlas_advanced_cluster` resource. For data source migrations, refer to the [output changes](#output-changes) section. +Also review [Advanced Cluster New Sharding Configurations Migration Guide](advanced-cluster-new-sharding-schema#data-source-transition-for-asymmetric-clusters) for guidance on the new sharding model that allows you to scale shards independently. + ## Why do we have both `mongodbatlas_cluster` and `mongodbatlas_advanced_cluster` resources? diff --git a/docs/guides/migrate-to-advanced-cluster-2.0.md b/docs/guides/migrate-to-advanced-cluster-2.0.md index 27f0fc564e..e6af2ab376 100644 --- a/docs/guides/migrate-to-advanced-cluster-2.0.md +++ b/docs/guides/migrate-to-advanced-cluster-2.0.md @@ -1,19 +1,39 @@ --- -page_title: "Migration Guide: Advanced Cluster (v1.x → v2.0.0)" +page_title: "Migration Guide: Moving to Advanced Cluster v2.0.0" --- -# Migration Guide: Advanced Cluster (v1.x → v2.0.0) +**Objective**: This guide is for users who are currently using `mongodbatlas_advanced_cluster` and want to upgrade to our Terraform Provider v2.0.0 or later from v1.x. -This guide helps you migrate from the legacy schema of `mongodbatlas_advanced_cluster` resource to the new schema introduced in v2.0.0 of the provider. The new implementation uses: - -1. The recommended Terraform Plugin Framework, which, in addition to providing a better user experience and other features, adds support for the `moved` block between different resource types. -2. New sharding configurations that supports scaling shards independently (see the [Migration Guide: Advanced Cluster New Sharding Configurations](advanced-cluster-new-sharding-schema#migration-sharded)). -~> **IMPORTANT:** Preview of the new schema was already released in versions 1.29.0 and later which could be enabled by setting the environment variable `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true`. If you are already using the new schema preview with the new sharding configurations **and not using deprecated attributes**, you would not be required to make any additional changes except that the mentioned environment variable is no longer required. +### How to use this guide? +1. [Identify your current setup](#identify-your-current-setup) using the table below. +2. Review the [Overview of configuration changes when upgrading from 1.x](#overview-of-configuration-changes-when-upgrading-from-1x) to understand what changes have been made to `mongodbatlas_advanced_cluster` in provider v2.0.0. +3. Review [Important Considerations](#important-considerations) before you start updating your configurations. +4. Follow the instructions based on your current setup from #1 above. + + + +## Identify your current setup + +| Case             | You are currently using `mongodbatlas_advanced_cluster`.. | What this means | +|------|--------------------------|-----------------| +|   |   |   | +| [1(a)](#case-1a-currently-using-mongodbatlas_advanced_cluster-with-num_shards--older-blocks-syntax) | ..with `num_shards` | You are using the [older blocks syntax](#attribute-vs-block-syntax) and legacy sharding configuration. | +|   |   |   | +| [1(b)](#case-1b-currently-using-mongodbatlas_advanced_cluster-without-num_shards--one-replication_specs-per-shard--older-blocks-syntax) | ..without `num_shards` and one `replication_specs` per shard | You are using the [older blocks syntax](#attribute-vs-block-syntax) and the [**new** independent shard scaling](./advanced-cluster-new-sharding-schema.md) configuration. | +|   |   |   | +| [2(a)](#case-2a-currently-using-mongodbatlas_advanced_cluster-preview-for-v200-using-environment-flag-with-num_shards) | ..[**preview for v2.0.0**](https://registry.terraform.io/providers/mongodb/mongodbatlas/1.41.1/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529) (using environment flag) with `num_shards` | You are using the [new attributes syntax](#attribute-vs-block-syntax) and legacy sharding configuration. | +|   |   |   | +| [2(b)](#case-2b-currently-using-mongodbatlas_advanced_cluster-preview-for-v200-using-environment-flag-without-num_shards) | ..[**preview for v2.0.0**](https://registry.terraform.io/providers/mongodb/mongodbatlas/1.41.1/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529) (using environment flag) without `num_shards` and one `replication_specs` per shard | You are using the [new attributes syntax](#attribute-vs-block-syntax) and the [**new** independent shard scaling](./advanced-cluster-new-sharding-schema.md) configuration. | +|   |   |   | + -## Configuration changes when upgrading from v1.x -In this section you can find the configuration changes between the legacy `mongodbatlas_advanced_cluster` and the new one released in v2.0.0. +If you are still using the deprecated `mongodbatlas_cluster` resource, use [Migration Guide: Cluster → Advanced Cluster instead](./cluster-to-advanced-cluster-migration-guide.md). + + + +## Overview of configuration changes when upgrading from 1.x 1. Below deprecated attributes have been removed: - `id` @@ -22,158 +42,1291 @@ In this section you can find the configuration changes between the legacy `mongo - `replication_specs.#.id` - `advanced_configuration.default_read_concern` - `advanced_configuration.fail_index_key_too_long` + +2. `mongodbatlas_advanced_cluster` now supports **only** the new sharding configuration that allows scaling shards independently. To learn more about independent shard configuration, please review [Advanced Cluster New Sharding Configurations](./advanced-cluster-new-sharding-schema.md) + +3. Elements `replication_specs` and `region_configs` are now [list attributes instead of blocks](#attribute-vs-block-syntax) so they are an array of objects. -2. Elements `replication_specs` and `region_configs` are now list attributes instead of blocks so they are an array of objects. If there is only one object, it still needs to be in an array. For example, +4. Elements `connection_strings`, `timeouts`, `advanced_configuration`, `bi_connector_config`, `pinned_fcv`, `electable_specs`, `read_only_specs`, `analytics_specs`, `auto_scaling` and `analytics_auto_scaling` are now single [attributes instead of blocks](#attribute-vs-block-syntax) so they are an object. If there are references to them, the index such as`[0]` or `.0` are dropped. + + +5. Elements `tags` and `labels` are now `maps` instead of `blocks`. For example, ```terraform -replication_specs { - region_configs { - electable_specs { - instance_size = "M10" - node_count = 1 +tags { + key = "env" + value = "dev" +} +tags { + key = "tag 2" + value = "val" +} +tags { + key = var.tag_key + value = "another_val" +} + +``` +becomes: +```terraform +tags = { + env = "dev" # key strings without blanks can be enclosed in quotes but not required + "tag 2" = "val" # enclose key strings with blanks in quotes + (var.tag_key) = "another_val" # enclose key expressions in brackets so they can be evaluated +} +``` + +6. `id` attribute which was an internal encoded resource identifier has been removed. Use `cluster_id` instead. + + +### Configuration changes when upgrading `data.mongodbatlas_advanced_cluster` and `data.mongodbatlas_advanced_clusters` from v1.x + +1. Below deprecated attributes have been removed (same as resource): + - `id` + - `disk_size_gb` + - `replication_specs.#.num_shards` + - `replication_specs.#.id` + - `advanced_configuration.default_read_concern` + - `advanced_configuration.fail_index_key_too_long` + +2. Deprecated attribute `use_replication_spec_per_shard` has been removed. The data sources will now return only the new sharding configuration of the clusters. + +3. `id` attribute which was an internal encoded resource identifier has been removed. Use `cluster_id` instead. + + +## Important Considerations +1. Before you migrate, create a backup of your [Terraform state file](https://developer.hashicorp.com/terraform/cli/commands/state). The state file will update to the new format and the old format will no longer be supported. +2. For nested attributes that have been removed, such as `replication_specs.#.num_shards` etc, Terraform may NOT throw an explicit error even if these attributes are left in the configuration. This is a [known Terraform issue](https://github.com/hashicorp/terraform-plugin-framework/issues/1210). Users should ensure to remove any such attributes from the configuration to avoid any confusion. +3. For any of the migration paths mentioned in this document, do NOT apply until the plan is empty. If it shows other changes, you must update the `mongodbatlas_advanced_cluster` configuration until it matches the original configuration. +4. Please refer to our [Considerations and Best Practices](../resources/advanced_cluster.md#considerations-and-best-practices) section for additional guidance on this resource. + + + + +## Case 1(a): Currently using `mongodbatlas_advanced_cluster` with `num_shards` & older blocks syntax + +After you upgrade to v2.0.0+ from v1.x.x, when you run `terraform plan`, you may run into syntax errors such as `Required attribute "replication_specs" not specified` or `Unexpected block: Blocks of type "advanced_configuration" are not expected here`. **This is expected** since the resource definition hasn't been updated yet using the latest schema. +At this point, you need to update the configuration by following all of below steps at once and finally running terraform apply: + +- **Step #1:** Apply **all** configuration [changes mentioned here](#overview-of-configuration-changes-when-upgrading-from-1x) **until there are no errors and no planned changes**. +This may include: + - Adjust syntax of [blocks to attributes](#attribute-vs-block-syntax). + - Remove `num_shards` and restructure `replication_specs` list to represent one element per shard instead. This ensures you use the new sharding configuration with independent scaling going forward. To learn more, please review [Advanced Cluster New Sharding Configurations](./advanced-cluster-new-sharding-schema.md). + - Remove references to deprecated attributes mentioned [in this section](#overview-of-configuration-changes-when-upgrading-from-1x). + +**Recommended:** Use the [Atlas CLI plugin](https://github.com/mongodb-labs/atlas-cli-plugin-terraform?tab=readme-ov-file#2-advancedclustertov2-adv2v2) to generate the `mongodbatlas_advanced_cluster` resource definition as it will generate a clean configuration while keeping the original Terraform expressions. Please ensure to review [plugin limitations](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/blob/main/docs/command_adv2v2.md#limitations). + +- **Step #2:** Ensure all deprecated attributes (and their references) mentioned [above](#overview-of-configuration-changes-when-upgrading-from-1x) are removed. + +- **Step #3:** Even though there are no plan changes shown at this point, run `terraform apply`. This will update the `mongodbatlas_advanced_cluster` state to support the new schema. + +### Example for migrating a `SHARDED` cluster using `num_shards` (see [complete example](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/master/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/README.md)): +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "SHARDED" + ... + disk_size_gb = 10 # remove this and set per shard for inner specs + + replication_specs { # update syntax to a list attribute of objects instead of blocks + num_shards = 2 # remove this & add another replication_spec element for the second shard + + region_configs { # update syntax to a list attribute of objects instead of blocks + electable_specs { # update syntax to an attribute instead of a block + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" } - provider_name = "AWS" - priority = 7 - region_name = "US_WEST_1" + zone_name = "zone n1" } - region_configs { - electable_specs { - instance_size = "M10" - node_count = 2 - } - provider_name = "AWS" - priority = 6 - region_name = "US_EAST_1" + advanced_configuration { # update syntax to an attribute instead of a block + oplog_size_mb = 999 + sample_refresh_interval_bi_connector = 300 + } + + tags { # update syntax for tags and labels to maps instead of blocks in v2.0.0+ + key = "environment" + value = "dev" } } ``` -goes to: +- After: ```terraform -replication_specs = [ - { - region_configs = [ - { - electable_specs = { - instance_size = "M10" - node_count = 1 +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "SHARDED" + ... + + replication_specs = [{ # notice the list of objects and the "=" sign + region_configs = [{ + electable_specs = { # notice the "=" sign + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + disk_size_gb = 10 # this is now set at spec level + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + }] + }, + { + region_configs = [{ + electable_specs = { + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + disk_size_gb = 10 # this is now set at spec level } provider_name = "AWS" priority = 7 - region_name = "US_WEST_1" - }, - { - electable_specs = { - instance_size = "M10" - node_count = 2 + region_name = "EU_WEST_1" + }] + }] + + advanced_configuration = { # notice the "=" sign + oplog_size_mb = 999 + sample_refresh_interval_bi_connector = 300 + } + + tags = { # notice the "=" sign and map syntax + environment = "dev" + } +} +``` + + +### Example for migrating a `REPLICASET` cluster using `num_shards = 1` (see [complete example](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/master/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/README.md)): +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "REPLICASET" + ... + + replication_specs { # update syntax to a list attribute of objects instead of blocks + num_shards = 1 # remove this + + region_configs { # update syntax to a list attribute of objects instead of blocks + electable_specs { # update syntax to an attribute instead of a block + instance_size = var.provider_instance_size_name + node_count = 3 + } + provider_name = var.provider_name + region_name = "US_EAST_1" + priority = 7 + } + } + + tags { # update syntax for tags and labels to maps instead of blocks in v2.0.0+ + key = "environment" + value = "dev" + } +} +``` + +- After: +```terraform +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "REPLICASET" + + replication_specs = [ # notice the list of objects and the "=" sign + { + region_configs = [ + { + electable_specs = { # notice the "=" sign + instance_size = var.provider_instance_size_name + node_count = 3 + } + provider_name = var.provider_name + region_name = "US_EAST_1" + priority = 7 } - provider_name = "AWS" - priority = 6 - region_name = "US_EAST_1" + ] + } + ] + + tags = { # notice the "=" sign and map syntax + environment = "dev" + } +} +``` + +### Example for migrating a `GEOSHARDED` cluster using `num_shards`: +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "test" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "GEOSHARDED" + disk_size_gb = 15 # remove this and set per shard for inner specs + + replication_specs { # update syntax to a list attribute of objects instead of blocks + num_shards = 2 # remove this & add another replication_spec element for the second shard + region_configs { # update syntax to a list attribute of objects instead of blocks + electable_specs { # update syntax to an attribute instead of a block + instance_size = "M10" + node_count = 3 + } + analytics_specs { # update syntax to an attribute instead of a block + instance_size = "M10" + node_count = 1 + } + provider_name = "AWS" + priority = 7 + region_name = "US_EAST_1" + } + zone_name = "zone 1" + } + + replication_specs { + num_shards = 2 # remove this & add another replication_spec element for the second shard + region_configs { + electable_specs { + instance_size = "M10" + node_count = 3 + } + analytics_specs { + instance_size = "M10" + node_count = 1 } - ] + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + zone_name = "zone 2" } -] +} ``` -3. `mongodbatlas_advanced_cluster` now supports only the new sharding configuration that allows scaling shards independently. If your configuration defines the num_shards attribute (removed in 2.0.0), please also see the [Migration Guide: Advanced Cluster New Sharding Configurations](advanced-cluster-new-sharding-schema#migration-sharded). +- After: +```terraform +resource "mongodbatlas_advanced_cluster" "test" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "GEOSHARDED" -4. Elements `connection_strings`, `timeouts`, `advanced_configuration`, `bi_connector_config`, `pinned_fcv`, `electable_specs`, `read_only_specs`, `analytics_specs`, `auto_scaling` and `analytics_auto_scaling` are now single attributes instead of blocks so they are an object. For example, -```terraform -advanced_configuration { - default_write_concern = "majority" - javascript_enabled = true -} + replication_specs = [{ # notice the list of objects and the "=" sign + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + zone_name = "zone 2" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + zone_name = "zone 2" + }] +} ``` -goes to: + + +## Case 1(b): Currently using `mongodbatlas_advanced_cluster` without `num_shards`, one `replication_specs` per shard & older blocks syntax + +After you upgrade to v2.0.0+ from v1.x.x, when you run `terraform plan`, you may run into syntax errors such as `Required attribute "replication_specs" not specified` or `Unexpected block: Blocks of type "advanced_configuration" are not expected here`. **This is expected** since the resource definition hasn't been updated yet using the latest schema. +At this point, you need to update the configuration by following all of below steps **at once** and finally running `terraform apply`: + +- **Step #1:** Apply **all** configuration [changes mentioned here except #2](#overview-of-configuration-changes-when-upgrading-from-1x) since you are already using the new sharding configuration, **until there are no errors and no planned changes**. This may include: + - Adjust syntax of [blocks to attributes](#attribute-vs-block-syntax). + - Remove references to deprecated attributes mentioned [in this section](#overview-of-configuration-changes-when-upgrading-from-1x). + +**Recommended:** Use the [Atlas CLI plugin](https://github.com/mongodb-labs/atlas-cli-plugin-terraform?tab=readme-ov-file#2-advancedclustertov2-adv2v2) to generate the `mongodbatlas_advanced_cluster` resource definition as it will generate a clean configuration while keeping the original Terraform expressions. Please ensure to review [plugin limitations](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/blob/main/docs/command_adv2v2.md#limitations). + +- **Step #2:** Ensure all deprecated attributes (and their references) mentioned [above](#overview-of-configuration-changes-when-upgrading-from-1x) are removed. + +- **Step #3:** Even though there are no plan changes shown at this point, run `terraform apply`. This will update the `mongodbatlas_advanced_cluster` state to support the new schema. + +### Example for migrating a `SHARDED` cluster using new sharding configuration (see [complete example](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/master/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/main.tf)): +- Before: ```terraform -advanced_configuration = { - default_write_concern = "majority" - javascript_enabled = true -} +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "SHARDED" + ... + disk_size_gb = 10 # remove this and set per shard for inner specs + + replication_specs { # shard 1 - M30 instance size + region_configs { # update syntax to a list attribute of objects instead of blocks + electable_specs { # update syntax to an attribute + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + } + + replication_specs { # shard 2 - M40 instance size + region_configs { + electable_specs { + instance_size = "M40" + disk_iops = 3000 + node_count = 3 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + } + + advanced_configuration { # update syntax to an attribute instead of a block + oplog_size_mb = 999 + sample_refresh_interval_bi_connector = 300 + } + + tags { # update syntax for tags and labels to maps instead of blocks in v2.0.0+ + key = "environment" + value = "dev" + } +} ``` -If there are references to them, `[0]` or `.0` are dropped. For example, + +- After: ```terraform -output "standard" { - value = mongodbatlas_advanced_cluster.cluster.connection_strings[0].standard +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "SHARDED" + ... + + replication_specs = [ # notice the list of objects and the "=" sign + { # shard 1 - M30 instance size + region_configs = [ + { + electable_specs = { # notice the "=" sign + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + disk_size_gb = 10 # this is now set at spec level + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + ] + }, + { # shard 2 - M40 instance size + region_configs = [ + { + electable_specs = { + instance_size = "M40" + disk_iops = 3000 + node_count = 3 + disk_size_gb = 10 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + ] + } + ] + + advanced_configuration = { # notice the "=" sign + oplog_size_mb = 999 + sample_refresh_interval_bi_connector = 300 + } + + tags = { # notice the "=" sign and map syntax + environment = "dev" + } } -output "javascript_enabled" { - value = mongodbatlas_advanced_cluster.cluster.advanced_configuration.0.javascript_enabled +``` + +### Example for migrating a `GEOSHARDED` cluster using new sharding configuration: +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "GEOSHARDED" + + replication_specs { # update syntax to a list attribute of objects instead of blocks + region_configs { # update syntax to a list attribute of objects instead of blocks + electable_specs { # update syntax to an attribute instead of a block + instance_size = "M10" + node_count = 3 + } + analytics_specs { # update syntax to an attribute instead of a block + instance_size = "M10" + node_count = 1 + } + provider_name = "AWS" + priority = 7 + region_name = "US_EAST_1" + } + zone_name = "zone 1" + } + + replication_specs { # update syntax to a list attribute of objects instead of blocks + region_configs { # update syntax to a list attribute of objects instead of blocks + electable_specs { # update syntax to an attribute instead of a block + instance_size = "M10" + node_count = 3 + } + analytics_specs { # update syntax to an attribute instead of a block + instance_size = "M10" + node_count = 1 + } + provider_name = "AWS" + priority = 7 + region_name = "US_EAST_1" + } + zone_name = "zone 1" + } + + replication_specs { + region_configs { + electable_specs { + instance_size = "M10" + node_count = 3 + } + analytics_specs { + instance_size = "M10" + node_count = 1 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + zone_name = "zone 2" + } + + replication_specs { + region_configs { + electable_specs { + instance_size = "M10" + node_count = 3 + } + analytics_specs { + instance_size = "M10" + node_count = 1 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + zone_name = "zone 2" + } } ``` -goes to: + +- After: ```terraform -output "standard" { - value = mongodbatlas_advanced_cluster.cluster.connection_strings.standard +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "GEOSHARDED" + + replication_specs = [{ # notice the list of objects and the "=" sign + region_configs = [{ + analytics_specs = { # notice the "=" sign + instance_size = "M10" + node_count = 1 + } + electable_specs = { # notice the "=" sign + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }, { + region_configs = [{ # notice the list of objects and the "=" sign + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + zone_name = "zone 2" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + zone_name = "zone 2" + }] } -output "javascript_enabled" { - value = mongodbatlas_advanced_cluster.cluster.advanced_configuration.javascript_enabled +``` + +### Example for migrating a `REPLICASET` cluster: +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "REPLICASET" + retain_backups_enabled = "true" + disk_size_gb = 60 + + replication_specs { + region_configs { + electable_specs { + instance_size = "M10" + node_count = 3 + } + analytics_specs { + instance_size = "M10" + node_count = 1 + } + provider_name = "AWS" + priority = 7 + region_name = "US_WEST_2" + } + } } ``` -5. Elements `tags` and `labels` are now `maps` instead of `blocks`. For example, +- After: ```terraform -tags { - key = "env" - value = "dev" +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "REPLICASET" + retain_backups_enabled = "true" + + replication_specs = [{ # notice the list of objects and the "=" sign + region_configs = [{ + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 60 # this is now set at spec level + } + analytics_specs = { # notice the "=" sign + instance_size = "M10" + node_count = 1 + disk_size_gb = 60 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "US_WEST_2" + }] + }] } -tags { - key = "tag 2" - value = "val" +``` + +## Case 2(a): Currently using `mongodbatlas_advanced_cluster` **preview** for v2.0.0 (using environment flag) with `num_shards` + +In this case, after you upgrade to v2.0.0+ from v1.x.x and run `terraform plan`, you should not run into any errors **unless you are using any of the deprecated attributes** mentioned [here](#overview-of-configuration-changes-when-upgrading-from-1x) as your configuration is already using the [new attribute](#attribute-vs-block-syntax) syntax. +You may encounter unexpected plan changes as you may have `num_shards` > 1. To address this, you need to remove `num_shards` and restructure the `replication_specs` list as mentioned in below steps. +Additionally, remove references of the other attributes that have been removed in v2.0.0. + +- **Step #1:** Remove the `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER` environment variable, as it is no longer required. + +- **Step #2:** Apply relevant configuration [changes mentioned here](#overview-of-configuration-changes-when-upgrading-from-1x) **until there are no errors and no planned changes**. +This may include: + - Remove `num_shards` and restructure `replication_specs` list to represent one element per shard. This ensures you use the new sharding configuration with independent scaling going forward. To learn more, please review [Advanced Cluster New Sharding Configurations](./advanced-cluster-new-sharding-schema.md). + - Remove references to deprecated attributes mentioned [in this section](#overview-of-configuration-changes-when-upgrading-from-1x). + +**Recommended:** Use the [Atlas CLI plugin](https://github.com/mongodb-labs/atlas-cli-plugin-terraform?tab=readme-ov-file#2-advancedclustertov2-adv2v2) to generate the `mongodbatlas_advanced_cluster` resource definition as it will generate a clean configuration while keeping the original Terraform expressions. Please ensure to review [plugin limitations](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/blob/main/docs/command_adv2v2.md#limitations). + +- **Step #3:** Ensure all deprecated attributes (and their references) mentioned [above](#overview-of-configuration-changes-when-upgrading-from-1x) are removed. + +- **Step #4:** Even though there are no plan changes shown at this point, run `terraform apply`. This will update the `mongodbatlas_advanced_cluster` state to support the new schema. + +### Example for migrating a `SHARDED` cluster using `num_shards` & legacy sharding configuration: +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "SHARDED" + disk_size_gb = 15 # remove this and set per shard for inner specs + + replication_specs = [{ + num_shards = 2 # remove this & add another replication_spec element for the second shard + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + auto_scaling = { + compute_enabled = true + compute_max_instance_size = "M20" + disk_gb_enabled = true + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + }] } -tags { - key = var.tag_key - value = "another_val" +``` + +- After: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "SHARDED" + + replication_specs = [{ + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 + } + auto_scaling = { + compute_enabled = true + compute_max_instance_size = "M20" + disk_gb_enabled = true + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 + } + auto_scaling = { + compute_enabled = true + compute_max_instance_size = "M20" + disk_gb_enabled = true + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + }] } +``` + +### Example for migrating a `GEOSHARDED` cluster using `num_shards` & legacy sharding configuration: +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "GEOSHARDED" + disk_size_gb = 15 # remove this and set per shard for inner specs + replication_specs = [{ + num_shards = 2 # remove this & add another replication_spec element for the second shard + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }] +} ``` -goes to: + +- After: ```terraform -tags = { - env = "dev" # key strings without blanks can be enclosed in quotes but not required - "tag 2" = "val" # enclose key strings with blanks in quotes - (var.tag_key) = "another_val" # enclose key expressions in brackets so they can be evaluated +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "GEOSHARDED" + + replication_specs = [{ + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }] } ``` -6. `id` attribute which was an internal encoded resource identifier has been removed. Use `cluster_id` instead. +### Example for migrating a `REPLICASET` cluster using `num_shards`: +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "REPLICASET" + retain_backups_enabled = "true" + disk_size_gb = 60 # remove this and set per shard for inner specs -### Configuration changes when upgrading `data.mongodbatlas_advanced_cluster` and `data.mongodbatlas_advanced_clusters` from v1.x + replication_specs = [{ + num_shards = 1 # remove this + region_configs = [{ + electable_specs = { + instance_size = "M10" + node_count = 3 + } + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + priority = 7 + provider_name = "AWS" + region_name = "US_WEST_2" + }] + }] +} +``` -1. Below deprecated attributes have been removed (same as resource): - - `id` - - `disk_size_gb` - - `replication_specs.#.num_shards` - - `replication_specs.#.id` - - `advanced_configuration.default_read_concern` - - `advanced_configuration.fail_index_key_too_long` +- After: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "REPLICASET" + retain_backups_enabled = "true" -2. Deprecated attribute `use_replication_spec_per_shard` has been removed. The data sources will now return only the new sharding configuration of the clusters. + replication_specs = [{ + region_configs = [{ + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 60 # this is now set at spec level + } + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 60 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "US_WEST_2" + }] + }] +} +``` -3. `id` attribute which was an internal encoded resource identifier has been removed. Use `cluster_id` instead. +## Case 2(b): Currently using `mongodbatlas_advanced_cluster` **preview** for v2.0.0 (using environment flag) without `num_shards` + +In this case, after you upgrade to v2.0.0+ from v1.x.x and run `terraform plan`, you should not run into any errors or unexpected planned changes **unless you are using any of the deprecated attributes** mentioned [here](#overview-of-configuration-changes-when-upgrading-from-1x) as you are already using the [new attribute](#attribute-vs-block-syntax) syntax and the new sharding configuration. + +- **Step #1:** Remove the `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER` environment variable, as it is no longer required. + +- **Step #2:** Ensure all deprecated attributes (and their references) mentioned [above](#overview-of-configuration-changes-when-upgrading-from-1x) are removed. + +- **Step #3:** Even though there are no plan changes shown at this point, run `terraform apply`. This will update the `mongodbatlas_advanced_cluster` state to support the new schema. + + +### Example for migrating a `SHARDED` cluster using new sharding configuration: +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "SHARDED" + disk_size_gb = 15 # remove this and set per shard for inner specs + + replication_specs = [{ + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + }] +} +``` -## How to migrate +- After: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "SHARDED" -If you currently use `mongodbatlas_cluster`, see our [Migration Guide](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/cluster-to-advanced-cluster-migration-guide). + replication_specs = [{ + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + }] +} +``` -If you currently use `mongodbatlas_advanced_cluster` with the preview of the new schema [released in version 1.29.0](https://registry.terraform.io/providers/mongodb/mongodbatlas/1.29.0/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529) **and you are not using deprecated attributes**, you would not be required to make any additional changes except removing the `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true` environment variable, which is no longer required. +### Example for migrating a `GEOSHARDED` cluster using new sharding configuration: +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "GEOSHARDED" + disk_size_gb = 15 # remove this and set per shard for inner specs -If you currently use `mongodbatlas_advanced_cluster` from v1.x.x of our provider, we recommend that you do the following steps: + replication_specs = [{ + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + zone_name = "zone 2" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + electable_specs = { + instance_size = "M10" + node_count = 3 + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + zone_name = "zone 2" + }] +} +``` -~> **IMPORTANT:** Before you migrate, create a backup of your [Terraform state file](https://developer.hashicorp.com/terraform/cli/commands/state). The state file will update to the new format and the old format will no longer be supported. +- After: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + backup_enabled = false + cluster_type = "GEOSHARDED" -After you upgrade to v2.0.0+ from v1.x.x, when you run `terraform plan`, syntax errors will return as expected since the definition file hasn't been updated yet using the latest schema. At this point, you need to update the configuration by following all of below steps at once and finally running `terraform apply`: + replication_specs = [{ + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "US_EAST_1" + }] + zone_name = "zone 1" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + zone_name = "zone 2" + }, { + region_configs = [{ + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 15 # this is now set at spec level + } + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 15 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "EU_WEST_1" + }] + zone_name = "zone 2" + }] +} +``` -- **Step #1:** Apply definition changes [explained on this page](#configuration-changes-when-upgrading-from-v1x) until there are no errors and no planned changes. - - **[Recommended]** You can also use the [Atlas CLI plugin](https://github.com/mongodb-labs/atlas-cli-plugin-terraform?tab=readme-ov-file#2-advancedclustertov2-adv2v2) to generate the `mongodbatlas_advanced_cluster` resource definition. This is the recommended method as it will generate a clean configuration while keeping the original Terraform expressions. Please be aware of the [plugin limitations](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/blob/main/docs/command_adv2v2.md#limitations). +### Example for migrating a `REPLICASET` cluster using new sharding configuration: +- Before: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "REPLICASET" + retain_backups_enabled = "true" + disk_size_gb = 60 # remove this and set per shard for inner specs -- **Step #2:** Remove any deprecated attributes (and their references) mentioned [above](#configuration-changes-when-upgrading-from-v1x). + replication_specs = [{ + region_configs = [{ + electable_specs = { + instance_size = "M10" + node_count = 3 + } + analytics_specs = { + instance_size = "M10" + node_count = 1 + } + priority = 7 + provider_name = "AWS" + region_name = "US_WEST_2" + }] + }] +} +``` -~> NOTE: For nested attributes that have been removed, such as `replication_specs.#.num_shards` etc, Terraform may NOT throw an explicit error even if these attributes are left in the configuration. This is a [known Terraform issue](https://github.com/hashicorp/terraform-plugin-framework/issues/1210). Users should ensure to remove any such attributes from the configuration to avoid any confusion. +- After: +```terraform +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "REPLICASET" + retain_backups_enabled = "true" -~> **IMPORTANT:** Don't apply until the plan is empty. If it shows other changes, you must update the `mongodbatlas_advanced_cluster` configuration until it matches the original configuration. + replication_specs = [{ + region_configs = [{ + electable_specs = { + instance_size = "M10" + node_count = 3 + disk_size_gb = 60 # this is now set at spec level + } + analytics_specs = { + instance_size = "M10" + node_count = 1 + disk_size_gb = 60 # this is now set at spec level + } + priority = 7 + provider_name = "AWS" + region_name = "US_WEST_2" + }] + }] +} +``` -- **Step #3:** Even though there are no plan changes shown at this point, run `terraform apply`. This will update the `mongodbatlas_advanced_cluster` state to support the new schema. -## Important notes +### Attribute vs Block Syntax +- In older versions, some list attributes (like `replication_specs` and `region_configs`) were written as nested **blocks**, for example: -Please refer to our [Considerations and Best Practices](#considerations-and-best-practices) section for additional guidance on this resource. +```terraform +replication_specs { + region_configs { + provider_name = "AWS" + region_name = "US_EAST_1" + } +} +replication_specs { + region_configs { + provider_name = "AWS" + region_name = "US_EAST_2" + } +} + +``` + +Newer Terraform plugin implementations, requires these to be expressed as **attributes** (with an `=` sign) instead, using a list or map syntax: + +```terraform +replication_specs = [{ + region_configs = [{ + provider_name = "AWS" + region_name = "US_EAST_1" + }] +}, +{ + region_configs = [{ + provider_name = "AWS" + region_name = "US_EAST_1" + }] +}] +``` + +- Similarly, elements such as `connection_strings`, `timeouts`, `advanced_configuration`, `bi_connector_config`, `pinned_fcv`, `electable_specs`, `read_only_specs`, `analytics_specs`, `auto_scaling` and `analytics_auto_scaling` are now **single attributes** instead of blocks so they are an object. For example, + +```terraform +advanced_configuration { + default_write_concern = "majority" +} +``` +becomes: + +```terraform +advanced_configuration = { + default_write_concern = "majority" +} +``` +If there are references to them, `[0]` or `.0` are dropped. For example, +```terraform +output "standard" { + value = mongodbatlas_advanced_cluster.cluster.connection_strings[0].standard +} +output "default_write_concern" { + value = mongodbatlas_advanced_cluster.cluster.advanced_configuration.0.default_write_concern +} +``` +becomes: + +```terraform +output "standard" { + value = mongodbatlas_advanced_cluster.cluster.connection_strings.standard +} +output "default_write_concern" { + value = mongodbatlas_advanced_cluster.cluster.advanced_configuration.default_write_concern +} +``` diff --git a/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/README.md b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/README.md index eb897cfc36..4f39a885d4 100644 --- a/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/README.md +++ b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/README.md @@ -1,19 +1,18 @@ -# MongoDB Atlas Provider -- Global Cluster (Preview for MongoDB Atlas Provider 2.0.0) +# MongoDB Atlas Provider — Asymmetric Sharded Cluster -This example creates a project and a Sharded Cluster with 4 independent shards with varying cluster tiers. +This example creates a project and a Sharded Cluster with 4 independent shards with varying cluster tiers. -It uses the **Preview for MongoDB Atlas Provider 2.0.0** of `mongodbatlas_advanced_cluster`. In order to enable the Preview, you must set the enviroment variable `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true`, otherwise the current version will be used. - -You can find more information in the [resource documentation page](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529). +### Migrating from v1.x to v2.0.0 or later +If you are migrating from v1.x of our provider to v2.0.0 or later, the `v1.x.x/` sub-directory shows how your current configuration might look like (with added inline comments to demonstrate what has changed in v2.0.0+ for migration reference). ## Dependencies -* Terraform MongoDB Atlas Provider v1.29.0 +* Terraform MongoDB Atlas Provider v2.0.0 or later * A MongoDB Atlas account ``` Terraform >= 0.13 -+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.29.0 ++ provider registry.terraform.io/terraform-providers/mongodbatlas v2.0.0 ``` @@ -63,4 +62,3 @@ Once you are finished your testing, ensure you destroy the resources to avoid un ``` bash $ terraform destroy ``` - diff --git a/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/main.tf b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/main.tf index 1a4f7fbc26..107433d12a 100644 --- a/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/main.tf +++ b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/main.tf @@ -17,6 +17,7 @@ resource "mongodbatlas_advanced_cluster" "cluster" { instance_size = "M30" disk_iops = 3000 node_count = 3 + disk_size_gb = 10 } provider_name = "AWS" priority = 7 @@ -32,6 +33,7 @@ resource "mongodbatlas_advanced_cluster" "cluster" { instance_size = "M30" disk_iops = 3000 node_count = 3 + disk_size_gb = 10 } provider_name = "AWS" priority = 7 @@ -47,6 +49,7 @@ resource "mongodbatlas_advanced_cluster" "cluster" { instance_size = "M40" disk_iops = 3000 node_count = 3 + disk_size_gb = 10 } provider_name = "AWS" priority = 7 @@ -62,6 +65,7 @@ resource "mongodbatlas_advanced_cluster" "cluster" { instance_size = "M40" disk_iops = 3000 node_count = 3 + disk_size_gb = 10 } provider_name = "AWS" priority = 7 diff --git a/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/README.md b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/README.md new file mode 100644 index 0000000000..4f89ce2aad --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/README.md @@ -0,0 +1,16 @@ +# Upgrade `mongodbatlas_advanced_cluster` v1.x → v2.0.0 (Asymmetric Sharded Cluster) + +This directory uses the deprecated v1.x schema version of the asymmetric sharded cluster example for migration reference. +Refer the `main.tf` in the parent directory (`../`) that shows what the corresponding configuration should look like after upgrading to provider v2.0.0+. + +**For details & to learn how to migrate, review the complete [Migration Guide: Advanced Cluster (v1.x → v2.0.0)](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/migrate-to-advanced-cluster-2.0#how-to-migrate)** + + ## Key changes in v2.0.0 + - `replication_specs` becomes a list of objects (was blocks in v1.x). + - `region_configs` becomes a list of objects (was blocks in v1.x). + - `electable_specs` becomes an attribute (was a nested block in v1.x). + - `advanced_configuration` becomes an attribute (was a block in v1.x). + - `tags` becomes a map attribute (was blocks in v1.x). + - Per-shard configuration remains explicit and can vary (e.g., different `instance_size` per shard). + - **If previously using** `disk_size_gb` at resource root level, it has been removed in v2.0.0 and now can be specified into the inner specs (for example, `electable_specs.disk_size_gb`). + - Some references drop `[0]` or `.0` indexing because objects are no longer lists but singular attributes (e.g., `replication_specs[0].region_configs[0].electable_specs.disk_size_gb`). diff --git a/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/main.tf b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/main.tf new file mode 100644 index 0000000000..2890060549 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/main.tf @@ -0,0 +1,83 @@ +provider "mongodbatlas" { + public_key = var.public_key + private_key = var.private_key +} + +# Below is the old v1.x schema of mongodbatlas_advanced_cluster. +# To migrate to v2.0.0+, see the main.tf in the parent directory. Refer README.md for more details. +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "SHARDED" + backup_enabled = true + disk_size_gb = 10 # removed in v2.0.0+, this can now be set per shard for inner specs + + # replication_specs are updated to a list of objects instead of blocks in v2.0.0+ + replication_specs { # shard 1 - M30 instance size + region_configs { # region_configs are updated to a list of objects instead of blocks in v2.0.0+ + electable_specs { # electable_specs are updated to an attribute instead of a block in v2.0.0+ + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + } + + replication_specs { # shard 2 - M30 instance size + region_configs { + electable_specs { + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + } + + replication_specs { # shard 3 - M40 instance size + region_configs { + electable_specs { + instance_size = "M40" + disk_iops = 3000 + node_count = 3 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + } + + replication_specs { # shard 4 - M40 instance size + region_configs { + electable_specs { + instance_size = "M40" + disk_iops = 3000 + node_count = 3 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + } + + advanced_configuration { # advanced_configuration are updated to an attribute instead of a block in v2.0.0+ + javascript_enabled = true + oplog_size_mb = 999 + sample_refresh_interval_bi_connector = 300 + } + + tags { # tags and labels are updated to maps instead of blocks in v2.0.0+ + key = "environment" + value = "dev" + } +} + +resource "mongodbatlas_project" "project" { + name = "Asymmetric Sharded Cluster" + org_id = var.atlas_org_id +} diff --git a/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/variables.tf b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/variables.tf new file mode 100644 index 0000000000..05e875b6b0 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/variables.tf @@ -0,0 +1,17 @@ +variable "atlas_org_id" { + description = "Atlas organization id" + type = string +} +variable "public_key" { + description = "Public API key to authenticate to Atlas" + type = string +} +variable "private_key" { + description = "Private API key to authenticate to Atlas" + type = string +} +variable "cluster_name" { + description = "Atlas cluster name" + type = string + default = "AsymmetricShardedCluster" +} diff --git a/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/versions.tf b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/versions.tf new file mode 100644 index 0000000000..62bbe10bf7 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/asymmetric-sharded-cluster/v1.x.x/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "<=1.41.0" + } + } + required_version = ">= 1.0" +} diff --git a/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/README.md b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/README.md index 58b25ea53f..f87b68abcd 100644 --- a/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/README.md +++ b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/README.md @@ -1,19 +1,18 @@ -# MongoDB Atlas Provider -- Sharded Cluster with Independent Shard Auto-scaling (Preview for MongoDB Atlas Provider 2.0.0) +# MongoDB Atlas Provider — Sharded Cluster with Independent Shard Auto-scaling This example creates a Sharded Cluster with 2 shards defining electable and analytics nodes. Compute auto-scaling is enabled for both `electable_specs` and `analytics_specs`, while also leveraging the [New Sharding Configuration](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/advanced-cluster-new-sharding-schema) by defining each shard with its individual `replication_specs`. This enables scaling of each shard to be independent. Please reference the [Use Auto-Scaling Per Shard](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/advanced-cluster-new-sharding-schema#use-auto-scaling-per-shard) section for more details. -It uses the **Preview for MongoDB Atlas Provider 2.0.0** of `mongodbatlas_advanced_cluster`. In order to enable the Preview, you must set the enviroment variable `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true`, otherwise the current version will be used. - -You can find more information in the [resource documentation page](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529). +### Migrating from v1.x to v2.0.0 or later +If you are migrating from v1.x of our provider to v2.0.0 or later, the `v1.x.x/` sub-directory shows how your current configuration might look like (with added inline comments to demonstrate what has changed in v2.0.0+ for migration reference). ## Dependencies -* Terraform MongoDB Atlas Provider v1.29.0 +* Terraform MongoDB Atlas Provider v2.0.0 or later * A MongoDB Atlas account ``` Terraform >= 0.13 -+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.29.0 ++ provider registry.terraform.io/terraform-providers/mongodbatlas v2.0.0 ``` @@ -63,4 +62,3 @@ Once you are finished your testing, ensure you destroy the resources to avoid un ``` bash $ terraform destroy ``` - diff --git a/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/README.md b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/README.md new file mode 100644 index 0000000000..e7bb384c75 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/README.md @@ -0,0 +1,14 @@ +# Upgrade `mongodbatlas_advanced_cluster` v1.x → v2.0.0 (Auto-scaling per Shard) + +This directory contains the deprecated v1.x schema version of the auto-scaling per shard example for migration reference. +Refer the `main.tf` in the parent directory (`../`) that shows what the corresponding configuration should look like after upgrading to provider v2.0.0+. + +**For details & to learn how to migrate, review the complete [Migration Guide: Advanced Cluster (v1.x → v2.0.0)](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/migrate-to-advanced-cluster-2.0#how-to-migrate)** + +## Key changes in v2.0.0 +- `replication_specs` becomes a list of objects (was a block in v1.x). +- `region_configs` becomes a list of objects (was a block in v1.x). +- `auto_scaling` and `analytics_auto_scaling` become attributes (were nested blocks in v1.x). +- `electable_specs` becomes an attribute (was a nested block in v1.x). +- **If previously using** `disk_size_gb` at resource root level, it has been removed in v2.0.0 and now can be specified into the inner specs (for example, `electable_specs.disk_size_gb`). +- Some references drop `[0]` or `.0` indexing because nested objects are no longer lists. diff --git a/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/main.tf b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/main.tf new file mode 100644 index 0000000000..3b4b31e4c3 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/main.tf @@ -0,0 +1,79 @@ +provider "mongodbatlas" { + public_key = var.public_key + private_key = var.private_key +} + +# Below is the old v1.x schema of mongodbatlas_advanced_cluster. +# To migrate to v2.0.0+, see the main.tf in the parent directory. Refer README.md for more details. +resource "mongodbatlas_advanced_cluster" "this" { + project_id = mongodbatlas_project.project.id + name = "AutoScalingCluster" + cluster_type = "SHARDED" + disk_size_gb = 10 # removed in v2.0.0+, this can now be set per shard for inner specs + + # replication_specs are updated to a list of objects instead of blocks in v2.0.0+ + replication_specs { # first shard + region_configs { # region_configs are updated to a list of objects instead of blocks in v2.0.0+ + auto_scaling { # auto_scaling are updated to an attribute instead of a block in v2.0.0+ + compute_enabled = true + compute_max_instance_size = "M60" + } + analytics_auto_scaling { # analytics_auto_scaling are updated to an attribute instead of a block in v2.0.0+ + compute_enabled = true + compute_max_instance_size = "M60" + } + electable_specs { # electable_specs are updated to an attribute instead of a block in v2.0.0+ + instance_size = "M40" + node_count = 3 + } + analytics_specs { + instance_size = "M40" + node_count = 1 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + zone_name = "Zone 1" + } + + replication_specs { # second shard + region_configs { + auto_scaling { + compute_enabled = true + compute_max_instance_size = "M60" + } + analytics_auto_scaling { + compute_enabled = true + compute_max_instance_size = "M60" + } + electable_specs { + instance_size = "M40" + node_count = 3 + } + analytics_specs { + instance_size = "M40" + node_count = 1 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + zone_name = "Zone 1" + } + + lifecycle { # avoid plans as autoscaling changes instance_size + ignore_changes = [ + # in v2.0.0+, electable_specs and analytics_specs are updated to attributes and will no longer require index to access instance_size + replication_specs[0].region_configs[0].electable_specs[0].instance_size, + replication_specs[0].region_configs[0].analytics_specs[0].instance_size, + replication_specs[1].region_configs[0].electable_specs[0].instance_size, + replication_specs[1].region_configs[0].analytics_specs[0].instance_size, + ] + } +} + +resource "mongodbatlas_project" "project" { + name = "AutoScalingPerShardCluster" + org_id = var.atlas_org_id +} diff --git a/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/variables.tf b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/variables.tf new file mode 100644 index 0000000000..d34c0ba2be --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/variables.tf @@ -0,0 +1,12 @@ +variable "atlas_org_id" { + description = "Atlas organization id" + type = string +} +variable "public_key" { + description = "Public API key to authenticate to Atlas" + type = string +} +variable "private_key" { + description = "Private API key to authenticate to Atlas" + type = string +} diff --git a/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/versions.tf b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/versions.tf new file mode 100644 index 0000000000..62bbe10bf7 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/auto-scaling-per-shard/v1.x.x/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "<=1.41.0" + } + } + required_version = ">= 1.0" +} diff --git a/examples/mongodbatlas_advanced_cluster/flex-upgrade/README.md b/examples/mongodbatlas_advanced_cluster/flex-upgrade/README.md index b43738f271..e4ebc90c5f 100644 --- a/examples/mongodbatlas_advanced_cluster/flex-upgrade/README.md +++ b/examples/mongodbatlas_advanced_cluster/flex-upgrade/README.md @@ -1,11 +1,6 @@ -# MongoDB Atlas Provider -- Flex cluster (Preview for MongoDB Atlas Provider 2.0.0) +# MongoDB Atlas Provider -- Flex cluster This example creates a project and a Flex cluster using `mongodbatlas_advanced_cluster` resource. It is intended to show how to create a Flex cluster, upgrade an M0 cluster to Flex and upgrade a Flex cluster to a Dedicated cluster. - -It uses the **Preview for MongoDB Atlas Provider 2.0.0** of `mongodbatlas_advanced_cluster`. In order to enable the Preview, you must set the enviroment variable `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true`, otherwise the current version will be used. - -You can find more information in the [resource documentation page](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529). - Variables Required: - `atlas_org_id`: ID of the Atlas organization - `public_key`: Atlas public key diff --git a/examples/mongodbatlas_advanced_cluster/flex-upgrade/main.tf b/examples/mongodbatlas_advanced_cluster/flex-upgrade/main.tf index 382a4a3c9d..b3381d1b66 100644 --- a/examples/mongodbatlas_advanced_cluster/flex-upgrade/main.tf +++ b/examples/mongodbatlas_advanced_cluster/flex-upgrade/main.tf @@ -26,8 +26,7 @@ resource "mongodbatlas_advanced_cluster" "cluster" { ] tags = { - key = "environment" - value = "dev" + environment = "dev" } } diff --git a/examples/mongodbatlas_advanced_cluster/global-cluster/README.md b/examples/mongodbatlas_advanced_cluster/global-cluster/README.md index 441fdc43d8..21b5c97d2a 100644 --- a/examples/mongodbatlas_advanced_cluster/global-cluster/README.md +++ b/examples/mongodbatlas_advanced_cluster/global-cluster/README.md @@ -1,19 +1,15 @@ -# MongoDB Atlas Provider -- Global Cluster (Preview for MongoDB Atlas Provider 2.0.0) +# MongoDB Atlas Provider -- Global Cluster This example creates a project and a Global Cluster with 2 zones where each zone has two shards. -It uses the **Preview for MongoDB Atlas Provider 2.0.0** of `mongodbatlas_advanced_cluster`. In order to enable the Preview, you must set the enviroment variable `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true`, otherwise the current version will be used. - -You can find more information in the [resource documentation page](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529). - ## Dependencies -* Terraform MongoDB Atlas Provider v1.29.0 +* Terraform MongoDB Atlas Provider v2.0.0 or later * A MongoDB Atlas account ``` Terraform >= 0.13 -+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.29.0 ++ provider registry.terraform.io/terraform-providers/mongodbatlas v2.0.0 ``` @@ -63,4 +59,3 @@ Once you are finished your testing, ensure you destroy the resources to avoid un ``` bash $ terraform destroy ``` - diff --git a/examples/mongodbatlas_advanced_cluster/multi-cloud/README.md b/examples/mongodbatlas_advanced_cluster/multi-cloud/README.md index 454faeefe6..150eb260e6 100644 --- a/examples/mongodbatlas_advanced_cluster/multi-cloud/README.md +++ b/examples/mongodbatlas_advanced_cluster/multi-cloud/README.md @@ -1,20 +1,15 @@ -# MongoDB Atlas Provider -- Multi-Cloud Advanced Cluster (Preview for MongoDB Atlas Provider 2.0.0) +# MongoDB Atlas Provider -- Multi-Cloud Advanced Cluster This example creates a project and a Multi Cloud Advanced Cluster with 2 shards. -It uses the **Preview for MongoDB Atlas Provider 2.0.0** of `mongodbatlas_advanced_cluster`. In order to enable the Preview, you must set the enviroment variable `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true`, otherwise the current version will be used. - -You can find more information in the [resource documentation page](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529). - - ## Dependencies -* Terraform MongoDB Atlas Provider v1.29.0 +* Terraform MongoDB Atlas Provider v2.0.0 or later * A MongoDB Atlas account ``` Terraform >= 0.13 -+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.29.0 ++ provider registry.terraform.io/terraform-providers/mongodbatlas v2.0.0 ``` @@ -64,4 +59,3 @@ Once you are finished your testing, ensure you destroy the resources to avoid un ``` bash $ terraform destroy ``` - diff --git a/examples/mongodbatlas_advanced_cluster/replicaset/README.md b/examples/mongodbatlas_advanced_cluster/replicaset/README.md new file mode 100644 index 0000000000..e74a29f0f3 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/replicaset/README.md @@ -0,0 +1,13 @@ +# MongoDB Atlas Provider — Advanced Cluster (Replica Set) + +This example creates a project and a Replica Set cluster. + +### Migrating from v1.x to v2.0.0 or later +If you are migrating from v1.x of our provider to v2.0.0 or later, the `v1.x.x/` sub-directory shows how your current configuration might look like (with added inline comments to demonstrate what has changed in v2.0.0+ for migration reference). + +Variables Required: +- `atlas_org_id`: ID of the Atlas organization +- `public_key`: Atlas public key +- `private_key`: Atlas private key +- `provider_name`: Name of provider to use for cluster (TENANT, AWS, GCP) +- `provider_instance_size_name`: Size of the cluster (Free: M0, Dedicated: M10+.) diff --git a/examples/mongodbatlas_advanced_cluster/replicaset/main.tf b/examples/mongodbatlas_advanced_cluster/replicaset/main.tf new file mode 100644 index 0000000000..02ffae53cc --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/replicaset/main.tf @@ -0,0 +1,35 @@ +provider "mongodbatlas" { + public_key = var.public_key + private_key = var.private_key +} + +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = "ClusterToUpgrade" + cluster_type = "REPLICASET" + + replication_specs = [ + { + region_configs = [ + { + electable_specs = { + instance_size = var.provider_instance_size_name + node_count = 3 + } + provider_name = var.provider_name + region_name = "US_EAST_1" + priority = 7 + } + ] + } + ] + + tags = { + environment = "dev" + } +} + +resource "mongodbatlas_project" "project" { + name = "TenantUpgradeTest" + org_id = var.atlas_org_id +} diff --git a/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/README.md b/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/README.md new file mode 100644 index 0000000000..b1da4e88a8 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/README.md @@ -0,0 +1,14 @@ +# Upgrade `mongodbatlas_advanced_cluster` v1.x → v2.0.0 (Replicaset) + +This directory contains the deprecated v1.x schema version of the Replica Set example for migration reference. +Refer the `main.tf` in the parent directory (`../`) that shows what the corresponding configuration should look like after upgrading to provider v2.0.0+. + +**For details & to learn how to migrate, review the complete [Migration Guide: Advanced Cluster (v1.x → v2.0.0)](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/migrate-to-advanced-cluster-2.0#how-to-migrate)** + +## Key changes in v2.0.0 +- `replication_specs` becomes a list of objects (was a block in v1.x). +- `region_configs` becomes a list of objects (was a block in v1.x). +- `electable_specs` becomes an attribute (was a nested block in v1.x). +- `tags` becomes a map attribute (was a block in v1.x). +- **If previously using** `num_shards`, it has been removed in v2.0.0; sharded layouts use multiple `replication_specs` entries instead and REPLICASET clusters don't require this attribute. +- Some references may drop `[0]` or `.0` indexing because nested objects are no longer lists. diff --git a/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/main.tf b/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/main.tf new file mode 100644 index 0000000000..f3a4b1d883 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/main.tf @@ -0,0 +1,38 @@ +provider "mongodbatlas" { + public_key = var.public_key + private_key = var.private_key +} + + +# Below is the old v1.x schema of mongodbatlas_advanced_cluster. +# To migrate to v2.0.0+, see the main.tf in the parent directory. Refer README.md for more details. +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = "ClusterToUpgrade" + cluster_type = "REPLICASET" + + # replication_specs are updated to a list of objects instead of blocks in v2.0.0+ + replication_specs { # replication_specs are updated to a list of objects instead of blocks in v2.0.0+ + num_shards = 1 # removed in v2.0.0+ + + region_configs { # region_configs are updated to a list of objects instead of blocks in v2.0.0+ + electable_specs { + instance_size = var.provider_instance_size_name + node_count = 3 + } + provider_name = var.provider_name + region_name = "US_EAST_1" + priority = 7 + } + } + + tags { # tags and labels are updated to maps instead of blocks in v2.0.0+ + key = "environment" + value = "dev" + } +} + +resource "mongodbatlas_project" "project" { + name = "TenantUpgradeTest" + org_id = var.atlas_org_id +} diff --git a/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/variables.tf b/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/variables.tf new file mode 100644 index 0000000000..fc67c1913e --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/variables.tf @@ -0,0 +1,22 @@ +variable "atlas_org_id" { + description = "Atlas organization id" + type = string +} +variable "public_key" { + description = "Public API key to authenticate to Atlas" + type = string +} +variable "private_key" { + description = "Private API key to authenticate to Atlas" + type = string +} +variable "provider_name" { + description = "Atlas cluster provider name" + default = "AWS" + type = string +} +variable "provider_instance_size_name" { + description = "Atlas cluster provider instance name" + default = "M10" + type = string +} diff --git a/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/versions.tf b/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/versions.tf new file mode 100644 index 0000000000..62bbe10bf7 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/replicaset/v1.x.x/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "<=1.41.0" + } + } + required_version = ">= 1.0" +} diff --git a/examples/mongodbatlas_advanced_cluster/replicaset/variables.tf b/examples/mongodbatlas_advanced_cluster/replicaset/variables.tf new file mode 100644 index 0000000000..fc67c1913e --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/replicaset/variables.tf @@ -0,0 +1,22 @@ +variable "atlas_org_id" { + description = "Atlas organization id" + type = string +} +variable "public_key" { + description = "Public API key to authenticate to Atlas" + type = string +} +variable "private_key" { + description = "Private API key to authenticate to Atlas" + type = string +} +variable "provider_name" { + description = "Atlas cluster provider name" + default = "AWS" + type = string +} +variable "provider_instance_size_name" { + description = "Atlas cluster provider instance name" + default = "M10" + type = string +} diff --git a/examples/mongodbatlas_advanced_cluster/replicaset/versions.tf b/examples/mongodbatlas_advanced_cluster/replicaset/versions.tf new file mode 100644 index 0000000000..0fe79cfac9 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/replicaset/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + } + } + required_version = ">= 1.0" +} diff --git a/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/README.md b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/README.md new file mode 100644 index 0000000000..d141c5f5d0 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/README.md @@ -0,0 +1,64 @@ +# MongoDB Atlas Provider — Symmetric Sharded Cluster + +This example creates a SHARDED cluster with 2 shards configured symmetrically. + +### Migrating from v1.x to v2.0.0 or later +If you are migrating from v1.x of our provider to v2.0.0 or later, the `v1.x.x/` sub-directory shows how your current configuration might look like (with added inline comments to demonstrate what has changed for migration reference). + +## Dependencies + +* Terraform MongoDB Atlas Provider v2.0.0 or later +* A MongoDB Atlas account + +``` +Terraform >= 0.13 ++ provider registry.terraform.io/terraform-providers/mongodbatlas v2.0.0 +``` + + +## Usage +**1\. Ensure your MongoDB Atlas credentials are set up.** + +This can be done using environment variables: + +```bash +export MONGODB_ATLAS_PUBLIC_KEY="" +export MONGODB_ATLAS_PRIVATE_KEY="" +``` + +... or follow as in the `variables.tf` file and create **terraform.tfvars** file with all the variable values, ex: +``` +public_key = "" +private_key = "" +atlas_org_id = "" +``` + +... or use [AWS Secrets Manager](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs#aws-secrets-manager) + +**2\. Review the Terraform plan.** + +Execute the below command and ensure you are happy with the plan. + +``` bash +$ terraform plan +``` +This project currently supports the below deployments: + +- An Atlas Project +- A Sharded Cluster with independent shards with varying cluster tiers + +**3\. Execute the Terraform apply.** + +Now execute the plan to provision the Atlas Project and Cluster resources. + +``` bash +$ terraform apply +``` + +**4\. Destroy the resources.** + +Once you are finished your testing, ensure you destroy the resources to avoid unnecessary Atlas charges. + +``` bash +$ terraform destroy +``` diff --git a/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/main.tf b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/main.tf new file mode 100644 index 0000000000..ef72a1f268 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/main.tf @@ -0,0 +1,53 @@ +provider "mongodbatlas" { + public_key = var.public_key + private_key = var.private_key +} + +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "SHARDED" + backup_enabled = true + + replication_specs = [{ + region_configs = [{ + electable_specs = { + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + disk_size_gb = 10 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + }] + }, + { + region_configs = [{ + electable_specs = { + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + disk_size_gb = 10 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + }] + }] + + advanced_configuration = { + javascript_enabled = true + oplog_size_mb = 999 + sample_refresh_interval_bi_connector = 300 + } + + tags = { + environment = "dev" + } +} + +resource "mongodbatlas_project" "project" { + name = "Symmetric Sharded Cluster" + org_id = var.atlas_org_id +} diff --git a/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/README.md b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/README.md new file mode 100644 index 0000000000..b75b608fe9 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/README.md @@ -0,0 +1,16 @@ +# Upgrade `mongodbatlas_advanced_cluster` v1.x → v2.0.0 (Symmetric Sharded Cluster) + +This directory contains the deprecated v1.x schema version of the symmetric sharded (2 shards) cluster example for migration reference. +Refer the `main.tf` in the parent directory (`../`) that shows what the corresponding configuration should look like after upgrading to provider v2.0.0+. + + **For details & to learn how to migrate, review the complete [Migration Guide: Advanced Cluster (v1.x → v2.0.0)](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/migrate-to-advanced-cluster-2.0#how-to-migrate)** + + ## Key changes in v2.0.0 + - `replication_specs` becomes a list of objects (was a block in v1.x). + - `region_configs` becomes a list of objects (was a block in v1.x). + - `electable_specs` becomes an attribute (was a nested block in v1.x). + - `advanced_configuration` becomes an attribute (was a block in v1.x). + - `tags` becomes an attribute (was a block in v1.x). + - **If previously using** `num_shards`, it has been removed in v2.0.0; sharded layouts use multiple `replication_specs` entries instead and REPLICASET clusters don't require this attribute. + - **If previously using** `disk_size_gb` at resource root level, it has been removed in v2.0.0 and now can be specified into the inner specs (for example, `electable_specs.disk_size_gb`). + - Some references drop `[0]` or `.0` indexing because objects are no longer lists but singular attributes (e.g., `replication_specs[0].region_configs[0].electable_specs.disk_size_gb`). diff --git a/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/main.tf b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/main.tf new file mode 100644 index 0000000000..9b2fe6aa27 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/main.tf @@ -0,0 +1,50 @@ +provider "mongodbatlas" { + public_key = var.public_key + private_key = var.private_key +} + +# Below is the old v1.x schema of mongodbatlas_advanced_cluster. +# To migrate to v2.0.0+, see the main.tf in the parent directory. Refer README.md for more details. +resource "mongodbatlas_advanced_cluster" "cluster" { + project_id = mongodbatlas_project.project.id + name = var.cluster_name + cluster_type = "SHARDED" + backup_enabled = true + disk_size_gb = 10 # removed in v2.0.0+, this can now be set per shard for inner specs + + # replication_specs are updated to a list of objects instead of blocks in v2.0.0+ + replication_specs { + + # this cluster has 2 M30 shards + # num_shards has been removed in v2.0.0+, upgrading to v2.0.0+ will require adding a new identical `replication_specs` element for each shard + # refer https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/advanced-cluster-new-sharding-schema for details. + num_shards = 2 + + region_configs { # region_configs are updated to a list of objects instead of blocks in v2.0.0+ + electable_specs { # electable_specs are updated to an attribute instead of a block in v2.0.0+ + instance_size = "M30" + disk_iops = 3000 + node_count = 3 + } + provider_name = "AWS" + priority = 7 + region_name = "EU_WEST_1" + } + zone_name = "zone n1" + } + advanced_configuration { # advanced_configuration are updated to an attribute instead of a block in v2.0.0+ + javascript_enabled = true + oplog_size_mb = 999 + sample_refresh_interval_bi_connector = 300 + } + + tags { # tags and labels are updated to maps instead of blocks in v2.0.0+ + key = "environment" + value = "dev" + } +} + +resource "mongodbatlas_project" "project" { + name = "Symmetric Geosharded Cluster" + org_id = var.atlas_org_id +} diff --git a/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/variables.tf b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/variables.tf new file mode 100644 index 0000000000..05e875b6b0 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/variables.tf @@ -0,0 +1,17 @@ +variable "atlas_org_id" { + description = "Atlas organization id" + type = string +} +variable "public_key" { + description = "Public API key to authenticate to Atlas" + type = string +} +variable "private_key" { + description = "Private API key to authenticate to Atlas" + type = string +} +variable "cluster_name" { + description = "Atlas cluster name" + type = string + default = "AsymmetricShardedCluster" +} diff --git a/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/versions.tf b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/versions.tf new file mode 100644 index 0000000000..62bbe10bf7 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/v1.x.x/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + version = "<=1.41.0" + } + } + required_version = ">= 1.0" +} diff --git a/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/variables.tf b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/variables.tf new file mode 100644 index 0000000000..05e875b6b0 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/variables.tf @@ -0,0 +1,17 @@ +variable "atlas_org_id" { + description = "Atlas organization id" + type = string +} +variable "public_key" { + description = "Public API key to authenticate to Atlas" + type = string +} +variable "private_key" { + description = "Private API key to authenticate to Atlas" + type = string +} +variable "cluster_name" { + description = "Atlas cluster name" + type = string + default = "AsymmetricShardedCluster" +} diff --git a/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/versions.tf b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/versions.tf new file mode 100644 index 0000000000..0fe79cfac9 --- /dev/null +++ b/examples/mongodbatlas_advanced_cluster/symmetric-sharded-cluster/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + mongodbatlas = { + source = "mongodb/mongodbatlas" + } + } + required_version = ">= 1.0" +} diff --git a/examples/mongodbatlas_advanced_cluster/tenant-upgrade/README.md b/examples/mongodbatlas_advanced_cluster/tenant-upgrade/README.md index 81dc6b9c4e..dac75f8b5f 100644 --- a/examples/mongodbatlas_advanced_cluster/tenant-upgrade/README.md +++ b/examples/mongodbatlas_advanced_cluster/tenant-upgrade/README.md @@ -1,11 +1,7 @@ -# MongoDB Atlas Provider -- Advanced Cluster Tenant Upgrade (Preview for MongoDB Atlas Provider 2.0.0) +# MongoDB Atlas Provider -- Advanced Cluster Tenant Upgrade This example creates a project and cluster. It is intended to show how to upgrade from shared, aka tenant, to dedicated tier. -It uses the **Preview for MongoDB Atlas Provider 2.0.0** of `mongodbatlas_advanced_cluster`. In order to enable the Preview, you must set the enviroment variable `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true`, otherwise the current version will be used. - -You can find more information in the [resource documentation page](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529). - Variables Required: - `atlas_org_id`: ID of the Atlas organization - `public_key`: Atlas public key diff --git a/examples/mongodbatlas_advanced_cluster/version-upgrade-with-pinned-fcv/README.md b/examples/mongodbatlas_advanced_cluster/version-upgrade-with-pinned-fcv/README.md index 73defa2b3c..0dece6dee2 100644 --- a/examples/mongodbatlas_advanced_cluster/version-upgrade-with-pinned-fcv/README.md +++ b/examples/mongodbatlas_advanced_cluster/version-upgrade-with-pinned-fcv/README.md @@ -1,4 +1,4 @@ -# MongoDB Atlas Provider -- Cluster with pinned FCV (Preview for MongoDB Atlas Provider 2.0.0) +# MongoDB Atlas Provider -- Cluster with pinned FCV Example shows how to pin the FCV of a cluster making use of `pinned_fcv` block. This enables direct control to pin cluster’s FCV before performing an upgrade on the `mongo_db_major_version`. Users can then downgrade to the previous MongoDB version with minimal risk if desired, as the FCV is maintained. @@ -6,18 +6,14 @@ The unpin operation can be performed by removing the `pinned_fcv` block. **Note* The following [knowledge hub article](https://kb.corp.mongodb.com/article/000021785/) and [FCV documentation](https://www.mongodb.com/docs/atlas/tutorial/major-version-change/#manage-feature-compatibility--fcv--during-upgrades) can be referenced for more details. -It uses the **Preview for MongoDB Atlas Provider 2.0.0** of `mongodbatlas_advanced_cluster`. In order to enable the Preview, you must set the enviroment variable `MONGODB_ATLAS_PREVIEW_PROVIDER_V2_ADVANCED_CLUSTER=true`, otherwise the current version will be used. - -You can find more information in the [resource documentation page](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/advanced_cluster%2520%2528preview%2520provider%25202.0.0%2529). - ## Dependencies -* Terraform MongoDB Atlas Provider v1.29.0 +* Terraform MongoDB Atlas Provider v2.0.0 or later * A MongoDB Atlas account ``` Terraform >= 0.13 -+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.29.0 ++ provider registry.terraform.io/terraform-providers/mongodbatlas v2.0.0 ``` @@ -58,4 +54,3 @@ Once you finished your testing, ensure you destroy the resources to avoid unnece ``` bash $ terraform destroy ``` - diff --git a/internal/testutil/acc/advanced_cluster_mig_TPF_test.go b/internal/testutil/acc/advanced_cluster_mig_TPF_test.go index 4faba33f66..f234328ba1 100644 --- a/internal/testutil/acc/advanced_cluster_mig_TPF_test.go +++ b/internal/testutil/acc/advanced_cluster_mig_TPF_test.go @@ -129,7 +129,7 @@ func TestConvertAdvancedClusterToTPF(t *testing.T) { value = "labelvalue" } - tags { + tags { key = "tag" value = "tagvalue" } diff --git a/scripts/tf-validate.sh b/scripts/tf-validate.sh index 5dd0745899..1cf9889c1e 100755 --- a/scripts/tf-validate.sh +++ b/scripts/tf-validate.sh @@ -20,23 +20,37 @@ set -Eeou pipefail find ./examples -type d -name ".terraform" -exec rm -rf {} + find ./examples -type f -name ".terraform.lock.hcl" -exec rm -f {} + -export TF_CLI_CONFIG_FILE="$PWD/bin-examples/tf-validate.tfrc" - # Use local provider to validate examples go build -o bin-examples/terraform-provider-mongodbatlas . -cat << EOF > "$TF_CLI_CONFIG_FILE" -provider_installation { +# Two TF CLI configs: one with local override, one without +TF_CLI_CONFIG_FILE_WITH="$PWD/bin-examples/tf-validate.local.tfrc" +TF_CLI_CONFIG_FILE_NO="$PWD/bin-examples/tf-validate.remote.tfrc" + +cat << EOF > "$TF_CLI_CONFIG_FILE_WITH" +provider_installation { dev_overrides { "mongodb/mongodbatlas" = "$PWD/bin-examples" } - direct {} + direct {} +} +EOF + +cat << EOF > "$TF_CLI_CONFIG_FILE_NO" +provider_installation { + direct {} } EOF for DIR in $(find ./examples -type f -name '*.tf' -exec dirname {} \; | sort -u); do [ ! -d "$DIR" ] && continue pushd "$DIR" + # For directories named like v1.x.x, do NOT use local override + if [[ "$(basename "$DIR")" == "v1.x.x" ]]; then + export TF_CLI_CONFIG_FILE="$TF_CLI_CONFIG_FILE_NO" + else + export TF_CLI_CONFIG_FILE="$TF_CLI_CONFIG_FILE_WITH" + fi echo; echo -e "\e[1;35m===> Example: $DIR <===\e[0m"; echo terraform init > /dev/null # suppress output as it's very verbose terraform fmt -check -recursive