Skip to content

Commit

Permalink
coverted error logs to flex errors
Browse files Browse the repository at this point in the history
  • Loading branch information
prajwal-jarali committed Dec 3, 2024
1 parent 0f9864f commit d480e47
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package appconfiguration

import (
"fmt"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -78,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 @@ -89,8 +88,7 @@ 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, err)
}

d.SetId(fmt.Sprintf("%s/%s", guid, *result.EnvironmentID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package appconfiguration

import (
"log"
"fmt"
"net/url"
"reflect"
"strconv"
Expand Down Expand Up @@ -165,7 +165,7 @@ func dataSourceIbmAppConfigEnvironmentsRead(d *schema.ResourceData, meta interfa

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

options := &appconfigurationv1.ListEnvironmentsOptions{}
Expand Down Expand Up @@ -198,8 +198,7 @@ func dataSourceIbmAppConfigEnvironmentsRead(d *schema.ResourceData, meta interfa
result, response, err := appconfigClient.ListEnvironments(options)
environmentList = result
if err != nil {
log.Printf("[ERROR] Listing Environments failed %s\n%s", err, response)
return err
return flex.FmtErrorf("[ERROR] Listing Environments failed %s\n%s", err, response)
}
if isLimit {
offset = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package appconfiguration

import (
"fmt"
"log"
"strconv"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
Expand Down Expand Up @@ -173,7 +172,7 @@ func dataSourceIbmAppConfigFeatureRead(d *schema.ResourceData, meta interface{})

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

options := &appconfigurationv1.GetFeatureOptions{}
Expand All @@ -187,8 +186,7 @@ func dataSourceIbmAppConfigFeatureRead(d *schema.ResourceData, meta interface{})

result, response, err := appconfigClient.GetFeature(options)
if err != nil {
log.Printf("[ERROR] GetFeature failed %s\n%s", err, response)
return err
return flex.FmtErrorf("[ERROR] GetFeature failed %s\n%s", err, response)
}

d.SetId(fmt.Sprintf("%s/%s/%s", guid, *options.EnvironmentID, *result.FeatureID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package appconfiguration

import (
"fmt"
"log"
"net/url"
"reflect"
"strconv"
Expand Down Expand Up @@ -283,7 +282,7 @@ func dataSourceIbmAppConfigFeaturesRead(d *schema.ResourceData, meta interface{}

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

options := &appconfigurationv1.ListFeaturesOptions{}
Expand Down Expand Up @@ -335,8 +334,7 @@ func dataSourceIbmAppConfigFeaturesRead(d *schema.ResourceData, meta interface{}
result, response, err := appconfigClient.ListFeatures(options)
featuresList = result
if err != nil {
log.Printf("[ERROR] Listing Features failed %s\n%s", err, response)
return err
return flex.FmtErrorf("[ERROR] Listing Features failed %s\n%s", err, response)
}
if isLimit {
offset = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package appconfiguration

import (
"fmt"
"log"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/IBM/appconfiguration-go-admin-sdk/appconfigurationv1"
Expand Down Expand Up @@ -134,7 +133,7 @@ func dataSourceIbmAppConfigSegmentRead(d *schema.ResourceData, meta interface{})

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

options := &appconfigurationv1.GetSegmentOptions{}
Expand All @@ -150,8 +149,7 @@ func dataSourceIbmAppConfigSegmentRead(d *schema.ResourceData, meta interface{})

result, response, err := appconfigClient.GetSegment(options)
if err != nil {
log.Printf("[ERROR] GetSegment failed %s\n%s", err, response)
return err
return flex.FmtErrorf("[ERROR] GetSegment failed %s\n%s", err, response)
}

d.SetId(fmt.Sprintf("%s/%s", guid, *result.SegmentID))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package appconfiguration

import (
"fmt"
"log"
"net/url"
"reflect"
"strconv"
Expand Down Expand Up @@ -215,8 +214,7 @@ func dataSourceIbmAppConfigSegmentsRead(d *schema.ResourceData, meta interface{}
result, response, err := appconfigClient.ListSegments(options)
segmentsList = result
if err != nil {
log.Printf("[ERROR] ListSegments failed %s\n%s", err, response)
return flex.FmtErrorf("ListSegments failed %s\n%s", err, response)
return flex.FmtErrorf("[ERROR] ListSegments failed %s\n%s", err, response)
}
if isLimit {
offset = 0
Expand Down
27 changes: 14 additions & 13 deletions ibm/service/appconfiguration/data_source_ibm_app_config_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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 @@ -114,7 +115,7 @@ func dataSourceIbmAppConfigSnapshotRead(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.GetGitconfigOptions{}
Expand All @@ -123,66 +124,66 @@ func dataSourceIbmAppConfigSnapshotRead(d *schema.ResourceData, meta interface{}
result, response, err := appconfigClient.GetGitconfig(options)

if err != nil {
return fmt.Errorf("GetGitconfig failed %s\n%s", err, response)
return flex.FmtErrorf("GetGitconfig failed %s\n%s", err, response)
}

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

if result.GitConfigName != nil {
if err = d.Set("git_config_name", result.GitConfigName); err != nil {
return fmt.Errorf("[ERROR] Error setting git_config_name: %s", err)
return flex.FmtErrorf("[ERROR] Error setting git_config_name: %s", err)
}
}
if result.GitConfigID != nil {
if err = d.Set("git_config_id", result.GitConfigID); err != nil {
return fmt.Errorf("[ERROR] Error setting git_config_id: %s", err)
return flex.FmtErrorf("[ERROR] Error setting git_config_id: %s", err)
}
}
if result.GitURL != nil {
if err = d.Set("git_url", result.GitURL); err != nil {
return fmt.Errorf("[ERROR] Error setting git_url: %s", err)
return flex.FmtErrorf("[ERROR] Error setting git_url: %s", err)
}
}
if result.GitBranch != nil {
if err = d.Set("git_branch", result.GitBranch); err != nil {
return fmt.Errorf("[ERROR] Error setting git_branch: %s", err)
return flex.FmtErrorf("[ERROR] Error setting git_branch: %s", err)
}
}
if result.GitFilePath != nil {
if err = d.Set("git_file_path", result.GitFilePath); err != nil {
return fmt.Errorf("[ERROR] Error setting git_file_path: %s", err)
return flex.FmtErrorf("[ERROR] Error setting git_file_path: %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.LastSyncTime != nil {
if err = d.Set("last_sync_time", result.LastSyncTime.String()); err != nil {
return fmt.Errorf("[ERROR] Error setting last_sync_time: %s", err)
return flex.FmtErrorf("[ERROR] Error setting last_sync_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.Collection != nil {
collectionItemMap := resourceIbmAppConfigSnapshotCollectionRefToMap(result.Collection)
if err = d.Set("collection", collectionItemMap); err != nil {
return fmt.Errorf("[ERROR] Error setting collection: %s", err)
return flex.FmtErrorf("[ERROR] Error setting collection: %s", err)
}
}
if result.Environment != nil {
environmentItemMap := resourceIbmAppConfigSnapshotEnvironmentRefToMap(result.Environment)
if err = d.Set("environment", environmentItemMap); err != nil {
return fmt.Errorf("[ERROR] Error setting environment: %s", err)
return flex.FmtErrorf("[ERROR] Error setting environment: %s", err)
}
}
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ func testAccCheckIbmAppConfigCollectionExists(n string, obj appconfigurationv1.C
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
return flex.FmtErrorf("Not found: %s", n)
}
parts, err := flex.IdParts(rs.Primary.ID)
if err != nil {
return err
return flex.FmtErrorf(fmt.Sprintf("%s", err))
}
appconfigClient, err := getAppConfigClient(acc.TestAccProvider.Meta(), parts[0])
if err != nil {
return err
return flex.FmtErrorf(fmt.Sprintf("%s", err))
}

options := &appconfigurationv1.GetCollectionOptions{}
Expand All @@ -93,7 +93,7 @@ func testAccCheckIbmAppConfigCollectionExists(n string, obj appconfigurationv1.C

result, _, err := appconfigClient.GetCollection(options)
if err != nil {
return err
return flex.FmtErrorf(fmt.Sprintf("%s", err))
}

obj = *result
Expand All @@ -109,11 +109,11 @@ func testAccCheckIbmAppConfigCollectionDestroy(s *terraform.State) error {
}
parts, err := flex.IdParts(rs.Primary.ID)
if err != nil {
return err
return flex.FmtErrorf(fmt.Sprintf("%s", err))
}
appconfigClient, err := getAppConfigClient(acc.TestAccProvider.Meta(), parts[0])
if err != nil {
return err
return flex.FmtErrorf(fmt.Sprintf("%s", err))
}
options := &appconfigurationv1.GetCollectionOptions{}

Expand All @@ -123,9 +123,9 @@ func testAccCheckIbmAppConfigCollectionDestroy(s *terraform.State) error {
_, response, err := appconfigClient.GetCollection(options)

if err == nil {
return fmt.Errorf("Collection still exists: %s", rs.Primary.ID)
return flex.FmtErrorf("Collection still exists: %s", rs.Primary.ID)
} else if response.StatusCode != 404 {
return fmt.Errorf("[ERROR] Error checking for Collection (%s) has been destroyed: %s", rs.Primary.ID, err)
return flex.FmtErrorf("[ERROR] Error checking for Collection (%s) has been destroyed: %s", rs.Primary.ID, err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func ResourceIBMAppConfigEnvironment() *schema.Resource {
func getAppConfigClient(meta interface{}, guid string) (*appconfigurationv1.AppConfigurationV1, error) {
appconfigClient, err := meta.(conns.ClientSession).AppConfigurationV1()
if err != nil {
return nil, err
return nil, flex.FmtErrorf(fmt.Sprintf("%s", err))
}
bluemixSession, err := meta.(conns.ClientSession).BluemixSession()
if err != nil {
return nil, err
return nil, flex.FmtErrorf(fmt.Sprintf("%s", err))
}
appConfigURL := fmt.Sprintf("https://%s.apprapp.cloud.ibm.com/apprapp/feature/v1/instances/%s", bluemixSession.Config.Region, guid)
url := conns.EnvFallBack([]string{"IBMCLOUD_APP_CONFIG_API_ENDPOINT"}, appConfigURL)
Expand All @@ -90,7 +90,7 @@ func resourceEnvironmentCreate(d *schema.ResourceData, meta interface{}) error {
guid := d.Get("guid").(string)
appconfigClient, err := getAppConfigClient(meta, guid)
if err != nil {
return err
return flex.FmtErrorf(fmt.Sprintf("%s", err))
}
options := &appconfigurationv1.CreateEnvironmentOptions{}

Expand Down Expand Up @@ -123,7 +123,7 @@ func resourceEnvironmentUpdate(d *schema.ResourceData, meta interface{}) error {
}
appconfigClient, err := getAppConfigClient(meta, parts[0])
if err != nil {
return err
return flex.FmtErrorf(fmt.Sprintf("%s", err))
}

options := &appconfigurationv1.UpdateEnvironmentOptions{}
Expand Down Expand Up @@ -156,7 +156,7 @@ func resourceEnvironmentRead(d *schema.ResourceData, meta interface{}) error {
}
appconfigClient, err := getAppConfigClient(meta, parts[0])
if err != nil {
return err
return flex.FmtErrorf(fmt.Sprintf("%s", err))
}

options := &appconfigurationv1.GetEnvironmentOptions{}
Expand Down Expand Up @@ -221,7 +221,7 @@ func resourceEnvironmentDelete(d *schema.ResourceData, meta interface{}) error {

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

options := &appconfigurationv1.DeleteEnvironmentOptions{}
Expand Down
Loading

0 comments on commit d480e47

Please sign in to comment.