Skip to content

Commit

Permalink
Merge branch 'main' of github.com:grafana/terraform-provider-grafana …
Browse files Browse the repository at this point in the history
…into tf-cloud-provider-aws-app
  • Loading branch information
tristanburgess committed Sep 18, 2024
2 parents c79d7eb + 422b1f7 commit 1341a57
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/grafana/amixr-api-go-client v0.0.12 // main branch
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3
github.com/grafana/grafana-openapi-client-go v0.0.0-20240723170622-ae2c94b7c9a3
github.com/grafana/machine-learning-go-client v0.8.0
github.com/grafana/machine-learning-go-client v0.8.1
github.com/grafana/slo-openapi-client/go/slo v0.0.0-20240807172758-1b7d00838fc7
github.com/grafana/synthetic-monitoring-agent v0.25.2
github.com/grafana/synthetic-monitoring-api-go-client v0.8.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ github.com/grafana/grafana-plugin-sdk-go v0.235.0 h1:UnZ/iBDvCkfDgwR94opi8trAWJX
github.com/grafana/grafana-plugin-sdk-go v0.235.0/go.mod h1:6n9LbrjGL3xAATntYVNcIi90G9BVHRJjzHKz5FXVfWw=
github.com/grafana/machine-learning-go-client v0.8.0 h1:N8+0f5aFM/umVJWvlJkJy9McVIp9MIBUtuNruug94II=
github.com/grafana/machine-learning-go-client v0.8.0/go.mod h1:9xRIoH6Y6RubuCPNjLfpckE/fLVe9dazg3HSLI1ARAU=
github.com/grafana/machine-learning-go-client v0.8.1 h1:cCVb2FQuMMto2qvhmVcjHM4eFjAey3AiTLYVUq3wYVI=
github.com/grafana/machine-learning-go-client v0.8.1/go.mod h1:9xRIoH6Y6RubuCPNjLfpckE/fLVe9dazg3HSLI1ARAU=
github.com/grafana/otel-profiling-go v0.5.1 h1:stVPKAFZSa7eGiqbYuG25VcqYksR6iWvF3YH66t4qL8=
github.com/grafana/otel-profiling-go v0.5.1/go.mod h1:ftN/t5A/4gQI19/8MoWurBEtC6gFw8Dns1sJZ9W4Tls=
github.com/grafana/pyroscope-go/godeltaprof v0.1.8 h1:iwOtYXeeVSAeYefJNaxDytgjKtUuKQbJqgAIjlnicKg=
Expand Down
43 changes: 29 additions & 14 deletions internal/resources/grafana/resource_folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
"strings"
"testing"

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

"github.com/grafana/grafana-openapi-client-go/client/service_accounts"
"github.com/grafana/grafana-openapi-client-go/models"

"github.com/grafana/terraform-provider-grafana/v3/internal/common"
"github.com/grafana/terraform-provider-grafana/v3/internal/resources/grafana"
"github.com/grafana/terraform-provider-grafana/v3/internal/testutils"

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

func TestAccFolder_basic(t *testing.T) {
Expand Down Expand Up @@ -285,26 +286,40 @@ func TestAccFolder_createFromDifferentRoles(t *testing.T) {
} {
t.Run(tc.role, func(t *testing.T) {
var folder models.Folder
var name = acctest.RandomWithPrefix(tc.role + "-key")
var saName = acctest.RandomWithPrefix(tc.role + "-sa")
var saTokenName = acctest.RandomWithPrefix(tc.role + "-token")

// Create an API key with the correct role and inject it in envvars. This auth will be used when the test runs
// Create a service account token with the correct role and inject it in envvars. This auth will be used when the test runs
client := grafanaTestClient()
resp, err := client.APIKeys.AddAPIkey(&models.AddAPIKeyCommand{
Name: name,
Role: tc.role,
})

sa, err := client.ServiceAccounts.CreateServiceAccount(
service_accounts.NewCreateServiceAccountParams().WithBody(&models.CreateServiceAccountForm{
Name: saName,
Role: tc.role,
}),
)
if err != nil {
t.Fatal(err)
}
defer client.ServiceAccounts.DeleteServiceAccount(sa.Payload.ID)

saToken, err := client.ServiceAccounts.CreateToken(
service_accounts.NewCreateTokenParams().WithBody(&models.AddServiceAccountTokenCommand{
Name: saTokenName,
}).WithServiceAccountID(sa.Payload.ID),
)
if err != nil {
t.Fatal(err)
}
defer client.APIKeys.DeleteAPIkey(resp.Payload.ID)

oldValue := os.Getenv("GRAFANA_AUTH")
defer os.Setenv("GRAFANA_AUTH", oldValue)
os.Setenv("GRAFANA_AUTH", resp.Payload.Key)
os.Setenv("GRAFANA_AUTH", saToken.Payload.Key)

config := fmt.Sprintf(`
resource "grafana_folder" "bar" {
title = "%[1]s"
}`, name)
}`, saName)

// Do not make parallel, fiddling with auth will break other tests that run in parallel
resource.Test(t, resource.TestCase{
Expand All @@ -318,7 +333,7 @@ func TestAccFolder_createFromDifferentRoles(t *testing.T) {
folderCheckExists.exists("grafana_folder.bar", &folder),
resource.TestMatchResourceAttr("grafana_folder.bar", "id", defaultOrgIDRegexp),
resource.TestMatchResourceAttr("grafana_folder.bar", "uid", common.UIDRegexp),
resource.TestCheckResourceAttr("grafana_folder.bar", "title", name),
resource.TestCheckResourceAttr("grafana_folder.bar", "title", saName),
),
},
},
Expand Down
1 change: 0 additions & 1 deletion pkg/provider/configure_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ func createMLClient(client *common.Client, providerConfig ProviderConfig) error
BasicAuth: client.GrafanaAPIConfig.BasicAuth,
BearerToken: client.GrafanaAPIConfig.APIKey,
Client: getRetryClient(providerConfig),
NumRetries: client.GrafanaAPIConfig.NumRetries,
}
mlURL := client.GrafanaAPIURL
if !strings.HasSuffix(mlURL, "/") {
Expand Down

0 comments on commit 1341a57

Please sign in to comment.