Skip to content
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
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"tfsdk",
"timeframe",
"unmarshalling",
"uuidgen",
"visualisation"
]
}
91 changes: 91 additions & 0 deletions docs/resources/dashboard_image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "squaredup_dashboard_image Resource - squaredup"
subcategory: ""
description: |-
SquaredUp Dashboard Image resource allows you to upload an image for use in the Image tile.
---

# squaredup_dashboard_image (Resource)

SquaredUp Dashboard Image resource allows you to upload an image for use in the Image tile.

## Example Usage

```terraform
resource "squaredup_workspace" "application_workspace" {
display_name = "Application Team"
allow_dashboard_sharing = false
description = "Workspace with Dashboards for Application Team"
}

locals {
// unique id for the image tile which is generated using uuidgen in bash
application1_image_tile_id = "1d5ec28e-d5d5-4bc9-bbe0-dd63d9871244"
}

resource "squaredup_dashboard" "application1_dashboard" {
display_name = "Application 1"
workspace_id = squaredup_workspace.application_workspace.id
dashboard_template = <<EOT
{
"_type": "layout/grid",
"contents": [
{
"x": 0,
"h": 2,
"i": "${local.application1_image_tile_id}",
"y": 0,
"config": {
"_type": "tile/image",
"description": "",
"title": "",
"visualisation": {
"config": {
"title": "Some description",
"uploaded": 123456789,
"showHealthState": false
}
}
},
"w": 4
}
],
"version": 5,
"columns": 4
}
EOT
}

resource "squaredup_dashboard_image" "application1_image" {
tile_id = local.application1_image_tile_id
dashboard_id = squaredup_dashboard.application1_dashboard.id
workspace_id = squaredup_workspace.application_workspace.id
image_base64_data_uri = "data:image/png;base64, ${filebase64("path/to/your/image.png")}"
image_file_name = "application1.png"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `dashboard_id` (String) The ID of the dashboard which contains the tile where the image will be used.
- `image_base64_data_uri` (String) The base64 data URI of the image.
- `image_file_name` (String) The file name of the image.
- `tile_id` (String) The ID of the tile where the image will be used.
- `workspace_id` (String) The ID of the workspace which contains the dashboard.

### Read-Only

- `id` (String) The ID of the dashboard image (which is the same as the tile ID).

## Import

Import is supported using the following syntax:

```shell
# Dashboard Image can be imported by specifying the workspace id, dashboard id and the tile id.
terraform import squaredup_dashboard_image.example space-123,dash-123,tile-guid
```
2 changes: 2 additions & 0 deletions examples/resources/squaredup_dashboard_image/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dashboard Image can be imported by specifying the workspace id, dashboard id and the tile id.
terraform import squaredup_dashboard_image.example space-123,dash-123,tile-guid
51 changes: 51 additions & 0 deletions examples/resources/squaredup_dashboard_image/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
resource "squaredup_workspace" "application_workspace" {
display_name = "Application Team"
allow_dashboard_sharing = false
description = "Workspace with Dashboards for Application Team"
}

locals {
// unique id for the image tile which is generated using uuidgen in bash
application1_image_tile_id = "1d5ec28e-d5d5-4bc9-bbe0-dd63d9871244"
}

resource "squaredup_dashboard" "application1_dashboard" {
display_name = "Application 1"
workspace_id = squaredup_workspace.application_workspace.id
dashboard_template = <<EOT
{
"_type": "layout/grid",
"contents": [
{
"x": 0,
"h": 2,
"i": "${local.application1_image_tile_id}",
"y": 0,
"config": {
"_type": "tile/image",
"description": "",
"title": "",
"visualisation": {
"config": {
"title": "Some description",
"uploaded": 123456789,
"showHealthState": false
}
}
},
"w": 4
}
],
"version": 5,
"columns": 4
}
EOT
}

resource "squaredup_dashboard_image" "application1_image" {
tile_id = local.application1_image_tile_id
dashboard_id = squaredup_dashboard.application1_dashboard.id
workspace_id = squaredup_workspace.application_workspace.id
image_base64_data_uri = "data:image/png;base64, ${filebase64("path/to/your/image.png")}"
image_file_name = "application1.png"
}
67 changes: 67 additions & 0 deletions internal/provider/client_dashboard_image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package provider

import (
"encoding/json"
"net/http"
"strconv"
"strings"
"time"
)

func (c *SquaredUpClient) GetDashboardImage(spaceId, dashId, tileId string) (*DashboardImage, error) {
currentTimeInMillis := time.Now().UnixMilli()
currentTimeStr := strconv.FormatInt(currentTimeInMillis, 10)
url := c.baseURL + "/api/workspaces/" + spaceId + "/dashboards/" + dashId + "/images/" + tileId + "?uploaded=" + currentTimeStr
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}

body, err := c.doRequest(req)
if err != nil {
return nil, err
}

dashboardImage := DashboardImage{}
err = json.Unmarshal(body, &dashboardImage)
if err != nil {
return nil, err
}

return &dashboardImage, nil
}

func (c *SquaredUpClient) UploadDashboardImage(spaceId, dashId, tileId string, dashboardImage *DashboardImage) error {
url := c.baseURL + "/api/workspaces/" + spaceId + "/dashboards/" + dashId + "/images/" + tileId
rb, err := json.Marshal(dashboardImage)
if err != nil {
return err
}

req, err := http.NewRequest("PUT", url, strings.NewReader(string(rb)))
if err != nil {
return err
}

_, err = c.doRequest(req)
if err != nil {
return err
}

return nil
}

func (c *SquaredUpClient) DeleteDashboardImage(spaceId, dashId, tileId string) error {
url := c.baseURL + "/api/workspaces/" + spaceId + "/dashboards/" + dashId + "/images/" + tileId
req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
}

_, err = c.doRequest(req)
if err != nil {
return err
}

return nil
}
9 changes: 9 additions & 0 deletions internal/provider/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,12 @@ type ScopeData struct {
Query string `json:"query"`
QueryDetail string `json:"queryDetail"`
}

type DashboardImage struct {
DataURL string `json:"dataURL"`
Metadata DashboardImageMetadata `json:"metadata"`
}

type DashboardImageMetadata struct {
FileName string `json:"fileName"`
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,6 @@ func (p *squaredupProvider) Resources(_ context.Context) []func() resource.Resou
SquaredupWorkspaceAlertResource,
SquaredUpScriptResource,
SquaredUpScopeResource,
SquaredUpDashboardImageResource,
}
}
Loading
Loading