Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ rpdk.log
#compiled file
bin/

#vendor
vendor/

create.json
delete.json
update.json
Expand Down
39 changes: 31 additions & 8 deletions cfn-resources/cluster/cmd/resource/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import (
"fmt"
"reflect"

"go.mongodb.org/atlas-sdk/v20231115014/admin"

"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/spf13/cast"

"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
"github.com/spf13/cast"
"go.mongodb.org/atlas-sdk/v20231115014/admin"
)

func mapClusterToModel(model *Model, cluster *admin.AdvancedClusterDescription) {
Expand Down Expand Up @@ -374,20 +376,27 @@ func flattenPrivateEndpoint(pes *[]admin.ClusterDescriptionConnectionStringsPriv
return privateEndpoints
}

func flattenProcessArgs(p *admin.ClusterDescriptionProcessArgs) *ProcessArgs {
return &ProcessArgs{
func flattenProcessArgs(p *admin.ClusterDescriptionProcessArgs, cluster *admin.AdvancedClusterDescription) *ProcessArgs {
res := &ProcessArgs{
DefaultReadConcern: p.DefaultReadConcern,
DefaultWriteConcern: p.DefaultWriteConcern,
FailIndexKeyTooLong: p.FailIndexKeyTooLong,
JavascriptEnabled: p.JavascriptEnabled,
MinimumEnabledTLSProtocol: p.MinimumEnabledTlsProtocol,
Copy link
Member

Choose a reason for hiding this comment

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

shoudn't we keep reading MinimumEnabledTLSProtocol from here in case advConfig is nil?

Copy link
Member

Choose a reason for hiding this comment

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

I see flattenProcessArgs is called in read only if advancedConfig is defined by the user

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 see flattenProcessArgs is called in read only if advancedConfig is defined by the user

right

shoudn't we keep reading MinimumEnabledTLSProtocol from here in case advConfig is nil?

no I think for consistency we should stick to one API

NoTableScan: p.NoTableScan,
OplogSizeMB: p.OplogSizeMB,
SampleSizeBIConnector: p.SampleSizeBIConnector,
SampleRefreshIntervalBIConnector: p.SampleRefreshIntervalBIConnector,
OplogMinRetentionHours: p.OplogMinRetentionHours,
TransactionLifetimeLimitSeconds: util.Int64PtrToIntPtr(p.TransactionLifetimeLimitSeconds),
}

if advConfig := cluster.AdvancedConfiguration; advConfig != nil {
res.MinimumEnabledTLSProtocol = advConfig.MinimumEnabledTlsProtocol
res.TlsCipherConfigMode = advConfig.TlsCipherConfigMode
res.CustomOpensslCipherConfigTls12 = advConfig.GetCustomOpensslCipherConfigTls12()
}

return res
}

func flattenLabels(clusterLabels []admin.ComponentLabel) []Labels {
Expand All @@ -412,9 +421,7 @@ func expandAdvancedSettings(processArgs ProcessArgs) *admin.ClusterDescriptionPr
args.DefaultWriteConcern = processArgs.DefaultWriteConcern
}
args.JavascriptEnabled = processArgs.JavascriptEnabled
if processArgs.MinimumEnabledTLSProtocol != nil {
args.MinimumEnabledTlsProtocol = processArgs.MinimumEnabledTLSProtocol
}

args.NoTableScan = processArgs.NoTableScan

if processArgs.OplogSizeMB != nil {
Expand Down Expand Up @@ -593,9 +600,25 @@ func setClusterRequest(currentModel *Model) (*admin.AdvancedClusterDescription,
clusterRequest.Tags = tags

clusterRequest.TerminationProtectionEnabled = currentModel.TerminationProtectionEnabled

clusterRequest.AdvancedConfiguration = expandClusterAdvancedConfiguration(*currentModel.AdvancedSettings)
return clusterRequest, nil
}

func expandClusterAdvancedConfiguration(processArgs ProcessArgs) *admin.ApiAtlasClusterAdvancedConfiguration {
var args admin.ApiAtlasClusterAdvancedConfiguration

if processArgs.MinimumEnabledTLSProtocol != nil {
args.MinimumEnabledTlsProtocol = processArgs.MinimumEnabledTLSProtocol
}
if processArgs.TlsCipherConfigMode != nil {
args.TlsCipherConfigMode = processArgs.TlsCipherConfigMode
}
args.CustomOpensslCipherConfigTls12 = &processArgs.CustomOpensslCipherConfigTls12
Copy link
Member

@lantoli lantoli May 6, 2025

Choose a reason for hiding this comment

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

similar to before, do we want to check if processArgs.CustomOpensslCipherConfigTls12 is nil? or maybe we can have if len(processArgs.CustomOpensslCipherConfigTls12) > 0 ...


return &args
}

func AddReplicationSpecIDs(src, dest []admin.ReplicationSpec) *[]admin.ReplicationSpec {
zoneToID := map[string]string{}
providerRegionToID := map[string]string{}
Expand Down
2 changes: 2 additions & 0 deletions cfn-resources/cluster/cmd/resource/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions cfn-resources/cluster/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ import (
"net/http"
"strings"

"go.mongodb.org/atlas-sdk/v20231115014/admin"

"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/spf13/cast"

"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
"github.com/spf13/cast"
"go.mongodb.org/atlas-sdk/v20231115014/admin"
)

const (
Expand Down Expand Up @@ -309,7 +311,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
return progressevent.GetFailedEventByResponse(fmt.Sprintf("Error creating resource : %s", err.Error()),
res), nil
}
model.AdvancedSettings = flattenProcessArgs(processArgs)
model.AdvancedSettings = flattenProcessArgs(processArgs, &clusterResults[i])
models[i] = model
}

Expand Down Expand Up @@ -395,7 +397,7 @@ func readCluster(ctx context.Context, client *util.MongoDBClient, currentModel *
if errr != nil || resp.StatusCode != http.StatusOK {
return currentModel, resp, errr
}
currentModel.AdvancedSettings = flattenProcessArgs(processArgs)
currentModel.AdvancedSettings = flattenProcessArgs(processArgs, cluster)
}
return currentModel, res, err
}
Expand Down
25 changes: 25 additions & 0 deletions cfn-resources/cluster/docs/processargs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ To declare this entity in your AWS CloudFormation template, use the following sy
"<a href="#failindexkeytoolong" title="FailIndexKeyTooLong">FailIndexKeyTooLong</a>" : <i>Boolean</i>,
"<a href="#javascriptenabled" title="JavascriptEnabled">JavascriptEnabled</a>" : <i>Boolean</i>,
"<a href="#minimumenabledtlsprotocol" title="MinimumEnabledTLSProtocol">MinimumEnabledTLSProtocol</a>" : <i>String</i>,
"<a href="#tlscipherconfigmode" title="TlsCipherConfigMode">TlsCipherConfigMode</a>" : <i>String</i>,
"<a href="#customopensslcipherconfigtls12" title="CustomOpensslCipherConfigTls12">CustomOpensslCipherConfigTls12</a>" : <i>[ String, ... ]</i>,
"<a href="#notablescan" title="NoTableScan">NoTableScan</a>" : <i>Boolean</i>,
"<a href="#oplogsizemb" title="OplogSizeMB">OplogSizeMB</a>" : <i>Integer</i>,
"<a href="#samplesizebiconnector" title="SampleSizeBIConnector">SampleSizeBIConnector</a>" : <i>Integer</i>,
Expand All @@ -32,6 +34,9 @@ To declare this entity in your AWS CloudFormation template, use the following sy
<a href="#failindexkeytoolong" title="FailIndexKeyTooLong">FailIndexKeyTooLong</a>: <i>Boolean</i>
<a href="#javascriptenabled" title="JavascriptEnabled">JavascriptEnabled</a>: <i>Boolean</i>
<a href="#minimumenabledtlsprotocol" title="MinimumEnabledTLSProtocol">MinimumEnabledTLSProtocol</a>: <i>String</i>
<a href="#tlscipherconfigmode" title="TlsCipherConfigMode">TlsCipherConfigMode</a>: <i>String</i>
<a href="#customopensslcipherconfigtls12" title="CustomOpensslCipherConfigTls12">CustomOpensslCipherConfigTls12</a>: <i>
- String</i>
<a href="#notablescan" title="NoTableScan">NoTableScan</a>: <i>Boolean</i>
<a href="#oplogsizemb" title="OplogSizeMB">OplogSizeMB</a>: <i>Integer</i>
<a href="#samplesizebiconnector" title="SampleSizeBIConnector">SampleSizeBIConnector</a>: <i>Integer</i>
Expand Down Expand Up @@ -92,6 +97,26 @@ _Type_: String

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### TlsCipherConfigMode

The TLS cipher suite configuration mode. Valid values include `CUSTOM` or `DEFAULT`. The `DEFAULT` mode uses the default cipher suites. The `CUSTOM` mode allows you to specify custom cipher suites for both TLS 1.2 and TLS 1.3. To unset, this should be set back to `DEFAULT`.

_Required_: No

_Type_: String

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### CustomOpensslCipherConfigTls12

The custom OpenSSL cipher suite list for TLS 1.2. This field is only valid when `tls_cipher_config_mode` is set to `CUSTOM`.

_Required_: No

_Type_: List of String

_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

#### NoTableScan

Flag that indicates whether the cluster disables executing any query that requires a collection scan to return results.
Expand Down
12 changes: 12 additions & 0 deletions cfn-resources/cluster/mongodb-atlas-cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@
"type": "string",
"description": "Minimum Transport Layer Security (TLS) version that the cluster accepts for incoming connections. Clusters using TLS 1.0 or 1.1 should consider setting TLS 1.2 as the minimum TLS protocol version."
},
"TlsCipherConfigMode": {
"type": "string",
"description": "The TLS cipher suite configuration mode. Valid values include `CUSTOM` or `DEFAULT`. The `DEFAULT` mode uses the default cipher suites. The `CUSTOM` mode allows you to specify custom cipher suites for both TLS 1.2 and TLS 1.3. To unset, this should be set back to `DEFAULT`."
},
"CustomOpensslCipherConfigTls12": {
"type": "array",
"insertionOrder": false,
"items": {
"type": "string"
},
"description": "The custom OpenSSL cipher suite list for TLS 1.2. This field is only valid when `tls_cipher_config_mode` is set to `CUSTOM`."
},
"NoTableScan": {
"type": "boolean",
"description": "Flag that indicates whether the cluster disables executing any query that requires a collection scan to return results."
Expand Down
5 changes: 5 additions & 0 deletions cfn-resources/cluster/test/inputs_1_update.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"DefaultWriteConcern": "1",
"JavascriptEnabled": "false",
"MinimumEnabledTLSProtocol": "TLS1_2",
"TlsCipherConfigMode": "CUSTOM",
"CustomOpensslCipherConfigTls12": [
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
],
"NoTableScan": "false",
"OplogSizeMB": "4000",
"SampleSizeBIConnector": "110",
Expand Down
5 changes: 4 additions & 1 deletion cfn-resources/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module github.com/mongodb/mongodbatlas-cloudformation-resources

go 1.23.1

// Replacing with local copy of Atlas SDK v20231115014 to support new AdvancedConfiguration in *admin.AdvancedClusterDescription
replace go.mongodb.org/atlas-sdk/v20231115014 => ../vendor/go.mongodb.org/atlas-sdk/v20231115014

require (
github.com/aws-cloudformation/cloudformation-cli-go-plugin v1.2.0
github.com/aws/aws-sdk-go v1.55.7
Expand All @@ -19,7 +22,7 @@ require (
github.com/stretchr/testify v1.10.0
github.com/tidwall/pretty v1.2.1
go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.1
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.0
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0
)

Expand Down
2 changes: 0 additions & 2 deletions cfn-resources/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ go.mongodb.org/atlas v0.37.0 h1:zQnO1o5+bVP9IotpAYpres4UjMD2F4nwNEFTZhNL4ck=
go.mongodb.org/atlas v0.37.0/go.mod h1:DJYtM+vsEpPEMSkQzJnFHrT0sP7ev6cseZc/GGjJYG8=
go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0 h1:x6nnq2pUIP9mN4WLD4/EseBzV88OmSgexxYchPilgno=
go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0/go.mod h1:el7cm23kEiiw72HAYimhNweKqp/ubHsNJk+Mk30yJhM=
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.1 h1:l+SxbeIK+3RmpSBq6MPfUEsQeQZHQ0pjTxeZQdNRFlA=
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.1/go.mod h1:pCl46YnWOIde8lq27whXDwUseNeUvtAy3vy5ZDeTcBA=
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0 h1:KX8PrYp3/PCSxG4NbGLcc3+EsNcfyhcvylGbe/oRlx8=
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0/go.mod h1:HHCmHxHPdJRr1bUXlvRIZbm7M4gRujjur1GnjE44YgA=
golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=
Expand Down
7 changes: 6 additions & 1 deletion cfn-resources/test/e2e/cluster/cluster.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
"NoTableScan": "false",
"OplogSizeMB": "2000",
"SampleSizeBIConnector": "110",
"SampleRefreshIntervalBIConnector": "310"
"SampleRefreshIntervalBIConnector": "310",
"TlsCipherConfigMode": "CUSTOM",
"CustomOpensslCipherConfigTls12": [
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
]
},
"BackupEnabled": "false",
"ClusterType": "GEOSHARDED",
Expand Down
9 changes: 7 additions & 2 deletions examples/cluster/cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
"NoTableScan": "false",
"OplogSizeMB": "2000",
"SampleSizeBIConnector": "110",
"SampleRefreshIntervalBIConnector": "310"
"SampleRefreshIntervalBIConnector": "310",
"TlsCipherConfigMode": "CUSTOM",
"CustomOpensslCipherConfigTls12": [
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
]
},
"BackupEnabled": "true",
"ClusterType": "REPLICASET",
Expand Down Expand Up @@ -122,4 +127,4 @@
}
}
}
}
}
Loading
Loading