diff --git a/consul/data_source_consul_config_entry_v2_exported_services.go b/consul/data_source_consul_config_entry_v2_exported_services.go index af7706a0..12d4a180 100644 --- a/consul/data_source_consul_config_entry_v2_exported_services.go +++ b/consul/data_source_consul_config_entry_v2_exported_services.go @@ -83,13 +83,13 @@ func dataSourceConsulV2ExportedServicesRead(d *schema.ResourceData, meta interfa client, qOpts, _ := getClient(d, meta) name := d.Get("name").(string) kind := d.Get("kind").(string) - gvk := &GVK{ //&api.GVK{ - Group: "multicluster", - Version: "v2", + gvk := &GVK{ + Group: pbmulticluster.GroupName, + Version: pbmulticluster.Version, Kind: kind, } resp, err := v2MulticlusterRead(client, gvk, name, qOpts) - if err != nil || resp == nil { + if err != nil || resp == nil || resp["id"] == nil || resp["data"] == nil { return fmt.Errorf("exported services config not found: %s", name) } respData, err := json.Marshal(resp["data"]) @@ -106,7 +106,7 @@ func dataSourceConsulV2ExportedServicesRead(d *schema.ResourceData, meta interfa } id := &pbresource.ID{} if err = protojson.Unmarshal(respID, id); err != nil { - return fmt.Errorf("Failed to unmarshal to proto message: %v", err) + return fmt.Errorf("failed to unmarshal to proto message: %v", err) } var partitions []string var peers []string diff --git a/consul/resource_consul_config_entry_v2_exported_services.go b/consul/resource_consul_config_entry_v2_exported_services.go index cc68ff45..2bb1bb19 100644 --- a/consul/resource_consul_config_entry_v2_exported_services.go +++ b/consul/resource_consul_config_entry_v2_exported_services.go @@ -102,16 +102,13 @@ func resourceConsulV2ExportedServicesUpdate(d *schema.ResourceData, meta interfa Kind: kind, } var consumers []map[string]any - peerConsumers := d.Get("peer_consumers").([]interface{}) - for _, p := range peerConsumers { + for _, p := range d.Get("peer_consumers").([]interface{}) { consumers = append(consumers, map[string]any{"peer": p}) } - partitionConsumers := d.Get("partition_consumers").([]interface{}) - for _, ap := range partitionConsumers { + for _, ap := range d.Get("partition_consumers").([]interface{}) { consumers = append(consumers, map[string]any{"partition": ap}) } - samenessConsumers := d.Get("sameness_group_consumers").([]interface{}) - for _, sg := range samenessConsumers { + for _, sg := range d.Get("sameness_group_consumers").([]interface{}) { consumers = append(consumers, map[string]any{"sameness_group": sg}) } data := map[string]any{"consumers": consumers} @@ -142,8 +139,8 @@ func resourceConsulV2ExportedServicesRead(d *schema.ResourceData, meta interface name := d.Get("name").(string) kind := d.Get("kind").(string) gvk := &GVK{ - Group: "multicluster", - Version: "v2", + Group: pbmulticluster.GroupName, + Version: pbmulticluster.Version, Kind: kind, } resp, err := v2MulticlusterRead(client, gvk, name, qOpts) @@ -164,7 +161,7 @@ func resourceConsulV2ExportedServicesRead(d *schema.ResourceData, meta interface } id := &pbresource.ID{} if err = protojson.Unmarshal(respID, id); err != nil { - return fmt.Errorf("Failed to unmarshal to proto message: %v", err) + return fmt.Errorf("failed to unmarshal to proto message: %v", err) } var partitions []string var peers []string @@ -195,10 +192,11 @@ func resourceConsulV2ExportedServicesRead(d *schema.ResourceData, meta interface func resourceConsulV2ExportedServicesDelete(d *schema.ResourceData, meta interface{}) error { client, qOpts, _ := getClient(d, meta) + kind := d.Get("kind").(string) gvk := &GVK{ - Group: "multicluster", - Version: "v2", - Kind: "ExportedServices", + Group: pbmulticluster.GroupName, + Version: pbmulticluster.Version, + Kind: kind, } name := d.Get("name").(string) return v2MulticlusterDelete(client, gvk, name, qOpts)