Skip to content

Commit

Permalink
Add systemInfo data source
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorGFM committed Sep 26, 2023
1 parent 0a1434d commit 7b72ed1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions cyral/data_source_cyral_system_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cyral

import (
"fmt"
"net/http"

"github.com/cyralinc/terraform-provider-cyral/client"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const (
// Schema keys
ControlPlaneVersionKey = "control_plane_version"
SidecarLatestVersionKey = "sidecar_latest_version"
)

type SystemInfo struct {
ControlPlaneVersion string `json:"controlPlaneVersion"`
SidecarLatestVersion string `json:"sidecarLatestVersion"`
}

func (systemInfo *SystemInfo) WriteToSchema(d *schema.ResourceData) error {
d.SetId(uuid.New().String())
d.Set(ControlPlaneVersionKey, systemInfo.ControlPlaneVersion)
d.Set(SidecarLatestVersionKey, systemInfo.SidecarLatestVersion)

return nil
}

func dataSourceSystemInfo() *schema.Resource {
return &schema.Resource{
Description: "Retrieve information from Cyral systems.",
ReadContext: ReadResource(ResourceOperationConfig{
Name: "SystemInfoDataSourceRead",
HttpMethod: http.MethodGet,
CreateURL: func(d *schema.ResourceData, c *client.Client) string {
return fmt.Sprintf("https://%s/v1/systemInfo", c.ControlPlane)
},
NewResponseData: func(_ *schema.ResourceData) ResponseData {
return &SystemInfo{}
},
}),
Schema: map[string]*schema.Schema{
IDKey: {
Description: "The data source identifier.",
Type: schema.TypeString,
Computed: true,
},
ControlPlaneVersionKey: {
Description: "The Control Plane version.",
Type: schema.TypeString,
Computed: true,
},
SidecarLatestVersionKey: {
Description: "The latest Sidecar version available to this Control Plane.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
1 change: 1 addition & 0 deletions cyral/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func Provider() *schema.Provider {
"cyral_sidecar_id": dataSourceSidecarID(),
"cyral_sidecar_instance_ids": dataSourceSidecarInstanceIDs(),
"cyral_sidecar_listener": dataSourceSidecarListener(),
"cyral_system_info": dataSourceSystemInfo(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down

0 comments on commit 7b72ed1

Please sign in to comment.