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

feat: Support pinned_fcv attribute in advanced_cluster resource and data sources #2789

Merged
merged 34 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e00992c
wip
AgustinBettati Nov 6, 2024
c0cbaa8
support pinning with and without expiration date
AgustinBettati Nov 6, 2024
6806b52
add support for unpinning on update
AgustinBettati Nov 6, 2024
c425e7a
commented code for handling validation
AgustinBettati Nov 6, 2024
7057ea8
make expiration date required
AgustinBettati Nov 7, 2024
c0d19f6
add waiting before continueing with other updates
AgustinBettati Nov 7, 2024
d14fb6b
handle fcv during creation
AgustinBettati Nov 7, 2024
f2d73a0
add support for singular data source
AgustinBettati Nov 7, 2024
0ff324a
add in plural data source
AgustinBettati Nov 7, 2024
e02cd81
add changelog entry
AgustinBettati Nov 7, 2024
9281b82
add in cluster tpf schema
AgustinBettati Nov 8, 2024
80e1433
include docs for fcv
AgustinBettati Nov 8, 2024
5a6ef9a
adding warning to provide reduce possibility of re-applying fcv
AgustinBettati Nov 8, 2024
499f0fb
adding acceptance test
AgustinBettati Nov 11, 2024
8eea20a
adjust changelog entry file
AgustinBettati Nov 11, 2024
6e4e871
specify date format in docs
AgustinBettati Nov 11, 2024
45a1118
add step to verify incorrect format
AgustinBettati Nov 11, 2024
cbca7ad
Merge remote-tracking branch 'origin/master' into CLOUDP-283044
AgustinBettati Nov 11, 2024
7aeb017
add skipping in advanced_cluster tpf
AgustinBettati Nov 11, 2024
a5f16cc
add tpf limited implementation
AgustinBettati Nov 11, 2024
aacc4a9
adjust test and fix in plural data source to capture upgrade and down…
AgustinBettati Nov 21, 2024
ddea4c8
Merge remote-tracking branch 'origin/master' into CLOUDP-283044
AgustinBettati Nov 22, 2024
edf7780
handle warning when expiration date has passed
AgustinBettati Nov 22, 2024
2343474
add knowledge hub article reference
AgustinBettati Nov 22, 2024
3ca9938
adding example
AgustinBettati Nov 22, 2024
7576396
fix example formatting
AgustinBettati Nov 22, 2024
a044607
add changelog for mongo_db_major_version fix
AgustinBettati Nov 22, 2024
71010a5
applying doc review changes
AgustinBettati Nov 25, 2024
efce54f
Merge remote-tracking branch 'origin/master' into CLOUDP-283044
AgustinBettati Dec 9, 2024
5e9a526
adding link to new docs page
AgustinBettati Dec 9, 2024
0edf394
applying doc review changes
AgustinBettati Dec 10, 2024
7abdb5f
pr review comments
AgustinBettati Dec 10, 2024
5959d00
extract checks into unified function
AgustinBettati Dec 10, 2024
35ac611
minor refactors
AgustinBettati Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changelog/2789.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```release-note:enhancement
resource/mongodbatlas_advanced_cluster: Adds `pinned_fcv` attribute
```

```release-note:enhancement
data-source/mongodbatlas_advanced_cluster: Adds `pinned_fcv` attribute
```

```release-note:enhancement
data-source/mongodbatlas_advanced_clusters: Adds `pinned_fcv` attribute
```

```release-note:bug
resource/mongodbatlas_advanced_cluster: `mongo_db_major_version` attribute is populated with binary version when FCV pin is active
```

```release-note:bug
data-source/mongodbatlas_advanced_cluster: `mongo_db_major_version` attribute is populated with binary version when FCV pin is active
```

