Skip to content

Commit 9e1b2ad

Browse files
committed
use cluster APIs to support certain processArgs
1 parent dc3828f commit 9e1b2ad

File tree

9 files changed

+91
-15
lines changed

9 files changed

+91
-15
lines changed

cfn-resources/cluster/cmd/resource/mappings.go

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ import (
1919
"fmt"
2020
"reflect"
2121

22+
"go.mongodb.org/atlas-sdk/v20231115014/admin"
23+
2224
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
2325
"github.com/aws/aws-sdk-go/service/cloudformation"
26+
"github.com/spf13/cast"
27+
2428
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
2529
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
26-
"github.com/spf13/cast"
27-
"go.mongodb.org/atlas-sdk/v20231115014/admin"
2830
)
2931

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

377-
func flattenProcessArgs(p *admin.ClusterDescriptionProcessArgs) *ProcessArgs {
378-
return &ProcessArgs{
379+
func flattenProcessArgs(p *admin.ClusterDescriptionProcessArgs, cluster *admin.AdvancedClusterDescription) *ProcessArgs {
380+
res := &ProcessArgs{
379381
DefaultReadConcern: p.DefaultReadConcern,
380382
DefaultWriteConcern: p.DefaultWriteConcern,
381383
FailIndexKeyTooLong: p.FailIndexKeyTooLong,
382384
JavascriptEnabled: p.JavascriptEnabled,
383-
MinimumEnabledTLSProtocol: p.MinimumEnabledTlsProtocol,
384385
NoTableScan: p.NoTableScan,
385386
OplogSizeMB: p.OplogSizeMB,
386387
SampleSizeBIConnector: p.SampleSizeBIConnector,
387388
SampleRefreshIntervalBIConnector: p.SampleRefreshIntervalBIConnector,
388389
OplogMinRetentionHours: p.OplogMinRetentionHours,
389390
TransactionLifetimeLimitSeconds: util.Int64PtrToIntPtr(p.TransactionLifetimeLimitSeconds),
390391
}
392+
393+
if advConfig := cluster.AdvancedConfiguration; advConfig != nil {
394+
res.MinimumEnabledTLSProtocol = advConfig.MinimumEnabledTlsProtocol
395+
res.TlsCipherConfigMode = advConfig.TlsCipherConfigMode
396+
res.CustomOpensslCipherConfigTls12 = *advConfig.CustomOpensslCipherConfigTls12
397+
}
398+
399+
return res
391400
}
392401

393402
func flattenLabels(clusterLabels []admin.ComponentLabel) []Labels {
@@ -412,9 +421,7 @@ func expandAdvancedSettings(processArgs ProcessArgs) *admin.ClusterDescriptionPr
412421
args.DefaultWriteConcern = processArgs.DefaultWriteConcern
413422
}
414423
args.JavascriptEnabled = processArgs.JavascriptEnabled
415-
if processArgs.MinimumEnabledTLSProtocol != nil {
416-
args.MinimumEnabledTlsProtocol = processArgs.MinimumEnabledTLSProtocol
417-
}
424+
418425
args.NoTableScan = processArgs.NoTableScan
419426

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

595602
clusterRequest.TerminationProtectionEnabled = currentModel.TerminationProtectionEnabled
603+
604+
clusterRequest.AdvancedConfiguration = expandClusterAdvancedConfiguration(*currentModel.AdvancedSettings)
596605
return clusterRequest, nil
597606
}
598607

608+
func expandClusterAdvancedConfiguration(processArgs ProcessArgs) *admin.ApiAtlasClusterAdvancedConfiguration {
609+
var args admin.ApiAtlasClusterAdvancedConfiguration
610+
611+
if processArgs.MinimumEnabledTLSProtocol != nil {
612+
args.MinimumEnabledTlsProtocol = processArgs.MinimumEnabledTLSProtocol
613+
}
614+
if processArgs.TlsCipherConfigMode != nil {
615+
args.TlsCipherConfigMode = processArgs.TlsCipherConfigMode
616+
}
617+
args.CustomOpensslCipherConfigTls12 = &processArgs.CustomOpensslCipherConfigTls12
618+
619+
return &args
620+
}
621+
599622
func AddReplicationSpecIDs(src, dest []admin.ReplicationSpec) *[]admin.ReplicationSpec {
600623
zoneToID := map[string]string{}
601624
providerRegionToID := map[string]string{}

cfn-resources/cluster/cmd/resource/model.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cfn-resources/cluster/cmd/resource/resource.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ import (
2121
"net/http"
2222
"strings"
2323

24+
"go.mongodb.org/atlas-sdk/v20231115014/admin"
25+
2426
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
2527
"github.com/aws/aws-sdk-go/aws"
2628
"github.com/aws/aws-sdk-go/service/cloudformation"
29+
"github.com/spf13/cast"
30+
2731
"github.com/mongodb/mongodbatlas-cloudformation-resources/util"
2832
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants"
2933
log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
3034
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
3135
"github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
32-
"github.com/spf13/cast"
33-
"go.mongodb.org/atlas-sdk/v20231115014/admin"
3436
)
3537

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

@@ -395,7 +397,7 @@ func readCluster(ctx context.Context, client *util.MongoDBClient, currentModel *
395397
if errr != nil || resp.StatusCode != http.StatusOK {
396398
return currentModel, resp, errr
397399
}
398-
currentModel.AdvancedSettings = flattenProcessArgs(processArgs)
400+
currentModel.AdvancedSettings = flattenProcessArgs(processArgs, cluster)
399401
}
400402
return currentModel, res, err
401403
}

cfn-resources/cluster/docs/processargs.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ To declare this entity in your AWS CloudFormation template, use the following sy
1515
"<a href="#failindexkeytoolong" title="FailIndexKeyTooLong">FailIndexKeyTooLong</a>" : <i>Boolean</i>,
1616
"<a href="#javascriptenabled" title="JavascriptEnabled">JavascriptEnabled</a>" : <i>Boolean</i>,
1717
"<a href="#minimumenabledtlsprotocol" title="MinimumEnabledTLSProtocol">MinimumEnabledTLSProtocol</a>" : <i>String</i>,
18+
"<a href="#tlscipherconfigmode" title="TlsCipherConfigMode">TlsCipherConfigMode</a>" : <i>String</i>,
19+
"<a href="#customopensslcipherconfigtls12" title="CustomOpensslCipherConfigTls12">CustomOpensslCipherConfigTls12</a>" : <i>[ String, ... ]</i>,
1820
"<a href="#notablescan" title="NoTableScan">NoTableScan</a>" : <i>Boolean</i>,
1921
"<a href="#oplogsizemb" title="OplogSizeMB">OplogSizeMB</a>" : <i>Integer</i>,
2022
"<a href="#samplesizebiconnector" title="SampleSizeBIConnector">SampleSizeBIConnector</a>" : <i>Integer</i>,
@@ -32,6 +34,9 @@ To declare this entity in your AWS CloudFormation template, use the following sy
3234
<a href="#failindexkeytoolong" title="FailIndexKeyTooLong">FailIndexKeyTooLong</a>: <i>Boolean</i>
3335
<a href="#javascriptenabled" title="JavascriptEnabled">JavascriptEnabled</a>: <i>Boolean</i>
3436
<a href="#minimumenabledtlsprotocol" title="MinimumEnabledTLSProtocol">MinimumEnabledTLSProtocol</a>: <i>String</i>
37+
<a href="#tlscipherconfigmode" title="TlsCipherConfigMode">TlsCipherConfigMode</a>: <i>String</i>
38+
<a href="#customopensslcipherconfigtls12" title="CustomOpensslCipherConfigTls12">CustomOpensslCipherConfigTls12</a>: <i>
39+
- String</i>
3540
<a href="#notablescan" title="NoTableScan">NoTableScan</a>: <i>Boolean</i>
3641
<a href="#oplogsizemb" title="OplogSizeMB">OplogSizeMB</a>: <i>Integer</i>
3742
<a href="#samplesizebiconnector" title="SampleSizeBIConnector">SampleSizeBIConnector</a>: <i>Integer</i>
@@ -92,6 +97,26 @@ _Type_: String
9297

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

100+
#### TlsCipherConfigMode
101+
102+
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`.
103+
104+
_Required_: No
105+
106+
_Type_: String
107+
108+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
109+
110+
#### CustomOpensslCipherConfigTls12
111+
112+
The custom OpenSSL cipher suite list for TLS 1.2. This field is only valid when `tls_cipher_config_mode` is set to `CUSTOM`.
113+
114+
_Required_: No
115+
116+
_Type_: List of String
117+
118+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
119+
95120
#### NoTableScan
96121

97122
Flag that indicates whether the cluster disables executing any query that requires a collection scan to return results.

cfn-resources/cluster/mongodb-atlas-cluster.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,18 @@
249249
"type": "string",
250250
"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."
251251
},
252+
"TlsCipherConfigMode": {
253+
"type": "string",
254+
"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`."
255+
},
256+
"CustomOpensslCipherConfigTls12": {
257+
"type": "array",
258+
"insertionOrder": false,
259+
"items": {
260+
"type": "string"
261+
},
262+
"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`."
263+
},
252264
"NoTableScan": {
253265
"type": "boolean",
254266
"description": "Flag that indicates whether the cluster disables executing any query that requires a collection scan to return results."

cfn-resources/cluster/test/inputs_1_update.template.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
"DefaultWriteConcern": "1",
88
"JavascriptEnabled": "false",
99
"MinimumEnabledTLSProtocol": "TLS1_2",
10+
"TlsCipherConfigMode": "CUSTOM",
11+
"CustomOpensslCipherConfigTls12": [
12+
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
13+
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
14+
],
1015
"NoTableScan": "false",
1116
"OplogSizeMB": "4000",
1217
"SampleSizeBIConnector": "110",

cfn-resources/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/stretchr/testify v1.10.0
2020
github.com/tidwall/pretty v1.2.1
2121
go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0
22-
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.0
22+
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.1-0.20250501203224-d289267fb00f
2323
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0
2424
)
2525

