Skip to content

Commit 988272a

Browse files
Extract meta Client to a common package (#805)
It's becoming hard to manage all resources at the root It's a huge amount of functions all in the same package By exporting the client to common package, I'll be able to send oncall to its own folder, cloud too, oss, etc
1 parent 7e759ec commit 988272a

File tree

150 files changed

+626
-500
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+626
-500
lines changed

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"flag"
55

6-
"github.com/grafana/terraform-provider-grafana/grafana"
6+
"github.com/grafana/terraform-provider-grafana/provider"
77
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
88
)
99

@@ -21,6 +21,6 @@ func main() {
2121
flag.BoolVar(&debugMode, "debug", false, "set to true to run the provider with support for debuggers like delve")
2222
flag.Parse()
2323

24-
opts := &plugin.ServeOpts{ProviderFunc: grafana.Provider(version), Debug: debugMode, ProviderAddr: "registry.terraform.io/grafana/grafana"}
24+
opts := &plugin.ServeOpts{ProviderFunc: provider.Provider(version), Debug: debugMode, ProviderAddr: "registry.terraform.io/grafana/grafana"}
2525
plugin.Serve(opts)
2626
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package grafana
1+
package provider
22

33
import (
44
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

provider/common/client.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package common
2+
3+
import (
4+
"sync"
5+
6+
onCallAPI "github.com/grafana/amixr-api-go-client"
7+
gapi "github.com/grafana/grafana-api-golang-client"
8+
"github.com/grafana/machine-learning-go-client/mlapi"
9+
SMAPI "github.com/grafana/synthetic-monitoring-api-go-client"
10+
)
11+
12+
type Client struct {
13+
GrafanaAPIURL string
14+
GrafanaAPIConfig *gapi.Config
15+
GrafanaAPI *gapi.Client
16+
GrafanaCloudAPI *gapi.Client
17+
18+
SMAPI *SMAPI.Client
19+
SMAPIURL string
20+
21+
MLAPI *mlapi.Client
22+
23+
OnCallClient *onCallAPI.Client
24+
25+
AlertingMutex sync.Mutex
26+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package grafana
1+
package provider
22

33
import (
44
"context"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package grafana
1+
package provider
22

33
import (
44
"fmt"

grafana/data_source_cloud_organization.go renamed to provider/data_source_cloud_organization.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package grafana
1+
package provider
22

33
import (
44
"context"
55
"strconv"
66
"time"
77

8+
"github.com/grafana/terraform-provider-grafana/provider/common"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1011
)
@@ -48,7 +49,7 @@ func DatasourceCloudOrganization() *schema.Resource {
4849
}
4950

5051
func datasourceCloudOrganizationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
51-
client := meta.(*client).gcloudapi
52+
client := meta.(*common.Client).GrafanaCloudAPI
5253

5354
id := d.Get("id").(string)
5455
if id == "" {

grafana/data_source_cloud_organization_test.go renamed to provider/data_source_cloud_organization_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package grafana
1+
package provider
22

33
import (
44
"fmt"
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package grafana
1+
package provider
22

33
import (
44
"context"
55

6+
"github.com/grafana/terraform-provider-grafana/provider/common"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
89
)
@@ -31,7 +32,7 @@ available at “https://<stack_slug>.grafana.net".`,
3132
}
3233

3334
func datasourceCloudStackRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
34-
client := meta.(*client).gcloudapi
35+
client := meta.(*common.Client).GrafanaCloudAPI
3536

3637
slug := d.Get("slug").(string)
3738

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package grafana
1+
package provider
22

33
import (
44
"fmt"
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package grafana
1+
package provider
22

33
import (
44
"context"
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
gapi "github.com/grafana/grafana-api-golang-client"
12+
"github.com/grafana/terraform-provider-grafana/provider/common"
1213
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1314
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1415
)
@@ -95,9 +96,9 @@ func findDashboardWithID(client *gapi.Client, id int64) (*gapi.FolderDashboardSe
9596
}
9697

9798
func dataSourceDashboardRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
98-
gapiURL := meta.(*client).gapiURL
99+
gapiURL := meta.(*common.Client).GrafanaAPIURL
99100
var dashboard *gapi.Dashboard
100-
client := meta.(*client).gapi
101+
client := meta.(*common.Client).GrafanaAPI
101102

102103
// get UID from ID if specified
103104
id := d.Get("dashboard_id").(int)

0 commit comments

Comments
 (0)