Skip to content

Commit

Permalink
Merge pull request #11 from squaredup/work/ss/code-review
Browse files Browse the repository at this point in the history
Rename of Data Source and Simplify DataSource Config
  • Loading branch information
shaswot77 authored Oct 26, 2023
2 parents 84a6b4d + 3d05c1f commit fffac66
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 127 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
terraform:
- '1.6.*'
- latest
max-parallel: 1
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "squaredup_latest_datasources Data Source - terraform-provider-squaredup"
page_title: "squaredup_datasources Data Source - terraform-provider-squaredup"
subcategory: ""
description: |-
Data Sources are used to query third party APIs and SquaredUp visualizes the results
---

# squaredup_latest_datasources (Data Source)
# squaredup_datasources (Data Source)

Data Sources are used to query third party APIs and SquaredUp visualizes the results

## Example Usage

```terraform
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}
```
Expand Down
6 changes: 3 additions & 3 deletions docs/resources/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Dashboard are used to visualize data from Data Sources
## Example Usage

```terraform
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}
resource "squaredup_datasource" "sample_data_source" {
display_name = "Sample Data"
data_source_name = data.squaredup_latest_datasources.sample_data.plugins[0].display_name
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
}
resource "squaredup_workspace" "application_workspace" {
Expand All @@ -29,7 +29,7 @@ resource "squaredup_workspace" "application_workspace" {
}
data "squaredup_data_streams" "sample_data_logs_dataStreams" {
data_source_id = data.squaredup_latest_datasources.sample_data.plugins[0].id
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id
}
locals {
Expand Down
16 changes: 12 additions & 4 deletions docs/resources/datasource.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ Data Sources are used to query third party APIs and SquaredUp visualizes the res
## Example Usage

```terraform
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}
resource "squaredup_datasource" "sample_data_source" {
display_name = "Sample Data"
data_source_name = data.squaredup_latest_datasources.sample_data.plugins[0].display_name
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
}
resource "squaredup_datasource" "ado_datasource" {
display_name = "Azure DevOps"
data_source_name = "Azure DevOps"
config = jsonencode({
org = "org-name"
accessToken = "access-token"
})
}
```

Expand All @@ -34,8 +43,7 @@ resource "squaredup_datasource" "sample_data_source" {
### Optional

- `agent_group_id` (String) The ID of the agent group to which the data source should connect to (on-prem data sources only)
- `json_data_encoded` (String) Additional configuration for configuring data source. Needs to be a valid JSON
- `secure_json_data_encoded` (String, Sensitive) Sensitive configuration for the data source. Needs to be a valid JSON
- `config` (String, Sensitive) Sensitive configuration for the data source. Needs to be a valid JSON

### Read-Only

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Each workspace has its own dashboards, data sources, monitors and scopes.
## Example Usage

```terraform
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}
resource "squaredup_datasource" "sample_data_source" {
display_name = "Sample Data"
data_source_name = data.squaredup_latest_datasources.sample_data.plugins[0].display_name
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
}
resource "squaredup_workspace" "application_workspace" {
Expand Down
3 changes: 3 additions & 0 deletions examples/data-sources/squaredup_datasources/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}

This file was deleted.

6 changes: 3 additions & 3 deletions examples/resources/squaredup_dashboard/resource.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}

resource "squaredup_datasource" "sample_data_source" {
display_name = "Sample Data"
data_source_name = data.squaredup_latest_datasources.sample_data.plugins[0].display_name
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
}

resource "squaredup_workspace" "application_workspace" {
Expand All @@ -14,7 +14,7 @@ resource "squaredup_workspace" "application_workspace" {
}

data "squaredup_data_streams" "sample_data_logs_dataStreams" {
data_source_id = data.squaredup_latest_datasources.sample_data.plugins[0].id
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id
}

locals {
Expand Down
13 changes: 11 additions & 2 deletions examples/resources/squaredup_datasource/resource.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}

resource "squaredup_datasource" "sample_data_source" {
display_name = "Sample Data"
data_source_name = data.squaredup_latest_datasources.sample_data.plugins[0].display_name
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
}

resource "squaredup_datasource" "ado_datasource" {
display_name = "Azure DevOps"
data_source_name = "Azure DevOps"
config = jsonencode({
org = "org-name"
accessToken = "access-token"
})
}
4 changes: 2 additions & 2 deletions examples/resources/squaredup_workspace/resource.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}

