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 14 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
11 changes: 11 additions & 0 deletions .changelog/2785.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```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
```
6 changes: 6 additions & 0 deletions docs/data-sources/advanced_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,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 @@ -202,6 +203,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.
* `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 @@ -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).
* `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 @@ -205,6 +206,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.
* `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 @@ -383,7 +383,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. Once FCV has expired `pinned_fcv` attribute must be removed. 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 @@ -650,6 +651,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. 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
8 changes: 8 additions & 0 deletions internal/common/conversion/type_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ func StringToTime(str string) (time.Time, bool) {
return ret, err == nil
}

func StringPtrToTimePtr(str *string) (*time.Time, bool) {
if str == nil {
return nil, true
}
res, ok := StringToTime(*str)
return &res, ok
}

func Int64PtrToIntPtr(i64 *int64) *int {
if i64 == nil {
return nil
Expand Down
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 @@ -434,6 +451,7 @@ func flattenAdvancedClustersOldSDK(ctx context.Context, connV20240530 *admin2024
"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.FeatureCompatibilityVersion == nil { // pinned_fcv is defined in state only if featureCompatibilityVersion is present in cluster response
return nil
}
nestedObj := map[string]string{}
nestedObj["version"] = cluster.GetFeatureCompatibilityVersion()
nestedObj["expiration_date"] = *conversion.TimePtrToStringPtr(cluster.FeatureCompatibilityVersionExpirationDate)
Copy link
Member

@lantoli lantoli Dec 9, 2024

Choose a reason for hiding this comment

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

Suggested change
nestedObj := map[string]string{}
nestedObj["version"] = cluster.GetFeatureCompatibilityVersion()
nestedObj["expiration_date"] = *conversion.TimePtrToStringPtr(cluster.FeatureCompatibilityVersionExpirationDate)
nestedObj := map[string]string{
"version": cluster.GetFeatureCompatibilityVersion(),
"expiration_date": *conversion.TimePtrToStringPtr(cluster.FeatureCompatibilityVersionExpirationDate),
}

Copy link
Member

Choose a reason for hiding this comment

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

TimePtrToStringPtr might return nil so * will panic, better to check, or create a TimePtrToString func or similar

Copy link
Member Author

Choose a reason for hiding this comment

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

There is an if just above that ensure FeatureCompatibilityVersionExpirationDate will not be nil. Modified this statement to use TimeToString directly 👍

return []map[string]string{nestedObj}
}

func flattenConnectionStrings(str admin.ClusterConnectionStrings) []map[string]any {
return []map[string]any{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ import (
// - These functions must not contain any business logic.
// - All will be removed once we rely on a single API version.

func convertTagsPtrToLatest(tags *[]admin20240530.ResourceTag) *[]admin.ResourceTag {
if tags == nil {
return nil
}
result := convertTagsToLatest(*tags)
return &result
}

func convertTagsPtrToOldSDK(tags *[]admin20240805.ResourceTag) *[]admin20240530.ResourceTag {
if tags == nil {
return nil
Expand Down Expand Up @@ -298,30 +290,3 @@ func convertRegionConfigSliceToLatest(slice *[]admin20240530.CloudRegionConfig,
}
return &results
}

func convertClusterDescToLatestExcludeRepSpecs(oldClusterDesc *admin20240530.AdvancedClusterDescription) *admin.ClusterDescription20240805 {
return &admin.ClusterDescription20240805{
BackupEnabled: oldClusterDesc.BackupEnabled,
AcceptDataRisksAndForceReplicaSetReconfig: oldClusterDesc.AcceptDataRisksAndForceReplicaSetReconfig,
ClusterType: oldClusterDesc.ClusterType,
CreateDate: oldClusterDesc.CreateDate,
DiskWarmingMode: oldClusterDesc.DiskWarmingMode,
EncryptionAtRestProvider: oldClusterDesc.EncryptionAtRestProvider,
GlobalClusterSelfManagedSharding: oldClusterDesc.GlobalClusterSelfManagedSharding,
GroupId: oldClusterDesc.GroupId,
Id: oldClusterDesc.Id,
MongoDBMajorVersion: oldClusterDesc.MongoDBMajorVersion,
MongoDBVersion: oldClusterDesc.MongoDBVersion,
Name: oldClusterDesc.Name,
Paused: oldClusterDesc.Paused,
PitEnabled: oldClusterDesc.PitEnabled,
RootCertType: oldClusterDesc.RootCertType,
StateName: oldClusterDesc.StateName,
TerminationProtectionEnabled: oldClusterDesc.TerminationProtectionEnabled,
VersionReleaseSystem: oldClusterDesc.VersionReleaseSystem,
Tags: convertTagsPtrToLatest(oldClusterDesc.Tags),
BiConnector: convertBiConnectToLatest(oldClusterDesc.BiConnector),
ConnectionStrings: convertConnectionStringToLatest(oldClusterDesc.ConnectionStrings),
Labels: convertLabelsToLatest(oldClusterDesc.Labels),
}
}
Loading
Loading