Skip to content

Commit

Permalink
feat(Cloud Databases): remove bluemix-go dependency for allowlist (#4222
Browse files Browse the repository at this point in the history
)
  • Loading branch information
alexhemard authored Dec 6, 2022
1 parent ad38584 commit e4be24c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 259 deletions.
49 changes: 12 additions & 37 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit e4be24c

Please sign in to comment.