diff --git a/cyral/internal/repository/resource_cyral_repository.go b/cyral/internal/repository/resource_cyral_repository.go index d594c08e..1d1631fb 100644 --- a/cyral/internal/repository/resource_cyral_repository.go +++ b/cyral/internal/repository/resource_cyral_repository.go @@ -32,6 +32,7 @@ const ( RepoMongoDBReplicaSetNameKey = "replica_set_name" RepoMongoDBServerTypeKey = "server_type" RepoMongoDBSRVRecordName = "srv_record_name" + RepoMongoDBFlavorKey = "flavor" ) const ( @@ -76,6 +77,11 @@ const ( Sharded = "sharded" ) +const ( + MongoDBFlavorMongoDB = "mongodb" + MongoDBFlavorDocumentDB = "documentdb" +) + func mongoServerTypes() []string { return []string{ ReplicaSet, @@ -84,6 +90,13 @@ func mongoServerTypes() []string { } } +func mongoFlavors() []string { + return []string{ + MongoDBFlavorMongoDB, + MongoDBFlavorDocumentDB, + } +} + type RepoInfo struct { ID string `json:"id"` Name string `json:"name"` @@ -109,6 +122,7 @@ type MongoDBSettings struct { ReplicaSetName string `json:"replicaSetName,omitempty"` ServerType string `json:"serverType,omitempty"` SRVRecordName string `json:"srvRecordName,omitempty"` + Flavor string `json:"flavor,omitempty"` } type RepoNode struct { @@ -237,6 +251,7 @@ func (r *RepoInfo) MongoDBSettingsAsInterface() []interface{} { RepoMongoDBReplicaSetNameKey: r.MongoDBSettings.ReplicaSetName, RepoMongoDBServerTypeKey: r.MongoDBSettings.ServerType, RepoMongoDBSRVRecordName: r.MongoDBSettings.SRVRecordName, + RepoMongoDBFlavorKey: r.MongoDBSettings.Flavor, }} } @@ -267,6 +282,7 @@ func (r *RepoInfo) MongoDBSettingsFromInterface(i []interface{}) error { ReplicaSetName: i[0].(map[string]interface{})[RepoMongoDBReplicaSetNameKey].(string), ServerType: i[0].(map[string]interface{})[RepoMongoDBServerTypeKey].(string), SRVRecordName: i[0].(map[string]interface{})[RepoMongoDBSRVRecordName].(string), + Flavor: i[0].(map[string]interface{})[RepoMongoDBFlavorKey].(string), } return nil } @@ -467,6 +483,14 @@ func ResourceRepository() *schema.Resource { Type: schema.TypeString, Optional: true, }, + RepoMongoDBFlavorKey: { + Description: "The flavor of the MongoDB deployment. Allowed values: " + utils.SupportedValuesAsMarkdown(mongoFlavors()) + + "\n\n The following conditions apply:\n" + + " - The `" + MongoDBFlavorDocumentDB + "` flavor cannot be combined with the MongoDB Server type `" + Sharded + "`.\n", + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(mongoFlavors(), false), + }, }, }, }, diff --git a/cyral/internal/repository/resource_cyral_repository_test.go b/cyral/internal/repository/resource_cyral_repository_test.go index bca4824c..5ce9a2e7 100644 --- a/cyral/internal/repository/resource_cyral_repository_test.go +++ b/cyral/internal/repository/resource_cyral_repository_test.go @@ -115,6 +115,7 @@ var ( MongoDBSettings: &repository.MongoDBSettings{ ReplicaSetName: "some-replica-set", ServerType: repository.ReplicaSet, + Flavor: "mongodb", }, } @@ -136,6 +137,7 @@ var ( ReplicaSetName: "myReplicaSet", ServerType: "replicaset", SRVRecordName: "mySRVRecord", + Flavor: "documentdb", }, } ) @@ -236,6 +238,13 @@ func repoCheckFuctions(repo repository.RepoInfo, resName string) resource.TestCh repo.MongoDBSettings.ReplicaSetName), }...) } + if repo.MongoDBSettings.Flavor != "" { + checkFuncs = append(checkFuncs, []resource.TestCheckFunc{ + resource.TestCheckResourceAttr(resourceFullName, + "mongodb_settings.0.flavor", + repo.MongoDBSettings.Flavor), + }...) + } checkFuncs = append(checkFuncs, []resource.TestCheckFunc{ resource.TestCheckResourceAttr(resourceFullName, "mongodb_settings.0.server_type", diff --git a/docker-compose.yaml b/docker-compose.yaml index fbdeed5c..f62f02d5 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,6 +4,8 @@ services: app: image: golang:1.21 container_name: terraform_provider_cyral + environment: + - GOFLAGS=-buildvcs=false volumes: - .:/go/src/terraform-provider-cyral working_dir: /go/src/terraform-provider-cyral diff --git a/docs/resources/repository.md b/docs/resources/repository.md index 514fc39f..a1cbf55f 100644 --- a/docs/resources/repository.md +++ b/docs/resources/repository.md @@ -164,5 +164,14 @@ Required: Optional: +- `flavor` (String) The flavor of the MongoDB deployment. Allowed values: + + - `mongodb` + - `documentdb` + + The following conditions apply: + + - The `documentdb` flavor cannot be combined with the MongoDB Server type `sharded`. + - `replica_set_name` (String) Name of the replica set, if applicable. - `srv_record_name` (String) Name of a DNS SRV record which contains cluster topology details. If specified, then all `repo_node` blocks must be declared dynamic (see [`dynamic`](#dynamic)). Only supported for `server_type="sharded"` or `server_type="replicaset".