Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: Updates examples and documentation in resource and data source with new ISS attributes and structure #2438

Merged
merged 15 commits into from
Jul 19, 2024
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# MongoDB Atlas Provider -- Global Cluster
This example creates a project and a Global Cluster.
This example creates a project and a Global Cluster with 2 zones.
maastha marked this conversation as resolved.
Show resolved Hide resolved


## Dependencies
Expand Down
76 changes: 62 additions & 14 deletions examples/mongodbatlas_advanced_cluster/global-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ resource "mongodbatlas_advanced_cluster" "cluster" {

backup_enabled = true

replication_specs { # zone n1
zone_name = "zone n1"
num_shards = 3 # 3-shard Multi-Cloud Cluster
replication_specs { # shard 1 - zone n1
zone_name = "zone n1"

region_configs { # shard n1
region_configs {
electable_specs {
instance_size = "M10"
node_count = 3
Expand All @@ -31,7 +30,7 @@ resource "mongodbatlas_advanced_cluster" "cluster" {
region_name = "US_EAST_1"
}

region_configs { # shard n2
region_configs {
electable_specs {
instance_size = "M10"
node_count = 2
Expand All @@ -44,8 +43,58 @@ resource "mongodbatlas_advanced_cluster" "cluster" {
priority = 6
region_name = "US_EAST_2"
}
}

replication_specs { # shard 2 - zone n1
zone_name = "zone n1"

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_EAST_1"
}

region_configs {
electable_specs {
instance_size = "M10"
node_count = 2
}
analytics_specs {
instance_size = "M10"
node_count = 1
}
provider_name = "AZURE"
priority = 6
region_name = "US_EAST_2"
}
}

region_configs { # shard n3
replication_specs { # shard 1 - zone n2
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
replication_specs { # shard 1 - zone n2
replication_specs { # shard 3 - zone n2

Same for # shard 2 - zone n2 -> # shard 4 - zone n2
Do you think this would make it more clear? At the end the configuration is defining 4 shards, 2 in each zone.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think since the zone is mentioned alongside, this should not be updated to shard 3 & 4. In the current way it seems clear that it's 2 shards in each zone

zone_name = "zone n2"

region_configs {
electable_specs {
instance_size = "M10"
node_count = 3
}
analytics_specs {
maastha marked this conversation as resolved.
Show resolved Hide resolved
instance_size = "M10"
node_count = 1
}
provider_name = "AWS"
priority = 7
region_name = "EU_WEST_1"
}

region_configs {
electable_specs {
instance_size = "M10"
node_count = 2
Expand All @@ -54,17 +103,16 @@ resource "mongodbatlas_advanced_cluster" "cluster" {
instance_size = "M10"
node_count = 1
}
provider_name = "GCP"
priority = 0
region_name = "US_EAST_4"
provider_name = "AZURE"
lantoli marked this conversation as resolved.
Show resolved Hide resolved
priority = 6
region_name = "EUROPE_NORTH"
}
}

replication_specs { # zone n2
zone_name = "zone n2"
num_shards = 2 # 2-shard Multi-Cloud Cluster
replication_specs { # shard 2 - zone n2
zone_name = "zone n2"

region_configs { # shard n1
region_configs {
electable_specs {
instance_size = "M10"
node_count = 3
Expand All @@ -78,7 +126,7 @@ resource "mongodbatlas_advanced_cluster" "cluster" {
region_name = "EU_WEST_1"
}

region_configs { # shard n2
region_configs {
electable_specs {
instance_size = "M10"
node_count = 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# MongoDB Atlas Provider -- Multi-Cloud Advanced Cluster
This example creates a project and a Multi Cloud Advanced Cluster in all the available cloud providers.
This example creates a project and a Multi Cloud Advanced Cluster with 2 shards.


## Dependencies
Expand Down
32 changes: 23 additions & 9 deletions examples/mongodbatlas_advanced_cluster/multi-cloud/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ resource "mongodbatlas_advanced_cluster" "cluster" {
cluster_type = "SHARDED"
backup_enabled = true

replication_specs {
num_shards = 3 # 3-shard Multi-Cloud Cluster

region_configs { # shard n1
replication_specs { # shard 1
region_configs {
electable_specs {
instance_size = "M10"
node_count = 3
Expand All @@ -26,7 +24,7 @@ resource "mongodbatlas_advanced_cluster" "cluster" {
region_name = "US_EAST_1"
}

region_configs { # shard n2
region_configs {
electable_specs {
instance_size = "M10"
node_count = 2
Expand All @@ -39,8 +37,24 @@ resource "mongodbatlas_advanced_cluster" "cluster" {
priority = 6
region_name = "US_EAST_2"
}
}

replication_specs { # shard 2
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_EAST_1"
}

region_configs { # shard n3
region_configs {
electable_specs {
instance_size = "M10"
node_count = 2
Expand All @@ -49,9 +63,9 @@ resource "mongodbatlas_advanced_cluster" "cluster" {
instance_size = "M10"
node_count = 1
}
provider_name = "GCP"
priority = 5
region_name = "US_EAST_4"
provider_name = "AZURE"
priority = 6
region_name = "US_EAST_2"
}
}

Expand Down
17 changes: 10 additions & 7 deletions internal/service/advancedcluster/data_source_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ func DataSource() *schema.Resource {
Required: true,
},
"use_replication_spec_per_shard": {
Type: schema.TypeBool,
Optional: true,
Type: schema.TypeBool,
Optional: true,
Description: "Set this field to true to allow the data source to use the latest schema leveraging independent shards in the cluster.",
maastha marked this conversation as resolved.
Show resolved Hide resolved
},
"advanced_configuration": SchemaAdvancedConfigDS(),
"backup_enabled": {
Expand Down Expand Up @@ -59,9 +60,10 @@ func DataSource() *schema.Resource {
Computed: true,
},
"disk_size_gb": {
Type: schema.TypeFloat,
Computed: true,
Deprecated: DeprecationMsgOldSchema,
Type: schema.TypeFloat,
Computed: true,
Description: "Capacity, in gigabytes, of the host's root volume. If `use_replication_spec_per_shard = true` then this value is equal to `disk_size_gb` of the first `replication_spec.#.region_configs.#.electable_specs`.",
Deprecated: DeprecationMsgOldSchema,
},
"encryption_at_rest_provider": {
Type: schema.TypeString,
Expand Down Expand Up @@ -117,8 +119,9 @@ func DataSource() *schema.Resource {
Deprecated: DeprecationMsgOldSchema,
},
"zone_id": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Description: "Unique 24-hexadecimal digit string that identifies the zone in a Global Cluster. If clusterType is GEOSHARDED or `global_cluster_self_managed_sharding` is true, this value indicates the zone that the given shard belongs to and can be used to configure Global Cluster backup policies. This attribute is only available if using the latest schema of this resource leveraging independent shards in the cluster (i.e. `use_replication_spec_per_shard = true`.",
maastha marked this conversation as resolved.
Show resolved Hide resolved
},
"external_id": {
Type: schema.TypeString,
Expand Down
5 changes: 3 additions & 2 deletions internal/service/advancedcluster/resource_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,9 @@ func Resource() *schema.Resource {
Deprecated: DeprecationMsgOldSchema,
},
"zone_id": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Description: "Unique 24-hexadecimal digit string that identifies the zone in a Global Cluster. If clusterType is GEOSHARDED or `global_cluster_self_managed_sharding` is true, this value indicates the zone that the given shard belongs to and can be used to configure Global Cluster backup policies. This attribute is only available if using the latest schema of this resource leveraging independent shards in the cluster.",
},
"external_id": {
Type: schema.TypeString,
Expand Down
62 changes: 60 additions & 2 deletions website/docs/d/advanced_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,66 @@ data "mongodbatlas_advanced_cluster" "example" {
}
```

Example using latest schema with independent (asymmetric) shards in the cluster:
maastha marked this conversation as resolved.
Show resolved Hide resolved

```terraform
resource "mongodbatlas_advanced_cluster" "example" {
project_id = "<YOUR-PROJECT-ID>"
name = "cluster-test"
backup_enabled = false
cluster_type = "SHARDED"

replication_specs { # Sharded cluster with 2 asymmetric shards (M30 and M40)
region_configs {
electable_specs {
instance_size = "M30"
disk_iops = 3000
node_count = 3
disk_size_gb = 60
}
analytics_specs {
instance_size = "M30"
node_count = 1
disk_size_gb = 60
maastha marked this conversation as resolved.
Show resolved Hide resolved
}
provider_name = "AWS"
priority = 7
region_name = "EU_WEST_1"
}
}

replication_specs {
region_configs {
electable_specs {
instance_size = "M40"
disk_iops = 3000
node_count = 3
disk_size_gb = 60
}
analytics_specs {
instance_size = "M40"
node_count = 1
disk_size_gb = 60
}
provider_name = "AWS"
priority = 7
region_name = "EU_WEST_1"
}
}
}

data "mongodbatlas_advanced_cluster" "example" {
project_id = mongodbatlas_advanced_cluster.example.project_id
name = mongodbatlas_advanced_cluster.example.name
use_replication_spec_per_shard = true
}
```

## Argument Reference

* `project_id` - (Required) The unique ID for the project to create the database user.
* `name` - (Required) Name of the cluster as it appears in Atlas. Once the cluster is created, its name cannot be changed.
* `use_replication_spec_per_shard` - (Optional) Set this field to true to allow the data source to use the latest schema leveraging independent shards in the cluster.
maastha marked this conversation as resolved.
Show resolved Hide resolved

## Attributes Reference

Expand All @@ -55,13 +111,13 @@ In addition to all arguments above, the following attributes are exported:
* `id` - The cluster ID.
* `bi_connector_config` - Configuration settings applied to BI Connector for Atlas on this cluster. See [below](#bi_connector_config). **NOTE** Prior version of provider had parameter as `bi_connector`
* `cluster_type` - Type of the cluster that you want to create.
* `disk_size_gb` - Capacity, in gigabytes, of the host's root volume. **(DEPRECATED)** Use `replication_specs.#.region_config.#.(analytics_specs|electable_specs|read_only_specs).disk_size_gb` instead. Please refer [1.18.0 upgrade guide](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/1.18.0-upgrade-guide.html.markdown) for more details.
* `disk_size_gb` - Capacity, in gigabytes, of the host's root volume. If `use_replication_spec_per_shard = true` then this value is equal to `disk_size_gb` of the first `replication_spec.#.region_configs.#.electable_specs`. **(DEPRECATED)** Use `replication_specs.#.region_config.#.(analytics_specs|electable_specs|read_only_specs).disk_size_gb` instead. Please refer [1.18.0 upgrade guide](https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/1.18.0-upgrade-guide.html.markdown) for more details.
Copy link
Member

Choose a reason for hiding this comment

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

If use_replication_spec_per_shard = true we still populate this root value, so believe this additional comment is not needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was added to address this point in the ticket Mention impact on root disk_size_gb computed value if new flag is used. Is there anything we should mention on this? If not, I can remove the additional comment

Copy link
Member

Choose a reason for hiding this comment

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

My bad for not updating that mention, after #2405 logic was added to always populate at the root level to avoid breaking changes in the resource, and having that implementation in place it was added to the data source as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

discussed offline, removed

* `encryption_at_rest_provider` - Possible values are AWS, GCP, AZURE or NONE.
* `tags` - Set that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the cluster. See [below](#tags).
* `labels` - Set that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the cluster. See [below](#labels). **DEPRECATED** Use `tags` instead.
* `mongo_db_major_version` - Version of the cluster to deploy.
* `pit_enabled` - Flag that indicates if the cluster uses Continuous Cloud Backup.
* `replication_specs` - Configuration for cluster regions and the hardware provisioned in them. See [below](#replication_specs).
* `replication_specs` - List of settings that configure your cluster regions. This array has one object per shard representing node configurations in each shard. For replica sets there is only one object representing node configurations. See [below](#replication_specs).
maastha marked this conversation as resolved.
Show resolved Hide resolved
* `root_cert_type` - Certificate Authority that MongoDB Atlas clusters use.
* `termination_protection_enabled` - Flag that indicates whether termination protection is enabled on the cluster. If set to true, MongoDB Cloud won't delete the cluster. If set to false, MongoDB Cloud will delete the cluster.
* `version_release_system` - Release cadence that Atlas uses for this cluster.
Expand Down Expand Up @@ -102,6 +158,7 @@ Key-value pairs that categorize the cluster. Each key and value has a maximum le
* `region_configs` - Configuration for the hardware specifications for nodes set for a given regionEach `region_configs` object describes the region's priority in elections and the number and type of MongoDB nodes that Atlas deploys to the region. Each `region_configs` object must have either an `analytics_specs` object, `electable_specs` object, or `read_only_specs` object. See [below](#region_configs)
* `container_id` - A key-value map of the Network Peering Container ID(s) for the configuration specified in `region_configs`. The Container ID is the id of the container either created programmatically by the user before any clusters existed in a project or when the first cluster in the region (AWS/Azure) or project (GCP) was created. The syntax is `"providerName:regionName" = "containerId"`. Example `AWS:US_EAST_1" = "61e0797dde08fb498ca11a71`.
* `zone_name` - Name for the zone in a Global Cluster.
* `zone_id` - Unique 24-hexadecimal digit string that identifies the zone in a Global Cluster. If clusterType is GEOSHARDED or `global_cluster_self_managed_sharding` is true, this value indicates the zone that the given shard belongs to and can be used to configure Global Cluster backup policies. This attribute is only available if using the latest schema of this resource leveraging independent shards in the cluster (i.e. `use_replication_spec_per_shard = true`.
maastha marked this conversation as resolved.
Show resolved Hide resolved
maastha marked this conversation as resolved.
Show resolved Hide resolved


### region_configs
Expand All @@ -124,6 +181,7 @@ Key-value pairs that categorize the cluster. Each key and value has a maximum le
* `PROVISIONED` volume types must fall within the allowable IOPS range for the selected volume size.
* `instance_size` - Hardware specification for the instance sizes in this region.
* `node_count` - Number of nodes of the given type for MongoDB Atlas to deploy to the region.
* `disk_size_gb` - Storage capacity that the host's root volume possesses expressed in gigabytes. Increase this number to add capacity. MongoDB Cloud requires this parameter if you set **replication_specs**. If you specify a disk size below the minimum (10 GB), this parameter defaults to the minimum disk size value. Storage charge calculations depend on whether you choose the default value or a custom value. The maximum value for disk storage cannot exceed 50 times the maximum RAM for the selected cluster. If you require more storage space, consider upgrading your cluster to a higher tier.
maastha marked this conversation as resolved.
Show resolved Hide resolved

### auto_scaling

Expand Down
Loading
Loading