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

Changed fmt error building function to wrapper flex fmterror builder #5845

Merged
merged 8 commits into from
Dec 24, 2024
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
github.com/IBM-Cloud/power-go-client v1.8.3
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
github.com/IBM/appconfiguration-go-admin-sdk v0.4.4
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
github.com/IBM/cloud-databases-go-sdk v0.7.1
github.com/IBM/cloudant-go-sdk v0.8.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKO
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs=
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca/go.mod h1:IjXrnOcTe92Q4pEBHmui3H/GM1hw5Pd0zXA5cw5/iZU=
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0 h1:OqFxnDxro0JiRwHBKytCcseY2YKD4n87JN1UcaOD4Ss=
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0/go.mod h1:xPxAYhr/uywUIDEo/JqWbkUdTryPdzRdYBfUpA5IjoE=
github.com/IBM/appconfiguration-go-admin-sdk v0.4.4 h1:VQ+mVavoo3/xrBaVSyxE+B6Uef+m33RcbropwpTRBy4=
github.com/IBM/appconfiguration-go-admin-sdk v0.4.4/go.mod h1:E9cXu9w0EClhZq+E9wBw8QzNLKZd2bNdMrTXwVSWJ1s=
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f h1:4c1kqY4GqmkQ+tO03rneDb74Tv7BhTj8jDiDB1p8mdM=
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f/go.mod h1:d22kTYY7RYBWcQlZpqrSdshpB/lJ16viWS5Sbjtlc8s=
github.com/IBM/cloud-databases-go-sdk v0.7.1 h1:5kK4/3NUsGxZzmuUe+1ftajpOQbeDVh5VeemrPgROP4=
Expand All @@ -151,7 +151,6 @@ github.com/IBM/go-sdk-core/v3 v3.2.4/go.mod h1:lk9eOzNbNltPf3CBpcg1Ewkhw4qC3u2QC
github.com/IBM/go-sdk-core/v5 v5.0.0/go.mod h1:vyNdbFujJtdTj9HbihtvKwwS3k/GKSKpOx9ZIQ6MWDY=
github.com/IBM/go-sdk-core/v5 v5.5.1/go.mod h1:Sn+z+qTDREQvCr+UFa22TqqfXNxx3o723y8GsfLV8e0=
github.com/IBM/go-sdk-core/v5 v5.6.3/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3btdruJaoUeek=
github.com/IBM/go-sdk-core/v5 v5.7.0/go.mod h1:+YbdhrjCHC84ls4MeBp+Hj4NZCni+tDAc0XQUqRO9Jc=
github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2ywAPwW4VJjdI=
github.com/IBM/go-sdk-core/v5 v5.17.4/go.mod h1:KsAAI7eStAWwQa4F96MLy+whYSh39JzNjklZRbN/8ns=
Expand Down Expand Up @@ -599,7 +598,6 @@ github.com/go-openapi/strfmt v0.19.3/go.mod h1:0yX7dbo8mKIvc3XSKp7MNfxw4JytCfCD6
github.com/go-openapi/strfmt v0.19.4/go.mod h1:eftuHTlB/dI8Uq8JJOyRlieZf+WkkxUuk0dgdHXr2Qk=
github.com/go-openapi/strfmt v0.19.10/go.mod h1:qBBipho+3EoIqn6YDI+4RnQEtj6jT/IdKm+PAlXxSUc=
github.com/go-openapi/strfmt v0.20.1/go.mod h1:43urheQI9dNtE5lTZQfuFJvjYJKPrxicATpEfZwHUNk=
github.com/go-openapi/strfmt v0.20.2/go.mod h1:43urheQI9dNtE5lTZQfuFJvjYJKPrxicATpEfZwHUNk=
github.com/go-openapi/strfmt v0.21.1/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k=
github.com/go-openapi/strfmt v0.21.3/go.mod h1:k+RzNO0Da+k3FrrynSNN8F7n/peCmQQqbbXjtDfvmGg=
github.com/go-openapi/strfmt v0.21.7/go.mod h1:adeGTkxE44sPyLk0JV235VQAO/ZXUr8KAzYjclFs3ew=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package appconfiguration
import (
"fmt"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -122,7 +123,7 @@ func dataSourceIbmAppConfigCollectionRead(d *schema.ResourceData, meta interface

appconfigClient, err := getAppConfigClient(meta, guid)
if err != nil {
return fmt.Errorf("getAppConfigClient failed %s", err)
return flex.FmtErrorf("getAppConfigClient failed %s", err)
}

options := &appconfigurationv1.GetCollectionOptions{}
Expand All @@ -142,50 +143,50 @@ func dataSourceIbmAppConfigCollectionRead(d *schema.ResourceData, meta interface

result, response, err := appconfigClient.GetCollection(options)
if err != nil {
return fmt.Errorf("GetCollection failed %s\n%s", err, response)
return flex.FmtErrorf("GetCollection failed %s\n%s", err, response)
}

d.SetId(fmt.Sprintf("%s/%s", guid, *result.CollectionID))
if result.Name != nil {
if err = d.Set("name", result.Name); err != nil {
return fmt.Errorf("[ERROR] Error setting name: %s", err)
return flex.FmtErrorf("[ERROR] Error setting name: %s", err)
}
}
if result.Description != nil {
if err = d.Set("description", result.Description); err != nil {
return fmt.Errorf("[ERROR] Error setting description: %s", err)
return flex.FmtErrorf("[ERROR] Error setting description: %s", err)
}
}
if result.Tags != nil {
if err = d.Set("tags", result.Tags); err != nil {
return fmt.Errorf("[ERROR] Error setting tags: %s", err)
return flex.FmtErrorf("[ERROR] Error setting tags: %s", err)
}
}
if result.CreatedTime != nil {
if err = d.Set("created_time", result.CreatedTime.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting created_time: %s", err)
return flex.FmtErrorf("[ERROR] Error setting created_time: %s", err)
}
}
if result.UpdatedTime != nil {
if err = d.Set("updated_time", result.UpdatedTime.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting updated_time: %s", err)
return flex.FmtErrorf("[ERROR] Error setting updated_time: %s", err)
}
}
if result.Href != nil {
if err = d.Set("href", result.Href); err != nil {
return fmt.Errorf("[ERROR] Error setting href: %s", err)
return flex.FmtErrorf("[ERROR] Error setting href: %s", err)
}
}
if result.Features != nil {
err = d.Set("features", dataSourceCollectionFlattenFeatures(result.Features))
if err != nil {
return fmt.Errorf("[ERROR] Error setting features %s", err)
return flex.FmtErrorf("[ERROR] Error setting features %s", err)
}
}
if result.Properties != nil {
err = d.Set("properties", dataSourceCollectionFlattenProperties(result.Properties))
if err != nil {
return fmt.Errorf("[ERROR] Error setting properties %s", err)
return flex.FmtErrorf("[ERROR] Error setting properties %s", err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"strconv"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
Expand Down Expand Up @@ -150,7 +151,7 @@ func dataSourceIbmAppConfigCollectionsRead(d *schema.ResourceData, meta interfac

appconfigClient, err := getAppConfigClient(meta, guid)
if err != nil {
return fmt.Errorf("getAppConfigClient failed %s", err)
return flex.FmtErrorf("getAppConfigClient failed %s", err)
}

options := &appconfigurationv1.ListCollectionsOptions{}
Expand Down Expand Up @@ -205,7 +206,7 @@ func dataSourceIbmAppConfigCollectionsRead(d *schema.ResourceData, meta interfac
result, response, err := appconfigClient.ListCollections(options)
collectionsList = result
if err != nil {
return fmt.Errorf("ListCollections failed %s\n%s", err, response)
return flex.FmtErrorf("ListCollections failed %s\n%s", err, response)
}
if isLimit {
offset = 0
Expand All @@ -225,22 +226,22 @@ func dataSourceIbmAppConfigCollectionsRead(d *schema.ResourceData, meta interfac
if collectionsList.Collections != nil {
err = d.Set("collections", dataSourceCollectionListFlattenCollections(collectionsList.Collections))
if err != nil {
return fmt.Errorf("[ERROR] Error setting collections %s", err)
return flex.FmtErrorf("[ERROR] Error setting collections %s", err)
}
}
if collectionsList.Limit != nil {
if err = d.Set("limit", collectionsList.Limit); err != nil {
return fmt.Errorf("[ERROR] Error setting limit: %s", err)
return flex.FmtErrorf("[ERROR] Error setting limit: %s", err)
}
}
if collectionsList.Offset != nil {
if err = d.Set("offset", collectionsList.Offset); err != nil {
return fmt.Errorf("[ERROR] Error setting offset: %s", err)
return flex.FmtErrorf("[ERROR] Error setting offset: %s", err)
}
}
if collectionsList.TotalCount != nil {
if err = d.Set("total_count", collectionsList.TotalCount); err != nil {
return fmt.Errorf("[ERROR] Error setting total_count: %s", err)
return flex.FmtErrorf("[ERROR] Error setting total_count: %s", err)
}
}

Expand Down Expand Up @@ -352,19 +353,30 @@ func dataSourceCollectionsListGetNext(next interface{}) int64 {
return convertedVal
}

func dataSourceCollectionListFlattenPagination(result appconfigurationv1.PageHrefResponse) (finalList []map[string]interface{}) {
func dataSourceCollectionListFlattenPagination(result interface{}) (finalList []map[string]interface{}) {
finalList = []map[string]interface{}{}
finalMap := dataSourceCollectionsListURLToMap(result)
finalList = append(finalList, finalMap)

return finalList
}

func dataSourceCollectionsListURLToMap(urlItem appconfigurationv1.PageHrefResponse) (urlMap map[string]interface{}) {
func dataSourceCollectionsListURLToMap(urlItem interface{}) (urlMap map[string]interface{}) {
urlMap = map[string]interface{}{}

if urlItem.Href != nil {
urlMap["href"] = urlItem.Href
var hrefUrl *string
switch urlItem := urlItem.(type) {
case appconfigurationv1.PaginatedListFirst:
hrefUrl = urlItem.Href
case appconfigurationv1.PaginatedListLast:
hrefUrl = urlItem.Href
case appconfigurationv1.PaginatedListNext:
hrefUrl = urlItem.Href
case appconfigurationv1.PaginatedListPrevious:
hrefUrl = urlItem.Href
}
if hrefUrl != nil {
urlMap["href"] = hrefUrl
}

return urlMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package appconfiguration

import (
"fmt"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
Expand Down Expand Up @@ -77,7 +77,7 @@ func dataSourceIbmAppConfigEnvironmentRead(d *schema.ResourceData, meta interfac

appconfigClient, err := getAppConfigClient(meta, guid)
if err != nil {
return err
return flex.FmtErrorf(fmt.Sprintf("%s", err))
}

options := &appconfigurationv1.GetEnvironmentOptions{}
Expand All @@ -88,45 +88,44 @@ func dataSourceIbmAppConfigEnvironmentRead(d *schema.ResourceData, meta interfac
}
result, response, err := appconfigClient.GetEnvironment(options)
if err != nil {
log.Printf("GetEnvironment failed %s\n%s", err, response)
return err
return flex.FmtErrorf("GetEnvironment failed %s\n%s", err, response)
}

d.SetId(fmt.Sprintf("%s/%s", guid, *result.EnvironmentID))

if result.Name != nil {
if err = d.Set("name", result.Name); err != nil {
return fmt.Errorf("[ERROR] Error setting name: %s", err)
return flex.FmtErrorf("[ERROR] Error setting name: %s", err)
}
}
if result.Description != nil {
if err = d.Set("description", result.Description); err != nil {
return fmt.Errorf("[ERROR] Error setting description: %s", err)
return flex.FmtErrorf("[ERROR] Error setting description: %s", err)
}
}
if result.Tags != nil {
if err = d.Set("tags", result.Tags); err != nil {
return fmt.Errorf("[ERROR] Error setting tags: %s", err)
return flex.FmtErrorf("[ERROR] Error setting tags: %s", err)
}
}
if result.ColorCode != nil {
if err = d.Set("color_code", result.ColorCode); err != nil {
return fmt.Errorf("[ERROR] Error setting color_code: %s", err)
return flex.FmtErrorf("[ERROR] Error setting color_code: %s", err)
}
}
if result.CreatedTime != nil {
if err = d.Set("created_time", result.CreatedTime.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting created_time: %s", err)
return flex.FmtErrorf("[ERROR] Error setting created_time: %s", err)
}
}
if result.UpdatedTime != nil {
if err = d.Set("updated_time", result.UpdatedTime.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting updated_time: %s", err)
return flex.FmtErrorf("[ERROR] Error setting updated_time: %s", err)
}
}
if result.Href != nil {
if err = d.Set("href", result.Href); err != nil {
return fmt.Errorf("[ERROR] Error setting href: %s", err)
return flex.FmtErrorf("[ERROR] Error setting href: %s", err)
}
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func testAccCheckIbmAppConfigEnvironmentDataSourceConfigBasic(name, envName, env
name = "%s"
location = "us-south"
service = "apprapp"
plan = "standard"
plan = "lite"
}
resource "ibm_app_config_environment" "app_config_environment_resource1" {
name = "%s"
Expand Down
Loading