From d0f5fda6ebd663b02b072e43330fbd233e8bb9db Mon Sep 17 00:00:00 2001 From: Tongyao Si Date: Tue, 17 Dec 2019 18:53:16 +0800 Subject: [PATCH] Support creating v3.6 mongoDB account (#732) * Support creating v3.6 mongoDB * Add e2e test * fix: lint --- docs/modules/cosmosdb.md | 1 + pkg/services/cosmosdb/catalog.go | 4 ++-- pkg/services/cosmosdb/mongodb-provision.go | 5 +++++ pkg/services/cosmosdb/mongodb-types.go | 5 +++++ pkg/services/cosmosdb/plan_schemas.go | 12 ++++++++++++ tests/lifecycle/cosmosdb_cases_test.go | 19 +++++++++++++++++++ 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/docs/modules/cosmosdb.md b/docs/modules/cosmosdb.md index 77a70900f..795861877 100644 --- a/docs/modules/cosmosdb.md +++ b/docs/modules/cosmosdb.md @@ -218,6 +218,7 @@ Provisions a new CosmosDB database account that can be accessed through the Mong |----------------|------|-------------|----------|---------------| | `location` | `string` | The Azure region in which to provision applicable resources. | Y | | | `resourceGroup` | `string` | The (new or existing) resource group with which to associate new resources. | Y | | +| `version` | `string` | The version of MongoDB api. Allowed values are: ["3.2", "3.6"] | Y | If not specified, 3.2 will be used. | | `tags` | `map[string]string` | Tags to be applied to new resources, specified as key/value pairs. | N | Tags (even if none are specified) are automatically supplemented with `heritage: open-service-broker-azure`. | | `ipFilters` | `object` | IP Range Filter to be applied to new CosmosDB account | N | A default filter is created that allows only Azure service access | | `ipFilters.allowAccessFromAzure` | `string` | Specifies if Azure Services should be able to access the CosmosDB account. Valid valued are `""` (unspecified), `enabled`, or `disabled`. | N | If left unspecified, defaults to enabled. | diff --git a/pkg/services/cosmosdb/catalog.go b/pkg/services/cosmosdb/catalog.go index dd9faadb5..725cee576 100644 --- a/pkg/services/cosmosdb/catalog.go +++ b/pkg/services/cosmosdb/catalog.go @@ -154,8 +154,8 @@ func (m *module) GetCatalog() (service.Catalog, error) { }, Schemas: service.PlanSchemas{ ServiceInstances: service.InstanceSchemas{ - ProvisioningParametersSchema: generateProvisioningParamsSchema(), // nolint: lll - UpdatingParametersSchema: generateUpdatingParamsSchema(), // nolint: lll + ProvisioningParametersSchema: generateMongoDBProvisionParamsSchema(), // nolint: lll + UpdatingParametersSchema: generateUpdatingParamsSchema(), // nolint: lll }, }, }), diff --git a/pkg/services/cosmosdb/mongodb-provision.go b/pkg/services/cosmosdb/mongodb-provision.go index 80f4dcdf6..e1325b013 100644 --- a/pkg/services/cosmosdb/mongodb-provision.go +++ b/pkg/services/cosmosdb/mongodb-provision.go @@ -34,6 +34,11 @@ func (m *mongoAccountManager) deployARMTemplate( if err != nil { return nil, err } + + mongoDBVersion := pp.GetString("version") + if mongoDBVersion == mongoDBVersion36 { + p["capability"] = "EnableMongo" + } tags := getTags(pp) fqdn, pk, err := m.cosmosAccountManager.deployARMTemplate( pp, diff --git a/pkg/services/cosmosdb/mongodb-types.go b/pkg/services/cosmosdb/mongodb-types.go index 9c8d8565b..96bf8cd68 100644 --- a/pkg/services/cosmosdb/mongodb-types.go +++ b/pkg/services/cosmosdb/mongodb-types.go @@ -26,3 +26,8 @@ func ( func (m *mongoAccountManager) GetEmptyBindingDetails() service.BindingDetails { return nil } + +const ( + mongoDBVersion36 = "3.6" + mongoDBVersion32 = "3.2" +) diff --git a/pkg/services/cosmosdb/plan_schemas.go b/pkg/services/cosmosdb/plan_schemas.go index 4cf237f5a..771651ac7 100644 --- a/pkg/services/cosmosdb/plan_schemas.go +++ b/pkg/services/cosmosdb/plan_schemas.go @@ -153,6 +153,18 @@ func generateProvisioningParamsSchema() service.InputParametersSchema { } } +func generateMongoDBProvisionParamsSchema() service.InputParametersSchema { + sharedProvisioningSchema := generateProvisioningParamsSchema() + sharedProvisioningSchema.PropertySchemas["version"] = &service.StringPropertySchema{ // nolint: lll + Title: "The version of MongoDB api", + Description: "Specifies the version you want to use " + + "in created MongoDB acccount.", + AllowedValues: []string{mongoDBVersion32, mongoDBVersion36}, + DefaultValue: mongoDBVersion32, + } + return sharedProvisioningSchema +} + func ipRangeValidator(context, value string) error { ip := net.ParseIP(value) if ip == nil { diff --git a/tests/lifecycle/cosmosdb_cases_test.go b/tests/lifecycle/cosmosdb_cases_test.go index 778652fb9..dc59d5494 100644 --- a/tests/lifecycle/cosmosdb_cases_test.go +++ b/tests/lifecycle/cosmosdb_cases_test.go @@ -109,6 +109,25 @@ var cosmosdbTestCases = []serviceLifecycleTestCase{ "readRegions": []interface{}{}, }, }, + { // MongoDB v3.6 + group: "cosmosdb", + name: "mongo-api-account-only-v3.6", + serviceID: "8797a079-5346-4e84-8018-b7d5ea5c0e3a", + planID: "86fdda05-78d7-4026-a443-1325928e7b02", + + testCredentials: testMongoDBCreds, + provisioningParameters: map[string]interface{}{ + "location": "eastus", + "version": "3.6", + "ipFilters": map[string]interface{}{ + "allowedIPRanges": []interface{}{"0.0.0.0/0"}, + }, + "consistencyPolicy": map[string]interface{}{ + "defaultConsistencyLevel": "Session", + }, + "readRegions": []interface{}{"westus"}, + }, + }, { // SQL API All In One group: "cosmosdb", name: "sql-api-all-in-one",