Skip to content

Commit f0eae58

Browse files
Add OTLP endpoint to cloud stacks
Closes #1358
1 parent 955f364 commit f0eae58

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

docs/data-sources/cloud_stack.md

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ available at “https://<stack_slug>.grafana.net".
5353
- `org_id` (Number) Organization id to assign to this stack.
5454
- `org_name` (String) Organization name to assign to this stack.
5555
- `org_slug` (String) Organization slug to assign to this stack.
56+
- `otlp_url` (String) Base URL of the OTLP instance configured for this stack. See https://grafana.com/docs/grafana-cloud/send-data/otlp/send-data-otlp/ for docs on how to use this.
5657
- `profiles_name` (String)
5758
- `profiles_status` (String)
5859
- `profiles_url` (String)

docs/resources/cloud_stack.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ available at “https://<stack_slug>.grafana.net".
5656
- `org_id` (Number) Organization id to assign to this stack.
5757
- `org_name` (String) Organization name to assign to this stack.
5858
- `org_slug` (String) Organization slug to assign to this stack.
59+
- `otlp_url` (String) Base URL of the OTLP instance configured for this stack. See https://grafana.com/docs/grafana-cloud/send-data/otlp/send-data-otlp/ for docs on how to use this.
5960
- `profiles_name` (String)
6061
- `profiles_status` (String)
6162
- `profiles_url` (String)

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/go-openapi/runtime v0.27.1
1010
github.com/go-openapi/strfmt v0.22.0
1111
github.com/grafana/amixr-api-go-client v0.0.11
12-
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240205204245-e327bebd7c02
12+
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240220151716-042876eff9fb
1313
github.com/grafana/grafana-openapi-client-go v0.0.0-20240131162504-9263d72bd697
1414
github.com/grafana/machine-learning-go-client v0.5.0
1515
github.com/grafana/slo-openapi-client/go v0.0.0-20240112175006-de02e75b9d73

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
9898
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
9999
github.com/grafana/amixr-api-go-client v0.0.11 h1:jlE+5t0tRuCtjbpM81j70Dr2J4eCySuWyNGdfLMGdhE=
100100
github.com/grafana/amixr-api-go-client v0.0.11/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
101-
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240205204245-e327bebd7c02 h1:TvPNghzCF1/DC+PGi2fccwayVS/8wCB1X6E4etuosao=
102-
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240205204245-e327bebd7c02/go.mod h1:6sYY1qgwYfSDNQhKQA0tar8Oc38cIGfyqwejhxoOsPs=
101+
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240220151716-042876eff9fb h1:9lMBTa0DTo6/sluXCOA6UO/xxKPq8jWIID57KkoKQj0=
102+
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240220151716-042876eff9fb/go.mod h1:6sYY1qgwYfSDNQhKQA0tar8Oc38cIGfyqwejhxoOsPs=
103103
github.com/grafana/grafana-openapi-client-go v0.0.0-20240131162504-9263d72bd697 h1:pqQoKCVWXVtPwgCjFcCtuWiElkSNv1a97uUjiYEUl0k=
104104
github.com/grafana/grafana-openapi-client-go v0.0.0-20240131162504-9263d72bd697/go.mod h1:EapKj5Z1OKDssvRofVwD8XEuJtZUaysLWPFFM2QoK0Q=
105105
github.com/grafana/machine-learning-go-client v0.5.0 h1:Q1K+MPSy8vfMm2jsk3WQ7O77cGr2fM5hxwtPSoPc5NU=

internal/resources/cloud/data_source_cloud_organization.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func DataSourceOrganizationRead(ctx context.Context, d *schema.ResourceData, met
5555
return apiError(err)
5656
}
5757

58-
id = strconv.FormatInt(int64(*org.Id), 10)
58+
id = strconv.FormatInt(int64(org.Id), 10)
5959
d.SetId(id)
6060
d.Set("id", id)
6161
d.Set("name", org.Name)

internal/resources/cloud/data_source_cloud_stack.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,6 @@ available at “https://<stack_slug>.grafana.net".`,
3232
}
3333

3434
func DataSourceStackRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
35-
client := meta.(*common.Client).GrafanaCloudAPI
36-
37-
slug := d.Get("slug").(string)
38-
39-
req := client.InstancesAPI.GetInstance(ctx, slug)
40-
stack, _, err := req.Execute()
41-
if err != nil {
42-
return apiError(err)
43-
}
44-
45-
if err := FlattenStack(d, stack); err != nil {
46-
return diag.FromErr(err)
47-
}
48-
49-
return nil
35+
d.SetId(d.Get("slug").(string))
36+
return ReadStack(ctx, d, meta)
5037
}

internal/resources/cloud/resource_cloud_stack.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ available at “https://<stack_slug>.grafana.net".`,
143143
"graphite_name": common.ComputedString(),
144144
"graphite_url": common.ComputedString(),
145145
"graphite_status": common.ComputedString(),
146+
147+
// OTLP
148+
"otlp_url": common.ComputedStringWithDescription("Base URL of the OTLP instance configured for this stack. See https://grafana.com/docs/grafana-cloud/send-data/otlp/send-data-otlp/ for docs on how to use this."),
146149
},
147150
CustomizeDiff: customdiff.All(
148151
customdiff.ComputedIf("url", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
@@ -263,7 +266,13 @@ func ReadStack(ctx context.Context, d *schema.ResourceData, meta interface{}) di
263266
return nil
264267
}
265268

266-
if err := FlattenStack(d, stack); err != nil {
269+
connectionsReq := client.InstancesAPI.GetConnections(ctx, d.Id())
270+
connections, _, err := connectionsReq.Execute()
271+
if err != nil {
272+
return apiError(err)
273+
}
274+
275+
if err := FlattenStack(d, stack, connections); err != nil {
267276
return diag.FromErr(err)
268277
}
269278
// Always set the wait attribute to true after creation
@@ -273,7 +282,7 @@ func ReadStack(ctx context.Context, d *schema.ResourceData, meta interface{}) di
273282
return nil
274283
}
275284

276-
func FlattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance) error {
285+
func FlattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance, connections *gcom.FormattedApiInstanceConnections) error {
277286
id := strconv.FormatInt(int64(stack.Id), 10)
278287
d.SetId(id)
279288
d.Set("name", stack.Name)
@@ -327,6 +336,8 @@ func FlattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance) erro
327336
d.Set("graphite_url", stack.HmInstanceGraphiteUrl)
328337
d.Set("graphite_status", stack.HmInstanceGraphiteStatus)
329338

339+
d.Set("otlp_user_id", connections.OtlpHttpUrl)
340+
330341
return nil
331342
}
332343

internal/resources/cloud/resource_cloud_stack_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestResourceStack_Basic(t *testing.T) {
4545
resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_name"),
4646
resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_url"),
4747
resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_status"),
48+
resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "otlp_url"),
4849
)
4950

5051
resource.ParallelTest(t, resource.TestCase{

0 commit comments

Comments
 (0)