Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Key Protect ID and Transition to v5 API #4420

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -1648,12 +1648,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
31 changes: 16 additions & 15 deletions ibm/service/database/data_source_ibm_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/IBM-Cloud/bluemix-go/api/icd/icdv4"
"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 @@ -113,12 +112,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 @@ -759,17 +752,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 Expand Up @@ -819,7 +820,7 @@ func dataSourceIBMDatabaseInstanceRead(d *schema.ResourceData, meta interface{})
tfusers := d.Get("users").(*schema.Set)
users := flex.ExpandUsers(tfusers)
user := icdv4.User{
UserName: cdb.AdminUser,
UserName: adminUser,
}
users = append(users, user)
for _, user := range users {
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 @@ -47,7 +47,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