From 6ab7898874326ffc38359d47b6683e182feecc98 Mon Sep 17 00:00:00 2001 From: zl0ty Date: Tue, 22 Oct 2024 14:33:27 +0200 Subject: [PATCH 1/8] switch from group name to group id --- cloudconnexa/data_source_user_group.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cloudconnexa/data_source_user_group.go b/cloudconnexa/data_source_user_group.go index f4849c8..ce025e9 100644 --- a/cloudconnexa/data_source_user_group.go +++ b/cloudconnexa/data_source_user_group.go @@ -15,12 +15,12 @@ func dataSourceUserGroup() *schema.Resource { Schema: map[string]*schema.Schema{ "id": { Type: schema.TypeString, - Computed: true, + Required: true, Description: "The user group ID.", }, "name": { Type: schema.TypeString, - Required: true, + Computed: true, Description: "The user group name.", }, "vpn_region_ids": { @@ -66,13 +66,13 @@ func dataSourceUserGroup() *schema.Resource { func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*cloudconnexa.Client) var diags diag.Diagnostics - userGroupName := d.Get("name").(string) - userGroup, err := c.UserGroups.GetByName(userGroupName) + userGroupId := d.Get("id").(string) + userGroup, err := c.UserGroups.Get(userGroupId) if err != nil { return append(diags, diag.FromErr(err)...) } if userGroup == nil { - return append(diags, diag.Errorf("User group with name %s was not found", userGroupName)...) + return append(diags, diag.Errorf("User group with id %s was not found", userGroupId)...) } d.SetId(userGroup.ID) d.Set("name", userGroup.Name) From 8bab3d9e32591299619b9aa52193bd2bd344a1d0 Mon Sep 17 00:00:00 2001 From: zl0ty Date: Mon, 4 Nov 2024 13:27:34 +0100 Subject: [PATCH 2/8] let id and name be optional --- cloudconnexa/data_source_user_group.go | 31 +++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cloudconnexa/data_source_user_group.go b/cloudconnexa/data_source_user_group.go index ce025e9..26ce103 100644 --- a/cloudconnexa/data_source_user_group.go +++ b/cloudconnexa/data_source_user_group.go @@ -2,6 +2,7 @@ package cloudconnexa import ( "context" + "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -15,12 +16,12 @@ func dataSourceUserGroup() *schema.Resource { Schema: map[string]*schema.Schema{ "id": { Type: schema.TypeString, - Required: true, + Optional: true, Description: "The user group ID.", }, "name": { Type: schema.TypeString, - Computed: true, + Optional: true, Description: "The user group name.", }, "vpn_region_ids": { @@ -66,13 +67,27 @@ func dataSourceUserGroup() *schema.Resource { func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*cloudconnexa.Client) var diags diag.Diagnostics + var userGroup cloudconnexa.UserGroup userGroupId := d.Get("id").(string) - userGroup, err := c.UserGroups.Get(userGroupId) - if err != nil { - return append(diags, diag.FromErr(err)...) - } - if userGroup == nil { - return append(diags, diag.Errorf("User group with id %s was not found", userGroupId)...) + userGroupName := d.Get("name").(string) + if userGroupId != "" { + userGroup, err := c.UserGroups.Get(userGroupId) + if err != nil { + return append(diags, diag.FromErr(err)...) + } + if userGroup == nil { + return append(diags, diag.Errorf("User group with id %s was not found", userGroupId)...) + } + } else if userGroupName != "" { + userGroup, err := c.UserGroups.GetByName(userGroupName) + if err != nil { + 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")...) } d.SetId(userGroup.ID) d.Set("name", userGroup.Name) From 75539ba77d971550c9957dae11adcba21ad1b94b Mon Sep 17 00:00:00 2001 From: zl0ty Date: Mon, 4 Nov 2024 17:31:48 +0100 Subject: [PATCH 3/8] change assignment --- cloudconnexa/data_source_user_group.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cloudconnexa/data_source_user_group.go b/cloudconnexa/data_source_user_group.go index 26ce103..1d3c4c0 100644 --- a/cloudconnexa/data_source_user_group.go +++ b/cloudconnexa/data_source_user_group.go @@ -67,11 +67,12 @@ func dataSourceUserGroup() *schema.Resource { func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*cloudconnexa.Client) var diags diag.Diagnostics - var userGroup cloudconnexa.UserGroup + var userGroup *cloudconnexa.UserGroup + var err error userGroupId := d.Get("id").(string) userGroupName := d.Get("name").(string) if userGroupId != "" { - userGroup, err := c.UserGroups.Get(userGroupId) + userGroup, err = c.UserGroups.Get(userGroupId) if err != nil { return append(diags, diag.FromErr(err)...) } @@ -79,7 +80,7 @@ func dataSourceUserGroupRead(ctx context.Context, d *schema.ResourceData, m inte return append(diags, diag.Errorf("User group with id %s was not found", userGroupId)...) } } else if userGroupName != "" { - userGroup, err := c.UserGroups.GetByName(userGroupName) + userGroup, err = c.UserGroups.GetByName(userGroupName) if err != nil { return append(diags, diag.FromErr(err)...) } From 9541863df8136096e98d4ad8eac50c75ee10ffea Mon Sep 17 00:00:00 2001 From: zl0ty Date: Tue, 5 Nov 2024 11:54:43 +0100 Subject: [PATCH 4/8] id or name changes --- cloudconnexa/data_source_application.go | 43 +++++++++++++------ cloudconnexa/data_source_connector.go | 57 ++++++++++++++++++------- cloudconnexa/data_source_network.go | 42 ++++++++++++------ cloudconnexa/data_source_user_group.go | 14 +++--- 4 files changed, 110 insertions(+), 46 deletions(-) diff --git a/cloudconnexa/data_source_application.go b/cloudconnexa/data_source_application.go index 691cc97..a3196a5 100644 --- a/cloudconnexa/data_source_application.go +++ b/cloudconnexa/data_source_application.go @@ -2,6 +2,7 @@ package cloudconnexa import ( "context" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" @@ -12,12 +13,16 @@ func dataSourceApplication() *schema.Resource { ReadContext: dataSourceApplicationRead, Schema: map[string]*schema.Schema{ "id": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: []string{"id", "name"}, + Description: "Application ID", }, "name": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: []string{"id", "name"}, + Description: "Application name", }, "description": { Type: schema.TypeString, @@ -48,14 +53,28 @@ func dataSourceApplication() *schema.Resource { func dataSourceApplicationRead(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics { c := i.(*cloudconnexa.Client) var diags diag.Diagnostics - var name = data.Get("name").(string) - application, err := c.Applications.GetByName(name) - - if err != nil { - return diag.FromErr(err) - } - if application == nil { - return append(diags, diag.Errorf("Application with name %s was not found", name)...) + var application *cloudconnexa.ApplicationResponse + var err error + applicationId := data.Get("id").(string) + applicationName := data.Get("name").(string) + if applicationId != "" { + application, err = c.Applications.Get(applicationId) + if err != nil { + return diag.FromErr(err) + } + if application == nil { + return append(diags, diag.Errorf("Application with id %s was not found", applicationId)...) + } + } else if applicationName != "" { + application, err = c.Applications.GetByName(applicationName) + if err != nil { + return diag.FromErr(err) + } + if application == nil { + return append(diags, diag.Errorf("Application with name %s was not found", applicationName)...) + } + } else { + return append(diags, diag.Errorf("Application name or id is missing")...) } setApplicationData(data, application) return nil diff --git a/cloudconnexa/data_source_connector.go b/cloudconnexa/data_source_connector.go index 7e8ed18..33f0528 100644 --- a/cloudconnexa/data_source_connector.go +++ b/cloudconnexa/data_source_connector.go @@ -2,6 +2,7 @@ package cloudconnexa import ( "context" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" @@ -13,13 +14,16 @@ func dataSourceConnector() *schema.Resource { ReadContext: dataSourceConnectorRead, Schema: map[string]*schema.Schema{ "id": { - Type: schema.TypeString, - Computed: true, + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: []string{"id", "name"}, + Description: "The ID of the connector.", }, "name": { - Type: schema.TypeString, - Required: true, - Description: "The name of the connector.", + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: []string{"id", "name"}, + Description: "The name of the connector.", }, "description": { Type: schema.TypeString, @@ -68,17 +72,38 @@ func dataSourceConnector() *schema.Resource { func dataSourceConnectorRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*cloudconnexa.Client) var diags diag.Diagnostics - name := d.Get("name").(string) - connector, err := c.Connectors.GetByName(name) - if err != nil { - return append(diags, diag.FromErr(err)...) - } - if connector == nil { - return append(diags, diag.Errorf("Connector with name %s was not found", name)...) - } - token, err := c.Connectors.GetToken(connector.Id) - if err != nil { - return append(diags, diag.FromErr(err)...) + var connector *cloudconnexa.Connector + var err error + var token string + connectorName := d.Get("name").(string) + connectorId := d.Get("id").(string) + if connectorId != "" { + connector, err = c.Connectors.GetByID(connectorId) + if err != nil { + return append(diags, diag.FromErr(err)...) + } + if connector == nil { + return append(diags, diag.Errorf("Connector with id %s was not found", connectorId)...) + } + token, err = c.Connectors.GetToken(connector.Id) + if err != nil { + return append(diags, diag.FromErr(err)...) + } + } else if connectorName != "" { + connector, err = c.Connectors.GetByName(connectorName) + if err != nil { + return append(diags, diag.FromErr(err)...) + } + if connector == nil { + return append(diags, diag.Errorf("Connector with name %s was not found", connectorName)...) + } + token, err = c.Connectors.GetToken(connector.Id) + if err != nil { + return append(diags, diag.FromErr(err)...) + } + + } else { + return append(diags, diag.Errorf("Connector name or id is missing")...) } d.SetId(connector.Id) diff --git a/cloudconnexa/data_source_network.go b/cloudconnexa/data_source_network.go index 155517e..782b2a4 100644 --- a/cloudconnexa/data_source_network.go +++ b/cloudconnexa/data_source_network.go @@ -2,6 +2,7 @@ package cloudconnexa import ( "context" + "github.com/openvpn/cloudconnexa-go-client/v2/cloudconnexa" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -14,14 +15,16 @@ func dataSourceNetwork() *schema.Resource { ReadContext: dataSourceNetworkRead, Schema: map[string]*schema.Schema{ "id": { - Type: schema.TypeString, - Computed: true, - Description: "The network ID.", + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: []string{"id", "name"}, + Description: "The network ID.", }, "name": { - Type: schema.TypeString, - Required: true, - Description: "The network name.", + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: []string{"id", "name"}, + Description: "The network name.", }, "description": { Type: schema.TypeString, @@ -131,13 +134,28 @@ func dataSourceNetwork() *schema.Resource { func dataSourceNetworkRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { c := m.(*cloudconnexa.Client) var diags diag.Diagnostics + var network *cloudconnexa.Network + var err error + networkId := d.Get("id").(string) networkName := d.Get("name").(string) - network, err := c.Networks.GetByName(networkName) - if err != nil { - return append(diags, diag.FromErr(err)...) - } - if network == nil { - return append(diags, diag.Errorf("Network with name %s was not found", networkName)...) + if networkId != "" { + network, err = c.Networks.Get(networkId) + if err != nil { + return append(diags, diag.FromErr(err)...) + } + if network == nil { + return append(diags, diag.Errorf("Network with id %s was not found", networkId)...) + } + } else if networkName != "" { + network, err = c.Networks.GetByName(networkName) + if err != nil { + return append(diags, diag.FromErr(err)...) + } + if network == nil { + 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")...) } 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 1d3c4c0..ff1ef57 100644 --- a/cloudconnexa/data_source_user_group.go +++ b/cloudconnexa/data_source_user_group.go @@ -15,14 +15,16 @@ func dataSourceUserGroup() *schema.Resource { ReadContext: dataSourceUserGroupRead, Schema: map[string]*schema.Schema{ "id": { - Type: schema.TypeString, - Optional: true, - Description: "The user group ID.", + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: []string{"id", "name"}, + Description: "The user group ID.", }, "name": { - Type: schema.TypeString, - Optional: true, - Description: "The user group name.", + Type: schema.TypeString, + Optional: true, + AtLeastOneOf: []string{"id", "name"}, + Description: "The user group name.", }, "vpn_region_ids": { Type: schema.TypeList, From 7632b503ddc639b420bfa4f473ed9a843cc2d9fd Mon Sep 17 00:00:00 2001 From: zl0ty Date: Tue, 5 Nov 2024 13:11:01 +0100 Subject: [PATCH 5/8] change validation function --- cloudconnexa/data_source_application.go | 4 ++-- cloudconnexa/data_source_connector.go | 4 ++-- cloudconnexa/data_source_network.go | 4 ++-- cloudconnexa/data_source_user_group.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cloudconnexa/data_source_application.go b/cloudconnexa/data_source_application.go index a3196a5..59f792d 100644 --- a/cloudconnexa/data_source_application.go +++ b/cloudconnexa/data_source_application.go @@ -15,13 +15,13 @@ func dataSourceApplication() *schema.Resource { "id": { Type: schema.TypeString, Optional: true, - AtLeastOneOf: []string{"id", "name"}, + ExactlyOneOf: []string{"id", "name"}, Description: "Application ID", }, "name": { Type: schema.TypeString, Optional: true, - AtLeastOneOf: []string{"id", "name"}, + ExactlyOneOf: []string{"id", "name"}, Description: "Application name", }, "description": { diff --git a/cloudconnexa/data_source_connector.go b/cloudconnexa/data_source_connector.go index 33f0528..63393f5 100644 --- a/cloudconnexa/data_source_connector.go +++ b/cloudconnexa/data_source_connector.go @@ -16,13 +16,13 @@ func dataSourceConnector() *schema.Resource { "id": { Type: schema.TypeString, Optional: true, - AtLeastOneOf: []string{"id", "name"}, + ExactlyOneOf: []string{"id", "name"}, Description: "The ID of the connector.", }, "name": { Type: schema.TypeString, Optional: true, - AtLeastOneOf: []string{"id", "name"}, + ExactlyOneOf: []string{"id", "name"}, Description: "The name of the connector.", }, "description": { diff --git a/cloudconnexa/data_source_network.go b/cloudconnexa/data_source_network.go index 782b2a4..ce0bf73 100644 --- a/cloudconnexa/data_source_network.go +++ b/cloudconnexa/data_source_network.go @@ -17,13 +17,13 @@ func dataSourceNetwork() *schema.Resource { "id": { Type: schema.TypeString, Optional: true, - AtLeastOneOf: []string{"id", "name"}, + ExactlyOneOf: []string{"id", "name"}, Description: "The network ID.", }, "name": { Type: schema.TypeString, Optional: true, - AtLeastOneOf: []string{"id", "name"}, + ExactlyOneOf: []string{"id", "name"}, Description: "The network name.", }, "description": { diff --git a/cloudconnexa/data_source_user_group.go b/cloudconnexa/data_source_user_group.go index ff1ef57..efa28a9 100644 --- a/cloudconnexa/data_source_user_group.go +++ b/cloudconnexa/data_source_user_group.go @@ -17,13 +17,13 @@ func dataSourceUserGroup() *schema.Resource { "id": { Type: schema.TypeString, Optional: true, - AtLeastOneOf: []string{"id", "name"}, + ExactlyOneOf: []string{"id", "name"}, Description: "The user group ID.", }, "name": { Type: schema.TypeString, Optional: true, - AtLeastOneOf: []string{"id", "name"}, + ExactlyOneOf: []string{"id", "name"}, Description: "The user group name.", }, "vpn_region_ids": { From 14ae04aa1f92cd6058cdc764238101acb802fdfb Mon Sep 17 00:00:00 2001 From: zl0ty Date: Thu, 7 Nov 2024 14:23:46 +0100 Subject: [PATCH 6/8] detecting duplicate entries --- cloudconnexa/data_source_application.go | 19 +++++++++++++++++-- cloudconnexa/data_source_connector.go | 20 ++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/cloudconnexa/data_source_application.go b/cloudconnexa/data_source_application.go index 59f792d..ec86d93 100644 --- a/cloudconnexa/data_source_application.go +++ b/cloudconnexa/data_source_application.go @@ -66,12 +66,27 @@ func dataSourceApplicationRead(ctx context.Context, data *schema.ResourceData, i return append(diags, diag.Errorf("Application with id %s was not found", applicationId)...) } } else if applicationName != "" { - application, err = c.Applications.GetByName(applicationName) + applicationsAll, err := c.Applications.List() + var applicationCount int if err != nil { return diag.FromErr(err) } - if application == nil { + + for _, app := range applicationsAll { + if app.Name == applicationName { + applicationCount++ + } + } + + if applicationCount == 0 { return append(diags, diag.Errorf("Application with name %s was not found", applicationName)...) + } else if applicationCount > 1 { + return append(diags, diag.Errorf("More than 1 application with name %s was found. Please use id instead", applicationName)...) + } else { + application, err = c.Applications.GetByName(applicationName) + if err != nil { + return diag.FromErr(err) + } } } else { return append(diags, diag.Errorf("Application name or id is missing")...) diff --git a/cloudconnexa/data_source_connector.go b/cloudconnexa/data_source_connector.go index 63393f5..061f2ed 100644 --- a/cloudconnexa/data_source_connector.go +++ b/cloudconnexa/data_source_connector.go @@ -90,13 +90,29 @@ func dataSourceConnectorRead(ctx context.Context, d *schema.ResourceData, m inte return append(diags, diag.FromErr(err)...) } } else if connectorName != "" { - connector, err = c.Connectors.GetByName(connectorName) + connectorsAll, err := c.Connectors.List() + var connectorCount int if err != nil { return append(diags, diag.FromErr(err)...) } - if connector == nil { + + for _, con := range connectorsAll { + if con.Name == connectorName { + connectorCount++ + } + } + + if connectorCount == 0 { return append(diags, diag.Errorf("Connector with name %s was not found", connectorName)...) + } else if connectorCount > 1 { + return append(diags, diag.Errorf("More than 1 connector with name %s was found. Please use id instead", connectorName)...) + } else { + connector, err = c.Connectors.GetByName(connectorName) + if err != nil { + return append(diags, diag.FromErr(err)...) + } } + token, err = c.Connectors.GetToken(connector.Id) if err != nil { return append(diags, diag.FromErr(err)...) From 895d0fe7a0dea495fd639c657a2e7edecf6aa8f7 Mon Sep 17 00:00:00 2001 From: zl0ty Date: Tue, 19 Nov 2024 15:40:43 +0100 Subject: [PATCH 7/8] fix error handling --- cloudconnexa/data_source_application.go | 14 +++++++++++--- cloudconnexa/data_source_network.go | 2 +- cloudconnexa/data_source_user_group.go | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) 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) From 2fb258315ad6eefd4b4a7e5d2d7da22705f0d8d3 Mon Sep 17 00:00:00 2001 From: zl0ty Date: Thu, 21 Nov 2024 13:15:35 +0100 Subject: [PATCH 8/8] fix application data --- cloudconnexa/data_source_application.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cloudconnexa/data_source_application.go b/cloudconnexa/data_source_application.go index 3f4060a..022f461 100644 --- a/cloudconnexa/data_source_application.go +++ b/cloudconnexa/data_source_application.go @@ -96,9 +96,6 @@ func dataSourceApplicationRead(ctx context.Context, data *schema.ResourceData, i } else { return append(diags, diag.Errorf("Application name or id is missing")...) } - // setApplicationData(data, application) - data.SetId(application.Id) - data.Set("name", application.Name) - return diags - // return nil + setApplicationData(data, application) + return nil }