Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-12511: Add data source for systemInfo API #455

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 system.",
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: "Data source identifier.",
Type: schema.TypeString,
Computed: true,
},
ControlPlaneVersionKey: {
Description: "Control Plane version.",
Type: schema.TypeString,
Computed: true,
},
SidecarLatestVersionKey: {
Description: "Latest Sidecar version available to this Control Plane.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
49 changes: 49 additions & 0 deletions cyral/data_source_cyral_system_info_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cyral

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

const (
systemInfoDataSourceFullNameFmt = "data.cyral_system_info.%s"
)

func TestAccSystemInfoDataSource(t *testing.T) {
dataSourceName := "system_info"
testSteps := []resource.TestStep{
accTestStepSystemInfoDataSource_ListAllSystemInfo(dataSourceName),
}
resource.ParallelTest(t, resource.TestCase{
ProviderFactories: providerFactories,
Steps: testSteps,
})
}

func accTestStepSystemInfoDataSource_ListAllSystemInfo(dataSourceName string) resource.TestStep {
dataSourceFullName := fmt.Sprintf(systemInfoDataSourceFullNameFmt, dataSourceName)
config := fmt.Sprintf(`
data "cyral_system_info" "%s" {
}
`, dataSourceName)
check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
dataSourceFullName,
IDKey,
),
resource.TestCheckResourceAttrSet(
dataSourceFullName,
ControlPlaneVersionKey,
),
resource.TestCheckResourceAttrSet(
dataSourceFullName,
SidecarLatestVersionKey,
),
)
return resource.TestStep{
Config: config,
Check: check,
}
}
1 change: 1 addition & 0 deletions cyral/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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
21 changes: 21 additions & 0 deletions docs/data-sources/system_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "cyral_system_info Data Source - terraform-provider-cyral"
subcategory: ""
description: |-
Retrieve information from Cyral system.
---

# cyral_system_info (Data Source)

Retrieve information from Cyral system.

<!-- schema generated by tfplugindocs -->

## Schema

### Read-Only

- `control_plane_version` (String) Control Plane version.
- `id` (String) Data source identifier.
- `sidecar_latest_version` (String) Latest Sidecar version available to this Control Plane.
Loading