cfn-resources/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0 h1:x6nnq2pUIP9mN4WLD4/Ese
105105
go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0/go.mod h1:el7cm23kEiiw72HAYimhNweKqp/ubHsNJk+Mk30yJhM=
106106
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.0 h1:hN7x3m6THf03q/tE48up1j0U/26lJmx+s1LXB/qvHHc=
107107
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.0/go.mod h1:pCl46YnWOIde8lq27whXDwUseNeUvtAy3vy5ZDeTcBA=
108+
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.1-0.20250501203224-d289267fb00f h1:N5VEDjQhHAfS8RUBjHkkNqTi0qeiON5gML9YcLxJXQ8=
109+
go.mongodb.org/atlas-sdk/v20231115014 v20231115014.0.1-0.20250501203224-d289267fb00f/go.mod h1:pCl46YnWOIde8lq27whXDwUseNeUvtAy3vy5ZDeTcBA=
108110
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0 h1:KX8PrYp3/PCSxG4NbGLcc3+EsNcfyhcvylGbe/oRlx8=
109111
go.mongodb.org/atlas-sdk/v20250312002 v20250312002.0.0/go.mod h1:HHCmHxHPdJRr1bUXlvRIZbm7M4gRujjur1GnjE44YgA=
110112
golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=

examples/cluster/cluster.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@
4141
"NoTableScan": "false",
4242
"OplogSizeMB": "2000",
4343
"SampleSizeBIConnector": "110",
44-
"SampleRefreshIntervalBIConnector": "310"
44+
"SampleRefreshIntervalBIConnector": "310",
45+
"TlsCipherConfigMode": "CUSTOM",
46+
"CustomOpensslCipherConfigTls12": [
47+
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
48+
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
49+
]
4550
},
4651
"BackupEnabled": "true",
4752
"ClusterType": "REPLICASET",
@@ -122,4 +127,4 @@
122127
}
123128
}
124129
}
125-
}
130+
}

0 commit comments

Comments
 (0)