-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from squaredup/work/ss/scopes
Support for Scopes
- Loading branch information
Showing
8 changed files
with
910 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "squaredup_scope Resource - terraform-provider-squaredup" | ||
subcategory: "" | ||
description: |- | ||
SquaredUp Scope | ||
--- | ||
|
||
# squaredup_scope (Resource) | ||
|
||
SquaredUp Scope | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
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_datasources.sample_data.plugins[0].display_name | ||
} | ||
resource "squaredup_workspace" "application_workspace" { | ||
display_name = "Application Team" | ||
description = "Workspace with Dashboards for Application Team" | ||
datasources_links = [squaredup_datasource.sample_data_source.id] | ||
} | ||
resource "squaredup_scope" "advanced_scope" { | ||
scope_type = "advanced" | ||
display_name = "Advanced Scope" | ||
workspace_id = squaredup_workspace.application_workspace.id | ||
advanced_query = "g.V().has('__configId', '${squaredup_datasource.sample_data_source.id}').has('sourceId', 'sample-server-2')" //any gremlin query | ||
} | ||
data "squaredup_nodes" "acommon_node" { | ||
depends_on = [squaredup_datasource.sample_data_source] | ||
data_source_id = squaredup_datasource.sample_data_source.id | ||
node_name = "account-common-lambda" | ||
} | ||
data "squaredup_nodes" "api_node" { | ||
depends_on = [squaredup_datasource.sample_data_source] | ||
data_source_id = squaredup_datasource.sample_data_source.id | ||
node_name = "master-api-lambda" | ||
} | ||
resource "squaredup_scope" "fixed_scope" { | ||
scope_type = "fixed" | ||
display_name = "Fixed Scope" | ||
workspace_id = squaredup_workspace.application_workspace.id | ||
node_ids = [data.squaredup_nodes.acommon_node.node_properties[0].id, data.squaredup_nodes.api_node.node_properties[0].id] | ||
} | ||
resource "squaredup_scope" "dynamic_scope" { | ||
scope_type = "dynamic" | ||
display_name = "Dynamic Scope" | ||
workspace_id = squaredup_workspace.application_workspace.id | ||
data_source_id = [squaredup_datasource.sample_data_source.id] //if no data source is provided, it will search within all | ||
types = ["sample-function"] //if no type is provided, it will search within all | ||
search_query = "account-common" //similar to search bar | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `display_name` (String) Display name for the scope | ||
- `scope_type` (String) Type of the scope. Either 'dynamic' or 'fixed' | ||
- `workspace_id` (String) ID of the workspace | ||
|
||
### Optional | ||
|
||
- `advanced_query` (String) Advanced query (Gremlin) | ||
- `data_source_id` (List of String) IDs of the data sources to filter the scope | ||
- `node_ids` (List of String) IDs of the nodes that scope will contain | ||
- `search_query` (String) Search query | ||
- `types` (List of String) Node types to filter the scope | ||
|
||
### Read-Only | ||
|
||
- `id` (String) ID of the scope | ||
- `last_updated` (String) Last updated timestamp | ||
- `query` (String) Query for the scope | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# Scopes can be imported by specifying workspace id and scope id | ||
terraform import squaredup_scope.example space-123,scope-123 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Scopes can be imported by specifying workspace id and scope id | ||
terraform import squaredup_scope.example space-123,scope-123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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_datasources.sample_data.plugins[0].display_name | ||
} | ||
|
||
resource "squaredup_workspace" "application_workspace" { | ||
display_name = "Application Team" | ||
description = "Workspace with Dashboards for Application Team" | ||
datasources_links = [squaredup_datasource.sample_data_source.id] | ||
} | ||
|
||
resource "squaredup_scope" "advanced_scope" { | ||
scope_type = "advanced" | ||
display_name = "Advanced Scope" | ||
workspace_id = squaredup_workspace.application_workspace.id | ||
advanced_query = "g.V().has('__configId', '${squaredup_datasource.sample_data_source.id}').has('sourceId', 'sample-server-2')" //any gremlin query | ||
} | ||
|
||
data "squaredup_nodes" "acommon_node" { | ||
depends_on = [squaredup_datasource.sample_data_source] | ||
data_source_id = squaredup_datasource.sample_data_source.id | ||
node_name = "account-common-lambda" | ||
} | ||
|
||
data "squaredup_nodes" "api_node" { | ||
depends_on = [squaredup_datasource.sample_data_source] | ||
data_source_id = squaredup_datasource.sample_data_source.id | ||
node_name = "master-api-lambda" | ||
} | ||
|
||
resource "squaredup_scope" "fixed_scope" { | ||
scope_type = "fixed" | ||
display_name = "Fixed Scope" | ||
workspace_id = squaredup_workspace.application_workspace.id | ||
node_ids = [data.squaredup_nodes.acommon_node.node_properties[0].id, data.squaredup_nodes.api_node.node_properties[0].id] | ||
} | ||
|
||
resource "squaredup_scope" "dynamic_scope" { | ||
scope_type = "dynamic" | ||
display_name = "Dynamic Scope" | ||
workspace_id = squaredup_workspace.application_workspace.id | ||
data_source_id = [squaredup_datasource.sample_data_source.id] //if no data source is provided, it will search within all | ||
types = ["sample-function"] //if no type is provided, it will search within all | ||
search_query = "account-common" //similar to search bar | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package provider | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func (c *SquaredUpClient) CreateScope(scope ScopeCreate, workspaceId string) (string, error) { | ||
rb, err := json.Marshal(scope) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
req, err := http.NewRequest("POST", c.baseURL+"/api/workspaces/"+workspaceId+"/scopes", strings.NewReader(string(rb))) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
scopeID := string(body) | ||
scopeID = strings.Trim(scopeID, `"`) | ||
|
||
return scopeID, nil | ||
} | ||
|
||
func (c *SquaredUpClient) GetScope(scopeId string, workspaceId string) (*ScopeRead, error) { | ||
req, err := http.NewRequest("GET", c.baseURL+"/api/workspaces/"+workspaceId+"/scopes/"+scopeId, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
body, err := c.doRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
scope := ScopeRead{} | ||
err = json.Unmarshal(body, &scope) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &scope, nil | ||
} | ||
|
||
func (c *SquaredUpClient) UpdateScope(scopeId string, scope ScopeCreate, workspaceId string) error { | ||
rb, err := json.Marshal(scope) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
req, err := http.NewRequest("PUT", c.baseURL+"/api/workspaces/"+workspaceId+"/scopes/"+scopeId, strings.NewReader(string(rb))) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *SquaredUpClient) DeleteScope(scopeId string, workspaceId string) error { | ||
req, err := http.NewRequest("DELETE", c.baseURL+"/api/workspaces/"+workspaceId+"/scopes/"+scopeId, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.doRequest(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.