Skip to content

Commit 659ded7

Browse files
authored
feat: Add Frontend Observability provider (#2001)
This commit adds the groundwork to support Frontend Observability as code. More specificailly, the change contains 1. A Go HTTP client that consumes the Apps API (Create/Read/Update/Delete) 2. Data Source and Resource version of the Frontend Observability App entity.
1 parent bb0a948 commit 659ded7

File tree

22 files changed

+1648
-27
lines changed

22 files changed

+1648
-27
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/internal/resources/cloudprovider/* @grafana/platform-monitoring @grafana/middleware-apps
66
/internal/resources/connections/* @grafana/platform-monitoring @grafana/middleware-apps
77
/internal/resources/fleetmanagement/* @grafana/platform-monitoring @grafana/fleet-management-backend
8+
/internal/resources/frontendo11y/* @grafana/platform-monitoring @grafana/frontend-o11y
89
/internal/resources/machinelearning/* @grafana/platform-monitoring @grafana/machine-learning
910
/internal/resources/oncall/* @grafana/platform-monitoring @grafana/grafana-irm-backend
1011
/internal/resources/slo/* @grafana/platform-monitoring @grafana/slo-squad
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_frontend_o11y_app Data Source - terraform-provider-grafana"
4+
subcategory: "Frontend Observability"
5+
description: |-
6+
7+
---
8+
9+
# grafana_frontend_o11y_app (Data Source)
10+
11+
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "grafana_cloud_stack" "teststack" {
17+
provider = grafana.cloud
18+
name = "gcloudstacktest"
19+
}
20+
21+
data "grafana_frontend_o11y_app" "test-app" {
22+
provider = grafana.cloud
23+
stack_id = data.grafana_cloud_stack.teststack.id
24+
name = "test-app"
25+
}
26+
```
27+
28+
<!-- schema generated by tfplugindocs -->
29+
## Schema
30+
31+
### Required
32+
33+
- `name` (String) The name of the Frontend Observability App. Part of the Terraform Resource ID.
34+
- `stack_id` (Number) The Stack ID of the Grafana Cloud instance. Part of the Terraform Resource ID.
35+
36+
### Read-Only
37+
38+
- `allowed_origins` (List of String) A list of allowed origins for CORS.
39+
- `extra_log_attributes` (Map of String) The extra attributes to append in each signal.
40+
- `id` (Number) The Terraform Resource ID. This auto-generated from Frontend Observability API.
41+
- `settings` (Map of String) The settings of the Frontend Observability App.

docs/index.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,26 @@ resource "grafana_oncall_escalation" "example_notify_step" {
242242
}
243243
```
244244

245+
### Managing Frontend Observability
246+
247+
#### Obtaining Frontend Observability Access Token
248+
249+
Before using the Terraform Provider to manage Grafana Frontend Observability resources, such as your apps, you need to create an access policy token on the Grafana Cloud Portal. This token is used to authenticate the provider to the Grafana Frontend Observability API.
250+
[These docs](https://grafana.com/docs/grafana-cloud/security-and-account-management/authentication-and-permissions/access-policies/using-an-access-policy-token/#create-an-access-policy-for-a-stack) will guide you on how to create
251+
an access policy. The required permissions, or scopes, are `frontend-observability:read`, `frontend-observability:write`, `frontend-observability:delete` and `stacks:read`.
252+
253+
You can also use the `cloud_access_policy_token` provided it has the aforementioned scopes included.
254+
255+
#### Configuring the Provider to use the Frontend Observability API
256+
257+
Once you have the token you can configure the provider as follows:
258+
259+
```hcl
260+
provider "grafana" {
261+
frontend_o11y_api_access_token = "<Access Token from previous step>"
262+
}
263+
```
264+
245265
<!-- schema generated by tfplugindocs -->
246266
## Schema
247267

@@ -257,6 +277,7 @@ resource "grafana_oncall_escalation" "example_notify_step" {
257277
- `connections_api_url` (String) A Grafana Connections API address. May alternatively be set via the `GRAFANA_CONNECTIONS_API_URL` environment variable.
258278
- `fleet_management_auth` (String, Sensitive) A Grafana Fleet Management basic auth in the `username:password` format. May alternatively be set via the `GRAFANA_FLEET_MANAGEMENT_AUTH` environment variable.
259279
- `fleet_management_url` (String) A Grafana Fleet Management API address. May alternatively be set via the `GRAFANA_FLEET_MANAGEMENT_URL` environment variable.
280+
- `frontend_o11y_api_access_token` (String, Sensitive) A Grafana Frontend Observability API access token. May alternatively be set via the `GRAFANA_FRONTEND_O11Y_API_ACCESS_TOKEN` environment variable.
260281
- `http_headers` (Map of String, Sensitive) Optional. HTTP headers mapping keys to values used for accessing the Grafana and Grafana Cloud APIs. May alternatively be set via the `GRAFANA_HTTP_HEADERS` environment variable in JSON format.
261282
- `insecure_skip_verify` (Boolean) Skip TLS certificate verification. May alternatively be set via the `GRAFANA_INSECURE_SKIP_VERIFY` environment variable.
262283
- `oncall_access_token` (String, Sensitive) A Grafana OnCall access token. May alternatively be set via the `GRAFANA_ONCALL_ACCESS_TOKEN` environment variable.
@@ -577,3 +598,8 @@ For guidance on creating one, see section [obtaining connections access token](#
577598
uses basic auth to allow access to the API, where the username is the Fleet Management instance ID and the
578599
password is the API token. You can access the instance ID and request a new Fleet Management API token on the
579600
Connections -> Collector -> Fleet Management page, in the API tab.
601+
602+
### `frontend_o11y_access_token`
603+
604+
An access policy token created on the [Grafana Cloud Portal](https://grafana.com/docs/grafana-cloud/security-and-account-management/authentication-and-permissions/access-policies/) to manage Frontend Observability apps.
605+
For guidance on creating one, see section [obtaining Frontend Observability access token](#obtaining-frontend-observability-access-token).

docs/resources/frontend_o11y_app.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_frontend_o11y_app Resource - terraform-provider-grafana"
4+
subcategory: "Frontend Observability"
5+
description: |-
6+
7+
---
8+
9+
# grafana_frontend_o11y_app (Resource)
10+
11+
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "grafana_cloud_stack" "teststack" {
17+
provider = grafana.cloud
18+
name = "gcloudstacktest"
19+
}
20+
21+
resource "grafana_frontend_o11y_app" "test-app" {
22+
provider = grafana.cloud
23+
stack_id = data.grafana_cloud_stack.teststack.id
24+
name = "test-app"
25+
allowed_origins = ["https://grafana.com"]
26+
27+
extra_log_attributes = {
28+
"terraform" : "true"
29+
}
30+
31+
settings = {
32+
"geolocation.enabled" : "1"
33+
}
34+
}
35+
```
36+
37+
<!-- schema generated by tfplugindocs -->
38+
## Schema
39+
40+
### Required
41+
42+
- `allowed_origins` (List of String) A list of allowed origins for CORS.
43+
- `extra_log_attributes` (Map of String) The extra attributes to append in each signal.
44+
- `name` (String) The name of Frontend Observability App. Part of the Terraform Resource ID.
45+
- `settings` (Map of String) The key-value settings of the Frontend Observability app. Available Settings: `{combineLabData=(0|1)}`
46+
- `stack_id` (Number) The Stack ID of the Grafana Cloud instance. Part of the Terraform Resource ID.
47+
48+
### Read-Only
49+
50+
- `id` (Number) The Terraform Resource ID. This is auto-generated from Frontend Observability API.
51+
52+
## Import
53+
54+
Import is supported using the following syntax:
55+
56+
```shell
57+
terraform import grafana_frontend_o11y_app.name "{{ stack_id }}:{{ name }}"
58+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
data "grafana_cloud_stack" "teststack" {
2+
provider = grafana.cloud
3+
name = "gcloudstacktest"
4+
}
5+
6+
data "grafana_frontend_o11y_app" "test-app" {
7+
provider = grafana.cloud
8+
stack_id = data.grafana_cloud_stack.teststack.id
9+
name = "test-app"
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import grafana_frontend_o11y_app.name "{{ stack_id }}:{{ name }}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import grafana_frontend_o11y_app.name "{{ stack_id }}:{{ name }}"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
data "grafana_cloud_stack" "teststack" {
2+
provider = grafana.cloud
3+
name = "gcloudstacktest"
4+
}
5+
6+
resource "grafana_frontend_o11y_app" "test-app" {
7+
provider = grafana.cloud
8+
stack_id = data.grafana_cloud_stack.teststack.id
9+
name = "test-app"
10+
allowed_origins = ["https://grafana.com"]
11+
12+
extra_log_attributes = {
13+
"terraform" : "true"
14+
}
15+
16+
settings = {
17+
"geolocation.enabled" : "1"
18+
}
19+
}

internal/common/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/grafana/terraform-provider-grafana/v3/internal/common/cloudproviderapi"
1616
"github.com/grafana/terraform-provider-grafana/v3/internal/common/fleetmanagementapi"
1717

18+
"github.com/grafana/terraform-provider-grafana/v3/internal/common/frontendo11yapi"
1819
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1920
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2021

@@ -35,6 +36,7 @@ type Client struct {
3536
CloudProviderAPI *cloudproviderapi.Client
3637
ConnectionsAPIClient *connectionsapi.Client
3738
FleetManagementClient *fleetmanagementapi.Client
39+
FrontendO11yAPIClient *frontendo11yapi.Client
3840

3941
alertingMutex sync.Mutex
4042
}

0 commit comments

Comments
 (0)