Skip to content

Commit 1f2bcf1

Browse files
authored
fix(Cloud Databases): Add hidden and beta versions to in place upgrade (IBM-Cloud#6502)
1 parent 65685df commit 1f2bcf1

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/IBM-Cloud/power-go-client v1.13.0
99
github.com/IBM/appconfiguration-go-admin-sdk v0.5.1
1010
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
11-
github.com/IBM/cloud-databases-go-sdk v0.8.0
11+
github.com/IBM/cloud-databases-go-sdk v0.8.1
1212
github.com/IBM/cloud-db2-go-sdk v0.2.4
1313
github.com/IBM/cloudant-go-sdk v0.8.0
1414
github.com/IBM/code-engine-go-sdk v0.0.0-20241217191651-e1821f8c58c3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ github.com/IBM/appconfiguration-go-admin-sdk v0.5.1 h1:EAotl3yQ/u5u/uBryySJMm0CO
101101
github.com/IBM/appconfiguration-go-admin-sdk v0.5.1/go.mod h1:ikqhyFenxA/QgGh4vItBNjPes0NcI+teRof+z7pzLYM=
102102
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f h1:4c1kqY4GqmkQ+tO03rneDb74Tv7BhTj8jDiDB1p8mdM=
103103
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f/go.mod h1:d22kTYY7RYBWcQlZpqrSdshpB/lJ16viWS5Sbjtlc8s=
104-
github.com/IBM/cloud-databases-go-sdk v0.8.0 h1:uMFqhnc/roVTzfCaUsJ23eaHKjChhGpM1F7Mpxik0bo=
105-
github.com/IBM/cloud-databases-go-sdk v0.8.0/go.mod h1:JYucI1PdwqbAd8XGdDAchxzxRP7bxOh1zUnseovHKsc=
104+
github.com/IBM/cloud-databases-go-sdk v0.8.1 h1:ULQ5L8V/9z79/qS185LqbIK2LD4kMtk3Hdhp4lFMVcw=
105+
github.com/IBM/cloud-databases-go-sdk v0.8.1/go.mod h1:JYucI1PdwqbAd8XGdDAchxzxRP7bxOh1zUnseovHKsc=
106106
github.com/IBM/cloud-db2-go-sdk v0.2.4 h1:kCiFoKav2FVrZqukoSAp0ivH8xBZDYipFBNkiyAXDw0=
107107
github.com/IBM/cloud-db2-go-sdk v0.2.4/go.mod h1:U1E6eRDEL5zWTE+aP9zWRC1DyaXB29a0kkTvhlCT9Wc=
108108
github.com/IBM/cloudant-go-sdk v0.8.0 h1:XzaqZFy5fm1Q9+iK52X5zRW39SHaahT9pf5SRgVTsTY=

ibm/service/database/deployment.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ import (
1515
TODO Move other deployment api endpoints in here
1616
*/
1717

18-
func getDeploymentCapability(capabilityId string, deploymentId string, platform string, location string, meta interface{}) (*clouddatabasesv5.Capability, error) {
18+
type DeploymentCapabilityOptions struct {
19+
Platform string
20+
Location string
21+
IncludeHidden *bool
22+
IncludeBeta *bool
23+
}
24+
25+
func getDeploymentCapability(capabilityId string, deploymentId string, options DeploymentCapabilityOptions, meta interface{}) (*clouddatabasesv5.Capability, error) {
1926
cloudDatabasesClient, err := meta.(conns.ClientSession).CloudDatabasesV5()
2027
if err != nil {
2128
return nil, err
@@ -24,9 +31,18 @@ func getDeploymentCapability(capabilityId string, deploymentId string, platform
2431
getDeploymentCapabilityOptions := &clouddatabasesv5.GetDeploymentCapabilityOptions{
2532
ID: core.StringPtr(deploymentId),
2633
CapabilityID: core.StringPtr(capabilityId),
27-
TargetPlatform: core.StringPtr(fmt.Sprintf("target_platform=%s", platform)),
28-
TargetLocation: core.StringPtr(fmt.Sprintf("target_location=%s", location)),
34+
TargetPlatform: core.StringPtr(fmt.Sprintf("target_platform=%s", options.Platform)),
35+
TargetLocation: core.StringPtr(fmt.Sprintf("target_location=%s", options.Location)),
36+
}
37+
38+
if options.IncludeHidden != nil {
39+
getDeploymentCapabilityOptions.IncludeHidden = core.BoolPtr(*options.IncludeHidden)
2940
}
41+
42+
if options.IncludeBeta != nil {
43+
getDeploymentCapabilityOptions.IncludeBeta = core.BoolPtr(*options.IncludeBeta)
44+
}
45+
3046
getDeploymentCapabilityResponse, response, err := cloudDatabasesClient.GetDeploymentCapability(getDeploymentCapabilityOptions)
3147

3248
if getDeploymentCapabilityResponse == nil || getDeploymentCapabilityResponse.Capability == nil {

ibm/service/database/resource_ibm_database_mongodb_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func TestAccIBMDatabaseInstanceMongodbImport(t *testing.T) {
115115
}
116116

117117
func TestAccIBMDatabaseInstanceMongodbUpgrade(t *testing.T) {
118-
// IMPORTANT NOTE: The version in testAccCheckIBMDatabaseInstanceMongodbVersionUpgrade will have to be updated when versions deprecate etc. Currently mongo standard can only upgrade to version 7.0
118+
// IMPORTANT NOTE: The version in testAccCheckIBMDatabaseInstanceMongodbVersionUpgrade will have to be updated when versions deprecate etc. Currently mongo standard can only upgrade to version 8.0
119119
t.Parallel()
120120
databaseResourceGroup := "default"
121121
var databaseInstanceOne string
@@ -136,7 +136,7 @@ func TestAccIBMDatabaseInstanceMongodbUpgrade(t *testing.T) {
136136
resource.TestCheckResourceAttr(name, "service", "databases-for-mongodb"),
137137
resource.TestCheckResourceAttr(name, "plan", "standard"),
138138
resource.TestCheckResourceAttr(name, "location", acc.Region()),
139-
resource.TestCheckResourceAttr(name, "version", "6.0"),
139+
resource.TestCheckResourceAttr(name, "version", "7.0"),
140140
),
141141
},
142142
{
@@ -147,7 +147,7 @@ func TestAccIBMDatabaseInstanceMongodbUpgrade(t *testing.T) {
147147
resource.TestCheckResourceAttr(name, "service", "databases-for-mongodb"),
148148
resource.TestCheckResourceAttr(name, "plan", "standard"),
149149
resource.TestCheckResourceAttr(name, "location", acc.Region()),
150-
resource.TestCheckResourceAttr(name, "version", "7.0"),
150+
resource.TestCheckResourceAttr(name, "version", "8.0"),
151151
),
152152
},
153153
},
@@ -193,7 +193,7 @@ func testAccCheckIBMDatabaseInstanceMongodbBasic(databaseResourceGroup string, n
193193
}
194194

195195
func testAccCheckIBMDatabaseInstanceMongodbVersion6(databaseResourceGroup string, name string) string {
196-
// IMPORTANT NOTE: The version will have to be updated when version 6 is no longer available. Currently mongo standard can only upgrade to version 7.0
196+
// IMPORTANT NOTE: The version will have to be updated when version 6 is no longer available. Currently mongo standard can only upgrade to version 8.0
197197
return fmt.Sprintf(`
198198
data "ibm_resource_group" "test_acc" {
199199
name = "%[1]s"
@@ -205,15 +205,15 @@ func testAccCheckIBMDatabaseInstanceMongodbVersion6(databaseResourceGroup string
205205
service = "databases-for-mongodb"
206206
plan = "standard"
207207
location = "%[3]s"
208-
version = "6.0"
208+
version = "7.0"
209209
service_endpoints = "private"
210210
211211
}
212212
`, databaseResourceGroup, name, acc.Region())
213213
}
214214

215215
func testAccCheckIBMDatabaseInstanceMongodbVersionUpgrade(databaseResourceGroup string, name string) string {
216-
// IMPORTANT NOTE: The version will have to be updated when version 6.0 is no longer available. Currently mongo standard can only upgrade to version 7.0
216+
// IMPORTANT NOTE: The version will have to be updated when version 6.0 is no longer available. Currently mongo standard can only upgrade to version 8.0
217217
return fmt.Sprintf(`
218218
data "ibm_resource_group" "test_acc" {
219219
name = "%[1]s"
@@ -225,7 +225,7 @@ func testAccCheckIBMDatabaseInstanceMongodbVersionUpgrade(databaseResourceGroup
225225
service = "databases-for-mongodb"
226226
plan = "standard"
227227
location = "%[3]s"
228-
version = "7.0"
228+
version = "8.0"
229229
version_upgrade_skip_backup = true
230230
service_endpoints = "private"
231231
}

ibm/service/database/validators.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99

1010
"github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5"
11+
"github.com/IBM/go-sdk-core/v5/core"
1112
)
1213

1314
/* TODO move other validators in here */
@@ -107,7 +108,14 @@ func (v *Version) getAllowedVersionsList() []string {
107108
var fetchDeploymentVersionFn = fetchDeploymentVersion
108109

109110
func fetchDeploymentVersion(instanceId string, location string, meta interface{}) *Version {
110-
capability, err := getDeploymentCapability(versions, instanceId, classicPlatform, location, meta)
111+
options := DeploymentCapabilityOptions{
112+
Platform: classicPlatform,
113+
Location: location,
114+
IncludeHidden: core.BoolPtr(true),
115+
IncludeBeta: core.BoolPtr(true),
116+
}
117+
118+
capability, err := getDeploymentCapability(versions, instanceId, options, meta)
111119
if err != nil {
112120
log.Fatalf("Error fetching deployment versions: %v", err)
113121
}

ibm/service/database/validators_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func TestGetAllowedVersionsList(t *testing.T) {
240240

241241
type MockMeta struct{}
242242

243-
func MockGetDeploymentCapability(capability string, instanceID string, platform string, location string, meta interface{}) (*clouddatabasesv5.Capability, error) {
243+
func MockGetDeploymentCapability(capability string, instanceID string, options DeploymentCapabilityOptions, meta interface{}) (*clouddatabasesv5.Capability, error) {
244244
return &clouddatabasesv5.Capability{
245245
Versions: []clouddatabasesv5.VersionsCapabilityItem{
246246
{
@@ -275,7 +275,7 @@ func MockGetDeploymentCapability(capability string, instanceID string, platform
275275
}, nil
276276
}
277277

278-
func MockGetDeploymentCapabilityNoTransitions(capability string, instanceID string, platform string, location string, meta interface{}) (*clouddatabasesv5.Capability, error) {
278+
func MockGetDeploymentCapabilityNoTransitions(capability string, instanceID string, options DeploymentCapabilityOptions, meta interface{}) (*clouddatabasesv5.Capability, error) {
279279
return &clouddatabasesv5.Capability{
280280
Versions: []clouddatabasesv5.VersionsCapabilityItem{
281281
{
@@ -297,7 +297,7 @@ func TestValidateVersion(t *testing.T) {
297297
oldVersion string
298298
upgradeVersion string
299299
skipBackup bool
300-
mockCapabilityFunc func(capability string, instanceID string, platform string, location string, meta interface{}) (*clouddatabasesv5.Capability, error)
300+
mockCapabilityFunc func(capability string, instanceID string, options DeploymentCapabilityOptions, meta interface{}) (*clouddatabasesv5.Capability, error)
301301
expectedError string
302302
}{
303303
{
@@ -348,7 +348,14 @@ func TestValidateVersion(t *testing.T) {
348348
for _, tc := range tests {
349349
t.Run(tc.description, func(t *testing.T) {
350350
fetchDeploymentVersionFn = func(instanceID string, location string, meta interface{}) *Version {
351-
capability, err := tc.mockCapabilityFunc(versions, instanceID, classicPlatform, location, meta)
351+
options := DeploymentCapabilityOptions{
352+
Platform: classicPlatform,
353+
Location: location,
354+
IncludeHidden: core.BoolPtr(true),
355+
IncludeBeta: core.BoolPtr(true),
356+
}
357+
358+
capability, err := tc.mockCapabilityFunc(versions, instanceID, options, meta)
352359
require.NoError(t, err)
353360
return expandVersion(capability.Versions[0])
354361
}

0 commit comments

Comments
 (0)