diff --git a/cloudconnexa/data_source_application.go b/cloudconnexa/data_source_application.go index ec86d93..3f4060a 100644 --- a/cloudconnexa/data_source_application.go +++ b/cloudconnexa/data_source_application.go @@ -2,6 +2,7 @@ package cloudconnexa import ( "context" + "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -60,7 +61,11 @@ func dataSourceApplicationRead(ctx context.Context, data *schema.ResourceData, i if applicationId != "" { application, err = c.Applications.Get(applicationId) if err != nil { - return diag.FromErr(err) + if strings.Contains(err.Error(), "status code: 404") { + return append(diags, diag.Errorf("Application with id %s was not found", applicationId)...) + } else { + return append(diags, diag.FromErr(err)...) + } } if application == nil { return append(diags, diag.Errorf("Application with id %s was not found", applicationId)...) @@ -91,6 +96,9 @@ func dataSourceApplicationRead(ctx context.Context, data *schema.ResourceData, i } else { return append(diags, diag.Errorf("Application name or id is missing")...) } - setApplicationData(data, application) - return nil + // setApplicationData(data, application) + data.SetId(application.Id) + data.Set("name", application.Name) + return diags + // return nil } diff --git a/cloudconnexa/data_source_network.go b/cloudconnexa/data_source_network.go index ce0bf73..49b9195 100644 --- a/cloudconnexa/data_source_network.go +++ b/cloudconnexa/data_source_network.go @@ -155,7 +155,7 @@ func dataSourceNetworkRead(ctx context.Context, d *schema.ResourceData, m interf return append(diags, diag.Errorf("Network with name %s was not found", networkName)...) } } else { - return append(diags, diag.Errorf("Network name or id is missing")...) + return append(diags, diag.Errorf("Network name or id is missing")...) } d.SetId(network.Id) d.Set("name", network.Name) diff --git a/cloudconnexa/data_source_user_group.go b/cloudconnexa/data_source_user_group.go index efa28a9..1e88ce8 100644 --- a/cloudconnexa/data_source_user_group.go +++ b/cloudconnexa/data_source_user_group.go @@ -2,6 +2,7 @@ package cloudconnexa import ( "context" + "strings" "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" @@ -76,7 +77,11 @@ func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m inte if userGroupId != "" { userGroup, err = c.UserGroups.Get(userGroupId) if err != nil { - return append(diags, diag.FromErr(err)...) + if strings.Contains(err.Error(), "user group not found") { + return append(diags, diag.Errorf("User group with id %s was not found", userGroupId)...) + } else { + return append(diags, diag.FromErr(err)...) + } } if userGroup == nil { return append(diags, diag.Errorf("User group with id %s was not found", userGroupId)...) @@ -84,13 +89,17 @@ func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m inte } else if userGroupName != "" { userGroup, err = c.UserGroups.GetByName(userGroupName) if err != nil { - return append(diags, diag.FromErr(err)...) + if strings.Contains(err.Error(), "user group not found") { + return append(diags, diag.Errorf("User group with name %s was not found", userGroupName)...) + } else { + return append(diags, diag.FromErr(err)...) + } } if userGroup == nil { return append(diags, diag.Errorf("User group with name %s was not found", userGroupName)...) } } else { - return append(diags, diag.Errorf("User group name or group id is missing")...) + return append(diags, diag.Errorf("User group name or id is missing")...) } d.SetId(userGroup.ID) d.Set("name", userGroup.Name)