Skip to content

Commit

Permalink
Fix TLS + urls in resources
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduchesne committed Nov 6, 2023
1 parent 10ee1f0 commit ca1aa08
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
8 changes: 4 additions & 4 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ testacc-oss-docker:
GRAFANA_VERSION=$(GRAFANA_VERSION) docker compose up --force-recreate --detach --remove-orphans --wait

GRAFANA_VERSION=$(GRAFANA_VERSION) \
GRAFANA_URL="http://localhost:3000" \
GRAFANA_URL="http://127.0.0.1:3000" \
GRAFANA_AUTH="admin:admin" \
make testacc-oss

Expand All @@ -33,7 +33,7 @@ testacc-enterprise-docker:
GRAFANA_IMAGE=grafana/grafana-enterprise GRAFANA_VERSION=$(GRAFANA_VERSION) docker compose up --force-recreate --detach --remove-orphans --wait

GRAFANA_VERSION=$(GRAFANA_VERSION) \
GRAFANA_URL="http://localhost:3000" \
GRAFANA_URL="http://127.0.0.1:3000" \
GRAFANA_AUTH="admin:admin" \
make testacc-enterprise

Expand All @@ -44,7 +44,7 @@ testacc-tls-docker:
GRAFANA_VERSION=$(GRAFANA_VERSION) docker compose --profile tls up --force-recreate --detach --remove-orphans --wait

GRAFANA_VERSION=$(GRAFANA_VERSION) \
GRAFANA_URL="https://localhost:3001" \
GRAFANA_URL="https://127.0.0.1:3001" \
GRAFANA_AUTH="admin:admin" \
GRAFANA_TLS_KEY=$$(pwd)/testdata/client.key \
GRAFANA_TLS_CERT=$$(pwd)/testdata/client.crt \
Expand All @@ -57,7 +57,7 @@ testacc-subpath-docker:
GRAFANA_VERSION=$(GRAFANA_VERSION) GRAFANA_SUBPATH=/grafana/ GF_SERVER_SERVE_FROM_SUB_PATH=true docker compose up --force-recreate --detach --remove-orphans --wait

GRAFANA_VERSION=$(GRAFANA_VERSION) \
GRAFANA_URL="http://localhost:3000/grafana" \
GRAFANA_URL="http://127.0.0.1:3000/grafana" \
GRAFANA_AUTH="admin:admin" \
make testacc-oss

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ services:
- 3000:3000
image: ${GRAFANA_IMAGE:-grafana/grafana}:${GRAFANA_VERSION}
environment:
- GF_SERVER_ROOT_URL=http://0.0.0.0:3000${GRAFANA_SUBPATH:-}
- GF_SERVER_ROOT_URL=http://127.0.0.1:3000${GRAFANA_SUBPATH:-}
- GF_ENTERPRISE_LICENSE_TEXT=${GF_ENTERPRISE_LICENSE_TEXT:-}
- GF_SERVER_SERVE_FROM_SUB_PATH=${GF_SERVER_SERVE_FROM_SUB_PATH:-}
healthcheck:
test: wget --no-verbose --tries=1 --spider http://0.0.0.0:3000${GRAFANA_SUBPATH:-}/api/health || exit 1 # Use wget because older versions of Grafana don't have curl
test: wget --no-verbose --tries=1 --spider http://127.0.0.1:3000${GRAFANA_SUBPATH:-}/api/health || exit 1 # Use wget because older versions of Grafana don't have curl
interval: 10s
retries: 10
start_period: 10s
Expand Down
5 changes: 2 additions & 3 deletions internal/resources/grafana/data_source_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"net/url"
"strconv"
"strings"

gapi "github.com/grafana/grafana-api-golang-client"
"github.com/grafana/terraform-provider-grafana/internal/common"
Expand Down Expand Up @@ -96,7 +95,7 @@ func findDashboardWithID(client *gapi.Client, id int64) (*gapi.FolderDashboardSe
}

func dataSourceDashboardRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
gapiURL := meta.(*common.Client).GrafanaAPIURL
metaClient := meta.(*common.Client)
var dashboard *gapi.Dashboard
client := meta.(*common.Client).GrafanaAPI

Expand Down Expand Up @@ -129,7 +128,7 @@ func dataSourceDashboardRead(ctx context.Context, d *schema.ResourceData, meta i
d.Set("folder", dashboard.FolderID)
d.Set("is_starred", dashboard.Meta.IsStarred)
d.Set("slug", dashboard.Meta.Slug)
d.Set("url", strings.TrimRight(gapiURL, "/")+dashboard.Meta.URL)
d.Set("url", metaClient.GrafanaSubpath(dashboard.Meta.URL))

return nil
}
5 changes: 2 additions & 3 deletions internal/resources/grafana/data_source_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"strconv"
"strings"

gapi "github.com/grafana/grafana-api-golang-client"
"github.com/grafana/terraform-provider-grafana/internal/common"
Expand Down Expand Up @@ -61,7 +60,7 @@ func findFolderWithTitle(client *gapi.Client, title string) (*gapi.Folder, error
}

func dataSourceFolderRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
gapiURL := meta.(*common.Client).GrafanaAPIURL
metaClient := meta.(*common.Client)
client := meta.(*common.Client).GrafanaAPI
title := d.Get("title").(string)
folder, err := findFolderWithTitle(client, title)
Expand All @@ -74,7 +73,7 @@ func dataSourceFolderRead(ctx context.Context, d *schema.ResourceData, meta inte
d.SetId(id)
d.Set("uid", folder.UID)
d.Set("title", folder.Title)
d.Set("url", strings.TrimRight(gapiURL, "/")+folder.URL)
d.Set("url", metaClient.GrafanaSubpath(folder.URL))

return nil
}
5 changes: 2 additions & 3 deletions internal/resources/grafana/resource_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -110,7 +109,7 @@ func CreateDashboard(ctx context.Context, d *schema.ResourceData, meta interface
}

func ReadDashboard(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
gapiURL := meta.(*common.Client).GrafanaAPIURL
metaClient := meta.(*common.Client)
client, orgID, uid := ClientFromExistingOrgResource(meta, d.Id())

dashboard, err := client.DashboardByUID(uid)
Expand All @@ -123,7 +122,7 @@ func ReadDashboard(ctx context.Context, d *schema.ResourceData, meta interface{}
d.Set("uid", dashboard.Model["uid"].(string))
d.Set("dashboard_id", int64(dashboard.Model["id"].(float64)))
d.Set("version", int64(dashboard.Model["version"].(float64)))
d.Set("url", strings.TrimRight(gapiURL, "/")+dashboard.Meta.URL)
d.Set("url", metaClient.GrafanaSubpath(dashboard.Meta.URL))

// If the folder was originally set to a numeric ID, we read the folder ID
// Othwerwise, we read the folder UID
Expand Down

0 comments on commit ca1aa08

Please sign in to comment.