```release-note:bug
data-source/mongodbatlas_advanced_clusters: `mongo_db_major_version` attribute is populated with binary version when FCV pin is active
```
6 changes: 6 additions & 0 deletions docs/data-sources/advanced_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ In addition to all arguments above, the following attributes are exported:
* `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.
* `pinned_fcv` - The pinned Feature Compatibility Version (FCV) with its associated expiration date. See [below](#pinned_fcv).
* `pit_enabled` - Flag that indicates if the cluster uses Continuous Cloud Backup.
* `replication_specs` - List of settings that configure your cluster regions. If `use_replication_spec_per_shard = true`, 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).
* `root_cert_type` - Certificate Authority that MongoDB Atlas clusters use.
Expand Down Expand Up @@ -204,6 +205,11 @@ Key-value pairs that categorize the cluster. Each key and value has a maximum le
* `transaction_lifetime_limit_seconds` - Lifetime, in seconds, of multi-document transactions. Defaults to 60 seconds.
* `change_stream_options_pre_and_post_images_expire_after_seconds` - (Optional) The minimum pre- and post-image retention time in seconds This parameter is only supported for MongoDB version 6.0 and above. Defaults to `-1`(off).

### pinned_fcv

* `expiration_date` - Expiration date of the fixed FCV. This value is in the ISO 8601 timestamp format (e.g. "2024-12-04T16:25:00Z").
* `version` - Feature compatibility version of the cluster.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down
6 changes: 6 additions & 0 deletions docs/data-sources/advanced_clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ In addition to all arguments above, the following attributes are exported:
* `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).
* `mongo_db_major_version` - Version of the cluster to deploy.
* `pinned_fcv` - The pinned Feature Compatibility Version (FCV) with its associated expiration date. See [below](#pinned_fcv).
* `pit_enabled` - Flag that indicates if the cluster uses Continuous Cloud Backup.
* `replication_specs` - List of settings that configure your cluster regions. If `use_replication_spec_per_shard = true`, 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)
* `root_cert_type` - Certificate Authority that MongoDB Atlas clusters use.
Expand Down Expand Up @@ -207,6 +208,11 @@ Key-value pairs that categorize the cluster. Each key and value has a maximum le
* `transaction_lifetime_limit_seconds` - (Optional) Lifetime, in seconds, of multi-document transactions. Defaults to 60 seconds.
* `change_stream_options_pre_and_post_images_expire_after_seconds` - (Optional) The minimum pre- and post-image retention time in seconds. This parameter is only supported for MongoDB version 6.0 and above. Defaults to `-1`(off).

### pinned_fcv

* `expiration_date` - Expiration date of the fixed FCV. This value is in the ISO 8601 timestamp format (e.g. "2024-12-04T16:25:00Z").
* `version` - Feature compatibility version of the cluster.


## Attributes Reference

