Skip to content

Commit

Permalink
PLT-273:Datasource for PCG (#207)
Browse files Browse the repository at this point in the history
* PLT-273:Datasource for PCG

* Update spectrocloud/provider.go

---------

Co-authored-by: nikchern <[email protected]>
  • Loading branch information
SivaanandM and nikchern authored Jan 27, 2023
1 parent be11d10 commit dd7b969
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/client/private_cloud_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"github.com/spectrocloud/hapi/apiutil"
"github.com/spectrocloud/hapi/models"

clusterC "github.com/spectrocloud/hapi/spectrocluster/client/v1"
)

Expand Down Expand Up @@ -64,3 +63,8 @@ func (h *V1Client) DeleteIpPool(pcgUID, poolUID string) error {
_, err = client.V1OverlordsUIDPoolDelete(params)
return err
}

func (h *V1Client) GetPrivateCloudGatewayID(name *string) (string, error) {
// Need to call overload api
return "{id}", nil
}
47 changes: 47 additions & 0 deletions spectrocloud/data_source_private_cloud_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package spectrocloud

import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/spectrocloud/terraform-provider-spectrocloud/pkg/client"
)

func dataSourcePCG() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourcePCGRead,

Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ConflictsWith: []string{"name"},
Description: "The ID of Private Cloud Gateways.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The Name of Private Cloud Gateways.",
},
},
}
}

func dataSourcePCGRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*client.V1Client)
var diags diag.Diagnostics
if v, ok := d.GetOk("name"); ok {
name := v.(string)
var namePointer *string
namePointer = &name
uid, err := c.GetPrivateCloudGatewayID(namePointer)
if err != nil {
return diag.FromErr(err)
}
d.SetId(uid)
d.Set("name", v.(string))
}
return diags
}
1 change: 1 addition & 0 deletions spectrocloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func New(_ string) func() *schema.Provider {
"spectrocloud_cluster_group": dataSourceClusterGroup(),
"spectrocloud_application_profile": dataSourceApplicationProfile(),
"spectrocloud_workspace": dataSourceWorkspace(),
"spectrocloud_private_cloud_gateway": dataSourcePCG(),
},
ConfigureContextFunc: providerConfigure,
}
Expand Down

0 comments on commit dd7b969

Please sign in to comment.