Skip to content

Commit

Permalink
Remove Key Protect ID and Transition to v5 API (IBM-Cloud#4420)
Browse files Browse the repository at this point in the history
* removed key_protect_key_id and migrated to v5 api
* updated docs
  • Loading branch information
omaraibrahim committed Jul 20, 2023
1 parent d2d6f9e commit 05d5d6d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
7 changes: 3 additions & 4 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -1828,12 +1828,11 @@ func FlattenAllowlist(allowlist []clouddatabasesv5.AllowlistEntry) []map[string]
return entries
}

func ExpandPlatformOptions(platformOptions icdv4.PlatformOptions) []map[string]interface{} {
func ExpandPlatformOptions(deployment clouddatabasesv5.Deployment) []map[string]interface{} {
pltOptions := make([]map[string]interface{}, 0, 1)
pltOption := make(map[string]interface{})
pltOption["key_protect_key_id"] = platformOptions.KeyProtectKey
pltOption["disk_encryption_key_crn"] = platformOptions.DiskENcryptionKeyCrn
pltOption["backup_encryption_key_crn"] = platformOptions.BackUpEncryptionKeyCrn
pltOption["disk_encryption_key_crn"] = deployment.PlatformOptions["disk_encryption_key_crn"]
pltOption["backup_encryption_key_crn"] = deployment.PlatformOptions["backup_encryption_key_crn"]
pltOptions = append(pltOptions, pltOption)
return pltOptions
}
Expand Down
29 changes: 15 additions & 14 deletions ibm/service/database/data_source_ibm_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/IBM-Cloud/bluemix-go/api/resource/resourcev2/controllerv2"
"github.com/IBM-Cloud/bluemix-go/bmxerror"
"github.com/IBM-Cloud/bluemix-go/models"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
Expand Down Expand Up @@ -108,12 +107,6 @@ func DataSourceIBMDatabaseInstance() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key_protect_key_id": {
Description: "Key protect key id",
Type: schema.TypeString,
Computed: true,
Deprecated: "This field is deprecated and has been replaced by disk_encryption_key_crn",
},
"disk_encryption_key_crn": {
Description: "Disk encryption key crn",
Type: schema.TypeString,
Expand Down Expand Up @@ -668,17 +661,25 @@ func dataSourceIBMDatabaseInstanceRead(d *schema.ResourceData, meta interface{})
}

icdId := flex.EscapeUrlParm(instance.ID)
cdb, err := icdClient.Cdbs().GetCdb(icdId)
getDeploymentInfoOptions := &clouddatabasesv5.GetDeploymentInfoOptions{
ID: core.StringPtr(instance.ID),
}
getDeploymentInfoResponse, response, err := cloudDatabasesClient.GetDeploymentInfo(getDeploymentInfoOptions)
if err != nil {
if apiErr, ok := err.(bmxerror.RequestFailure); ok && apiErr.StatusCode() == 404 {
if response.StatusCode == 404 {
return fmt.Errorf("[ERROR] The database instance was not found in the region set for the Provider, or the default of us-south. Specify the correct region in the provider definition, or create a provider alias for the correct region. %v", err)
}
return fmt.Errorf("[ERROR] Error getting database config for: %s with error %s\n", icdId, err)
return fmt.Errorf("[ERROR] Error getting database config while updating adminpassword for: %s with error %s", instance.ID, err)
}
d.Set("adminuser", cdb.AdminUser)
d.Set("version", cdb.Version)
if &cdb.PlatformOptions != nil {
d.Set("platform_options", flex.ExpandPlatformOptions(cdb.PlatformOptions))

deployment := getDeploymentInfoResponse.Deployment
adminUser := deployment.AdminUsernames["database"]

d.Set("adminuser", adminUser)
d.Set("version", deployment.Version)

if deployment.PlatformOptions != nil {
d.Set("platform_options", flex.ExpandPlatformOptions(*deployment))
}

groupList, err := icdClient.Groups().GetGroups(icdId)
Expand Down
1 change: 0 additions & 1 deletion website/docs/d/database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ In addition to all argument references list, you can access the following attrib
- `platform_options`- (String) The CRN of key protect key.

Nested scheme for `platform_options`:
- `key_protect_key_id`- **Deprecated** - (String) The CRN of key protect key. - replaced by `disk_encryption_key_crn`
- `disk_encryption_key_crn`- (String) The CRN of disk encryption key.
- `backup_encryption_key_crn`- (String) The CRN of backup encryption key.

Expand Down

0 comments on commit 05d5d6d

Please sign in to comment.