diff --git a/pkg/client/private_cloud_gateway.go b/pkg/client/private_cloud_gateway.go index ddc0a004..2af11de9 100644 --- a/pkg/client/private_cloud_gateway.go +++ b/pkg/client/private_cloud_gateway.go @@ -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" ) @@ -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 +} diff --git a/spectrocloud/data_source_private_cloud_gateway.go b/spectrocloud/data_source_private_cloud_gateway.go new file mode 100644 index 00000000..d102564f --- /dev/null +++ b/spectrocloud/data_source_private_cloud_gateway.go @@ -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 +} diff --git a/spectrocloud/provider.go b/spectrocloud/provider.go index 31124eeb..bc874783 100644 --- a/spectrocloud/provider.go +++ b/spectrocloud/provider.go @@ -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, }