Skip to content

Commit

Permalink
Add OTLP endpoint to cloud stacks
Browse files Browse the repository at this point in the history
Closes #1358
  • Loading branch information
julienduchesne committed Feb 21, 2024
1 parent 955f364 commit 78fb763
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/cloud_stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ available at “https://<stack_slug>.grafana.net".
- `org_id` (Number) Organization id to assign to this stack.
- `org_name` (String) Organization name to assign to this stack.
- `org_slug` (String) Organization slug to assign to this stack.
- `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.
- `profiles_name` (String)
- `profiles_status` (String)
- `profiles_url` (String)
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cloud_stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ available at “https://<stack_slug>.grafana.net".
- `org_id` (Number) Organization id to assign to this stack.
- `org_name` (String) Organization name to assign to this stack.
- `org_slug` (String) Organization slug to assign to this stack.
- `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.
- `profiles_name` (String)
- `profiles_status` (String)
- `profiles_url` (String)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-openapi/runtime v0.27.1
github.com/go-openapi/strfmt v0.22.0
github.com/grafana/amixr-api-go-client v0.0.11
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240205204245-e327bebd7c02
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240220151716-042876eff9fb
github.com/grafana/grafana-openapi-client-go v0.0.0-20240131162504-9263d72bd697
github.com/grafana/machine-learning-go-client v0.5.0
github.com/grafana/slo-openapi-client/go v0.0.0-20240112175006-de02e75b9d73
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/amixr-api-go-client v0.0.11 h1:jlE+5t0tRuCtjbpM81j70Dr2J4eCySuWyNGdfLMGdhE=
github.com/grafana/amixr-api-go-client v0.0.11/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240205204245-e327bebd7c02 h1:TvPNghzCF1/DC+PGi2fccwayVS/8wCB1X6E4etuosao=
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240205204245-e327bebd7c02/go.mod h1:6sYY1qgwYfSDNQhKQA0tar8Oc38cIGfyqwejhxoOsPs=
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240220151716-042876eff9fb h1:9lMBTa0DTo6/sluXCOA6UO/xxKPq8jWIID57KkoKQj0=
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240220151716-042876eff9fb/go.mod h1:6sYY1qgwYfSDNQhKQA0tar8Oc38cIGfyqwejhxoOsPs=
github.com/grafana/grafana-openapi-client-go v0.0.0-20240131162504-9263d72bd697 h1:pqQoKCVWXVtPwgCjFcCtuWiElkSNv1a97uUjiYEUl0k=
github.com/grafana/grafana-openapi-client-go v0.0.0-20240131162504-9263d72bd697/go.mod h1:EapKj5Z1OKDssvRofVwD8XEuJtZUaysLWPFFM2QoK0Q=
github.com/grafana/machine-learning-go-client v0.5.0 h1:Q1K+MPSy8vfMm2jsk3WQ7O77cGr2fM5hxwtPSoPc5NU=
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/cloud/data_source_cloud_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func DataSourceOrganizationRead(ctx context.Context, d *schema.ResourceData, met
return apiError(err)
}

id = strconv.FormatInt(int64(*org.Id), 10)
id = strconv.FormatInt(int64(org.Id), 10)
d.SetId(id)
d.Set("id", id)
d.Set("name", org.Name)
Expand Down
17 changes: 2 additions & 15 deletions internal/resources/cloud/data_source_cloud_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,6 @@ available at “https://<stack_slug>.grafana.net".`,
}

func DataSourceStackRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*common.Client).GrafanaCloudAPI

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

req := client.InstancesAPI.GetInstance(ctx, slug)
stack, _, err := req.Execute()
if err != nil {
return apiError(err)
}

if err := FlattenStack(d, stack); err != nil {
return diag.FromErr(err)
}

return nil
d.SetId(d.Get("slug").(string))
return ReadStack(ctx, d, meta)
}
15 changes: 13 additions & 2 deletions internal/resources/cloud/resource_cloud_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ available at “https://<stack_slug>.grafana.net".`,
"graphite_name": common.ComputedString(),
"graphite_url": common.ComputedString(),
"graphite_status": common.ComputedString(),

// OTLP
"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."),
},
CustomizeDiff: customdiff.All(
customdiff.ComputedIf("url", func(_ context.Context, diff *schema.ResourceDiff, meta interface{}) bool {
Expand Down Expand Up @@ -263,7 +266,13 @@ func ReadStack(ctx context.Context, d *schema.ResourceData, meta interface{}) di
return nil
}

if err := FlattenStack(d, stack); err != nil {
connectionsReq := client.InstancesAPI.GetConnections(ctx, d.Id())
connections, _, err := connectionsReq.Execute()
if err != nil {
return apiError(err)
}

if err := FlattenStack(d, stack, connections); err != nil {
return diag.FromErr(err)
}
// Always set the wait attribute to true after creation
Expand All @@ -273,7 +282,7 @@ func ReadStack(ctx context.Context, d *schema.ResourceData, meta interface{}) di
return nil
}

func FlattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance) error {
func FlattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance, connections *gcom.FormattedApiInstanceConnections) error {
id := strconv.FormatInt(int64(stack.Id), 10)
d.SetId(id)
d.Set("name", stack.Name)
Expand Down Expand Up @@ -327,6 +336,8 @@ func FlattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance) erro
d.Set("graphite_url", stack.HmInstanceGraphiteUrl)
d.Set("graphite_status", stack.HmInstanceGraphiteStatus)

d.Set("otlp_url", connections.OtlpHttpUrl)

return nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/resources/cloud/resource_cloud_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestResourceStack_Basic(t *testing.T) {
resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_name"),
resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_url"),
resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "profiles_status"),
resource.TestCheckResourceAttrSet("grafana_cloud_stack.test", "otlp_url"),
)

resource.ParallelTest(t, resource.TestCase{
Expand Down

0 comments on commit 78fb763

Please sign in to comment.