Expand Down
8 changes: 7 additions & 1 deletion docs/resources/advanced_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ This parameter defaults to false.
* `tags` - (Optional) Set that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the cluster. See [below](#tags).
* `labels` - (Optional) 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` - (Optional) Version of the cluster to deploy. Atlas supports all the MongoDB versions that have **not** reached [End of Live](https://www.mongodb.com/legal/support-policy/lifecycles) for M10+ clusters. If omitted, Atlas deploys the cluster with the default version. For more details, see [documentation](https://www.mongodb.com/docs/atlas/reference/faq/database/#which-versions-of-mongodb-do-service-clusters-use-). Atlas always deploys the cluster with the latest stable release of the specified version. If you set a value to this parameter and set `version_release_system` `CONTINUOUS`, the resource returns an error. Either clear this parameter or set `version_release_system`: `LTS`.
* `pit_enabled` - (Optional) - Flag that indicates if the cluster uses Continuous Cloud Backup.
* `pinned_fcv` - (Optional) Pins the Feature Compatibility Version (FCV) to the current MongoDB version with a provided expiration date. To unpin the FCV the `pinned_fcv` attribute must be removed. This operation can take several minutes as the request processes through the MongoDB data plane. Once FCV is unpinned it will not be possible to downgrade the `mongo_db_major_version`. It is advised that updates to `pinned_fcv` are done isolated from other cluster changes. If a plan contains multiple changes, the FCV change will be applied first. If FCV is unpinned past the expiration date the `pinned_fcv` attribute must be removed. 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. See [below](#pinned_fcv).
* `pit_enabled` - (Optional) Flag that indicates if the cluster uses Continuous Cloud Backup.
* `replication_specs` - List of settings that configure your cluster regions. This attribute has one object per shard representing node configurations in each shard. For replica sets there is only one object representing node configurations. If for each replication_spec `num_shards` is configured with a value greater than 1 (using deprecated sharding configurations), then each object represents a zone with one or more shards. See [below](#replication_specs)
* `root_cert_type` - (Optional) - Certificate Authority that MongoDB Atlas clusters use. You can specify ISRGROOTX1 (for ISRG Root X1).
* `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.
Expand Down Expand Up @@ -652,6 +653,11 @@ After adding the `lifecycle` block to explicitly change `instance_size` comment
* `compute_min_instance_size` - (Optional) Minimum instance size to which your cluster can automatically scale (such as M10). Atlas requires this parameter if `replication_specs.#.region_configs.#.analytics_auto_scaling.0.compute_scale_down_enabled` is true.
* `compute_max_instance_size` - (Optional) Maximum instance size to which your cluster can automatically scale (such as M40). Atlas requires this parameter if `replication_specs.#.region_configs.#.analytics_auto_scaling.0.compute_enabled` is true.

### pinned_fcv

* `expiration_date` - (Required) Expiration date of the fixed FCV. This value is in the ISO 8601 timestamp format (e.g. "2024-12-04T16:25:00Z"). Note that this field cannot exceed 4 weeks from the pinned date.
* `version` - Feature compatibility version of the cluster.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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.

The unpin operation can be performed by removing the `pinned_fcv` block. **Note**: Once FCV is unpinned it will not be possible to downgrade the `mongo_db_major_version`. If FCV is unpinned past the expiration date the `pinned_fcv` attribute must be removed.

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.

## Dependencies

* Terraform MongoDB Atlas Provider v1.23.0
* A MongoDB Atlas account

```
Terraform >= 0.13
+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.23.0
```


## Usage
**1\. Ensure your MongoDB Atlas credentials are set up.**

Following `variables.tf` file create **terraform.tfvars** file with all the variable values, as demonstrated below:
```
public_key = "<MONGODB_ATLAS_PUBLIC_KEY>"
private_key = "<MONGODB_ATLAS_PRIVATE_KEY>"
atlas_project_id = "<MONGODB_ATLAS_PROJECT_ID>"
fcv_expiration_date = "<FCV pin expiration date, e.g. 2024-11-22T10:50:00Z>"
```

**2\. Review the Terraform plan.**

Execute the following command.

``` bash
$ terraform plan
```
This project currently supports the following deployments:

- A Cluster with pinned FCV configured.

**3\. Execute the Terraform apply.**

Execute the following plan to provision the Atlas Project and Cluster resources.

``` bash
$ terraform apply
```

**4\. Destroy the resources.**

Once you finished your testing, ensure you destroy the resources to avoid unnecessary Atlas charges.

``` bash
$ terraform destroy
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
provider "mongodbatlas" {
public_key = var.public_key
private_key = var.private_key
}

resource "mongodbatlas_advanced_cluster" "cluster" {
project_id = var.project_id
name = "cluster"
cluster_type = "REPLICASET"

mongo_db_major_version = "7.0"

pinned_fcv {
expiration_date = var.fcv_expiration_date # e.g. format: "2024-11-22T10:50:00Z". Hashicorp time provider https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/offset can be used to compute this string value.
}

replication_specs {
region_configs {
electable_specs {
instance_size = "M10"
node_count = 3
}
provider_name = "AWS"
priority = 7
region_name = "EU_WEST_1"
}
}
}

output "feature_compatibility_version" {
value = mongodbatlas_advanced_cluster.cluster.pinned_fcv[0].version
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "project_id" {
description = "Atlas project 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 "fcv_expiration_date" {
description = "Expiration date of the pinned FCV"
type = string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "~> 1.22"
}
}
required_version = ">= 1.0"
}
33 changes: 17 additions & 16 deletions internal/service/advancedcluster/data_source_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ func DataSource() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"pinned_fcv": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"version": {
Type: schema.TypeString,
Computed: true,
},
"expiration_date": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -301,12 +317,6 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
if err != nil {
return diag.FromErr(fmt.Errorf(errorRead, clusterName, err))
}
if err := d.Set("replica_set_scaling_strategy", clusterDescNew.GetReplicaSetScalingStrategy()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "replica_set_scaling_strategy", clusterName, err))
}
if err := d.Set("redact_client_log_data", clusterDescNew.GetRedactClientLogData()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "redact_client_log_data", clusterName, err))
}

zoneNameToZoneIDs, err := getZoneIDsFromNewAPI(clusterDescNew)
if err != nil {
Expand All @@ -318,10 +328,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "replication_specs", clusterName, err))
}

clusterDesc := convertClusterDescToLatestExcludeRepSpecs(clusterDescOld)
clusterDesc.ConfigServerManagementMode = clusterDescNew.ConfigServerManagementMode
clusterDesc.ConfigServerType = clusterDescNew.ConfigServerType
diags := setRootFields(d, clusterDesc, false)
diags := setRootFields(d, clusterDescNew, false)
if diags.HasError() {
return diags
}
Expand All @@ -340,12 +347,6 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
if err := d.Set("disk_size_gb", GetDiskSizeGBFromReplicationSpec(clusterDescLatest)); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "disk_size_gb", clusterName, err))
}
if err := d.Set("replica_set_scaling_strategy", clusterDescLatest.GetReplicaSetScalingStrategy()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "replica_set_scaling_strategy", clusterName, err))
}
if err := d.Set("redact_client_log_data", clusterDescLatest.GetRedactClientLogData()); err != nil {
return diag.FromErr(fmt.Errorf(ErrorClusterAdvancedSetting, "redact_client_log_data", clusterName, err))
}

zoneNameToOldReplicationSpecIDs, err := getReplicationSpecIDsFromOldAPI(ctx, projectID, clusterName, connV220240530)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ func PluralDataSource() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"pinned_fcv": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"version": {
Type: schema.TypeString,
Computed: true,
},
"expiration_date": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
Expand Down Expand Up @@ -375,6 +391,7 @@ func flattenAdvancedClusters(ctx context.Context, connV220240530 *admin20240530.
"redact_client_log_data": cluster.GetRedactClientLogData(),
"config_server_management_mode": cluster.GetConfigServerManagementMode(),
"config_server_type": cluster.GetConfigServerType(),
"pinned_fcv": flattenPinnedFCV(cluster),
}
results = append(results, result)
}
Expand Down Expand Up @@ -419,7 +436,6 @@ func flattenAdvancedClustersOldSDK(ctx context.Context, connV20240530 *admin2024
"encryption_at_rest_provider": cluster.GetEncryptionAtRestProvider(),
"labels": flattenLabels(*convertLabelsToLatest(cluster.Labels)),
"tags": conversion.FlattenTags(convertTagsToLatest(cluster.GetTags())),
"mongo_db_major_version": cluster.GetMongoDBMajorVersion(),
"mongo_db_version": cluster.GetMongoDBVersion(),
"name": cluster.GetName(),
"paused": cluster.GetPaused(),
Expand All @@ -430,10 +446,12 @@ func flattenAdvancedClustersOldSDK(ctx context.Context, connV20240530 *admin2024
"termination_protection_enabled": cluster.GetTerminationProtectionEnabled(),
"version_release_system": cluster.GetVersionReleaseSystem(),
"global_cluster_self_managed_sharding": cluster.GetGlobalClusterSelfManagedSharding(),
"mongo_db_major_version": clusterDescNew.GetMongoDBMajorVersion(), // uses 2024-08-05 as it has fix for correct value when FCV is active
"replica_set_scaling_strategy": clusterDescNew.GetReplicaSetScalingStrategy(),
"redact_client_log_data": clusterDescNew.GetRedactClientLogData(),
"config_server_management_mode": clusterDescNew.GetConfigServerManagementMode(),
"config_server_type": clusterDescNew.GetConfigServerType(),
"pinned_fcv": flattenPinnedFCV(clusterDescNew),
}
results = append(results, result)
}
Expand Down
10 changes: 10 additions & 0 deletions internal/service/advancedcluster/model_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,16 @@ func CheckRegionConfigsPriorityOrderOld(regionConfigs []admin20240530.Replicatio
return nil
}

func flattenPinnedFCV(cluster *admin.ClusterDescription20240805) []map[string]string {
if cluster.FeatureCompatibilityVersionExpirationDate == nil { // pinned_fcv is defined in state only if featureCompatibilityVersionExpirationDate is present in cluster response
return nil
}
nestedObj := map[string]string{}
nestedObj["version"] = cluster.GetFeatureCompatibilityVersion()
nestedObj["expiration_date"] = conversion.TimeToString(cluster.GetFeatureCompatibilityVersionExpirationDate())
return []map[string]string{nestedObj}
}

func flattenConnectionStrings(str admin.ClusterConnectionStrings) []map[string]any {
return []map[string]any{
{
Expand Down
Loading
Loading