resource "squaredup_datasource" "sample_data_source" {
display_name = "Sample Data"
data_source_name = data.squaredup_latest_datasources.sample_data.plugins[0].display_name
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
}

resource "squaredup_workspace" "application_workspace" {
Expand Down
22 changes: 10 additions & 12 deletions examples/test-setup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@ provider "squaredup" {
api_key = "api-key"
}

data "squaredup_latest_datasources" "azure_devops" {
data "squaredup_datasources" "azure_devops" {
data_source_name = "Azure DevOps"
}

data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}

resource "squaredup_datasource" "ado_datasource" {
display_name = "Azure DevOps"
data_source_name = data.squaredup_latest_datasources.azure_devops.plugins[0].display_name
json_data_encoded = jsonencode({
org = "org-name"
})
secure_json_data_encoded = jsonencode({
data_source_name = data.squaredup_datasources.azure_devops.plugins[0].display_name
config = jsonencode({
org = "org-name"
accessToken = "access-token"
})
}

resource "squaredup_datasource" "sample_data_source" {
display_name = "Sample Data"
data_source_name = data.squaredup_latest_datasources.sample_data.plugins[0].display_name
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
}

resource "squaredup_workspace" "application_workspace" {
Expand All @@ -51,7 +49,7 @@ resource "squaredup_workspace" "devops_workspace" {
}

data "squaredup_data_streams" "azure_devops_dataStreams" {
data_source_id = data.squaredup_latest_datasources.azure_devops.plugins[0].id
data_source_id = data.squaredup_datasources.azure_devops.plugins[0].id
}

locals {
Expand All @@ -60,17 +58,17 @@ locals {
}

data "squaredup_data_streams" "sample_data_logs_dataStreams" {
data_source_id = data.squaredup_latest_datasources.sample_data.plugins[0].id
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id
data_stream_definition_name = "logs"
}

data "squaredup_data_streams" "sample_data_lambdaerrors_dataStreams" {
data_source_id = data.squaredup_latest_datasources.sample_data.plugins[0].id
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id
data_stream_definition_name = "perf-lambda-errors"
}

resource "squaredup_dashboard" "devops_team_dashboard" {
dashboard_template = file(".\\dashboardTemplate.json")
dashboard_template = file("dashboardTemplate.json")
template_bindings = jsonencode({
azure_devops_data_source_id = squaredup_datasource.ado_datasource.id
sample_data_source_id = squaredup_datasource.sample_data_source.id
Expand Down
19 changes: 5 additions & 14 deletions internal/provider/client_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *SquaredUpClient) GetLatestDataSources(filterDisplayName string) ([]Late
return plugins, nil
}

func (c *SquaredUpClient) GenerateDataSourcePayload(displayName string, name string, pluginConfig map[string]interface{}, secureJsonData map[string]interface{}, agentGroupId string) (map[string]interface{}, error) {
func (c *SquaredUpClient) GenerateDataSourcePayload(displayName string, name string, pluginConfig map[string]interface{}, agentGroupId string) (map[string]interface{}, error) {
plugins, err := c.GetLatestDataSources(name)
if err != nil {
return nil, err
Expand Down Expand Up @@ -76,20 +76,11 @@ func (c *SquaredUpClient) GenerateDataSourcePayload(displayName string, name str
config[key] = value
}

for key, value := range secureJsonData {
config, ok := DataSourcePayload["config"].(map[string]interface{})
if !ok {
config = make(map[string]interface{})
DataSourcePayload["config"] = config
}
config[key] = value
}

return DataSourcePayload, nil
}

func (c *SquaredUpClient) AddDataSource(displayName string, name string, pluginConfig map[string]interface{}, secureJsonData map[string]interface{}, agentGroupId string) (*DataSource, error) {
DataSourcePayload, err := c.GenerateDataSourcePayload(displayName, name, pluginConfig, secureJsonData, agentGroupId)
func (c *SquaredUpClient) AddDataSource(displayName string, name string, pluginConfig map[string]interface{}, agentGroupId string) (*DataSource, error) {
DataSourcePayload, err := c.GenerateDataSourcePayload(displayName, name, pluginConfig, agentGroupId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -138,8 +129,8 @@ func (c *SquaredUpClient) GetDataSource(dataSourceId string) (*DataSource, error
return &dataSource, nil
}

func (c *SquaredUpClient) UpdateDataSource(dataSourceId string, displayName string, name string, pluginConfig map[string]interface{}, secureJsonData map[string]interface{}, agentGroupId string) error {
DataSourcePayload, err := c.GenerateDataSourcePayload(displayName, name, pluginConfig, secureJsonData, agentGroupId)
func (c *SquaredUpClient) UpdateDataSource(dataSourceId string, displayName string, name string, pluginConfig map[string]interface{}, agentGroupId string) error {
DataSourcePayload, err := c.GenerateDataSourcePayload(displayName, name, pluginConfig, agentGroupId)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type squaredupPluginModel struct {
}

func (d *squaredupLatestDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_latest_datasources"
resp.TypeName = req.ProviderTypeName + "_datasources"
}

func (d *squaredupLatestDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/data_source_data_streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func TestDataStreamsDataSource(t *testing.T) {
{
Config: providerConfig +
`
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}
data "squaredup_data_streams" "sample_data_logs_dataStreams" {
data_source_id = data.squaredup_latest_datasources.sample_data.plugins[0].id
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id
data_stream_definition_name = "logs"
}
`,
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_latest_data_sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ func TestLatestDataSourcesDataSource(t *testing.T) {
{
Config: providerConfig +
`
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.squaredup_latest_datasources.sample_data", "plugins.#", "1"),
resource.TestCheckResourceAttr("data.squaredup_latest_datasources.sample_data", "plugins.0.display_name", "Sample Data"),
resource.TestCheckResourceAttr("data.squaredup_datasources.sample_data", "plugins.#", "1"),
resource.TestCheckResourceAttr("data.squaredup_datasources.sample_data", "plugins.0.display_name", "Sample Data"),
),
},
},
Expand Down
12 changes: 6 additions & 6 deletions internal/provider/resource_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ func TestDashboardResource(t *testing.T) {
//Create Dashboard Test
{
Config: providerConfig + `
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}
resource "squaredup_datasource" "sample_data_source" {
display_name = "Sample Data"
data_source_name = data.squaredup_latest_datasources.sample_data.plugins[0].display_name
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
}
resource "squaredup_workspace" "application_workspace" {
Expand All @@ -29,7 +29,7 @@ resource "squaredup_workspace" "application_workspace" {
}
data "squaredup_data_streams" "sample_data_logs_dataStreams" {
data_source_id = data.squaredup_latest_datasources.sample_data.plugins[0].id
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id
}
locals {
Expand Down Expand Up @@ -149,13 +149,13 @@ EOT
//Update Dashboard Test
{
Config: providerConfig + `
data "squaredup_latest_datasources" "sample_data" {
data "squaredup_datasources" "sample_data" {
data_source_name = "Sample Data"
}
resource "squaredup_datasource" "sample_data_source" {
display_name = "Sample Data"
data_source_name = data.squaredup_latest_datasources.sample_data.plugins[0].display_name
data_source_name = data.squaredup_datasources.sample_data.plugins[0].display_name
}
resource "squaredup_workspace" "application_workspace" {
Expand All @@ -165,7 +165,7 @@ resource "squaredup_workspace" "application_workspace" {
}
data "squaredup_data_streams" "sample_data_logs_dataStreams" {
data_source_id = data.squaredup_latest_datasources.sample_data.plugins[0].id
data_source_id = data.squaredup_datasources.sample_data.plugins[0].id
}
locals {
Expand Down
Loading

0 comments on commit fffac66

Please sign in to comment.