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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Cloud Databases): remove bluemix-go dependency for allowlist #4222

Merged
merged 2 commits into from Dec 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 12 additions & 37 deletions ibm/flex/structures.go
Expand Up @@ -1606,53 +1606,28 @@ func FlattenremoteSubnet(vpn *datatypes.Network_Tunnel_Module_Context) []map[str
}

// IBM Cloud Databases
func ExpandWhitelist(whiteList *schema.Set) (whitelist []icdv4.WhitelistEntry) {
for _, iface := range whiteList.List() {
wlItem := iface.(map[string]interface{})
wlEntry := icdv4.WhitelistEntry{
Address: wlItem["address"].(string),
Description: wlItem["description"].(string),
}
whitelist = append(whitelist, wlEntry)
}
return
}

// IBM Cloud Databases
func ExpandAllowlist(allowList *schema.Set) (allowlist []clouddatabasesv5.AllowlistEntry) {
func ExpandAllowlist(allowList *schema.Set) (entries []clouddatabasesv5.AllowlistEntry) {
entries = make([]clouddatabasesv5.AllowlistEntry, 0, len(allowList.List()))
for _, iface := range allowList.List() {
alItem := iface.(map[string]interface{})
alEntry := &clouddatabasesv5.AllowlistEntry{
Address: core.StringPtr(alItem["address"].(string)),
Description: core.StringPtr(alItem["description"].(string)),
}
allowlist = append(allowlist, *alEntry)
entries = append(entries, *alEntry)
}
return
}

// Cloud Internet Services
func FlattenWhitelist(whitelist icdv4.Whitelist) []map[string]interface{} {
entries := make([]map[string]interface{}, len(whitelist.WhitelistEntrys), len(whitelist.WhitelistEntrys))
for i, whitelistEntry := range whitelist.WhitelistEntrys {
l := map[string]interface{}{
"address": whitelistEntry.Address,
"description": whitelistEntry.Description,
}
entries[i] = l
}
return entries
}

// Cloud Internet Services
func FlattenGetAllowlist(allowlist clouddatabasesv5.GetAllowlistResponse) []map[string]interface{} {
entries := make([]map[string]interface{}, len(allowlist.IPAddresses), len(allowlist.IPAddresses))
for i, allowlistEntry := range allowlist.IPAddresses {
l := map[string]interface{}{
"address": allowlistEntry.Address,
"description": allowlistEntry.Description,
}
entries[i] = l
// IBM Cloud Databases
func FlattenAllowlist(allowlist []clouddatabasesv5.AllowlistEntry) []map[string]interface{} {
entries := make([]map[string]interface{}, 0, len(allowlist))
for _, ip := range allowlist {
entry := map[string]interface{}{
"address": ip.Address,
"description": ip.Description,
}
entries = append(entries, entry)
}
return entries
}
Expand Down
15 changes: 7 additions & 8 deletions ibm/service/database/data_source_ibm_database.go
Expand Up @@ -752,6 +752,11 @@ func dataSourceIBMDatabaseInstanceRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("[ERROR] Error getting database client settings: %s", err)
}

cloudDatabasesClient, err := meta.(conns.ClientSession).CloudDatabasesV5()
if err != nil {
return fmt.Errorf("[ERROR] Error getting database client settings: %s", err)
}

icdId := flex.EscapeUrlParm(instance.ID)
cdb, err := icdClient.Cdbs().GetCdb(icdId)
if err != nil {
Expand Down Expand Up @@ -780,13 +785,6 @@ func dataSourceIBMDatabaseInstanceRead(d *schema.ResourceData, meta interface{})
}
d.Set("auto_scaling", flattenICDAutoScalingGroup(autoSclaingGroup))

whitelist, err := icdClient.Whitelists().GetWhitelist(icdId)
if err != nil {
return fmt.Errorf("[ERROR] Error getting database whitelist: %s", err)
}
d.Set("whitelist", flex.FlattenWhitelist(whitelist))

cloudDatabasesClient, err := meta.(conns.ClientSession).CloudDatabasesV5()
alEntry := &clouddatabasesv5.GetAllowlistOptions{
ID: &instance.ID,
}
Expand All @@ -797,7 +795,8 @@ func dataSourceIBMDatabaseInstanceRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("[ERROR] Error getting database allowlist: %s", err)
}

d.Set("allowlist", flex.FlattenGetAllowlist(*allowlist))
d.Set("allowlist", flex.FlattenAllowlist(allowlist.IPAddresses))
d.Set("whitelist", flex.FlattenAllowlist(allowlist.IPAddresses))

connectionEndpoint := "public"
if instance.Parameters != nil {
Expand Down