Skip to content

Commit 683e6c1

Browse files
Add support for Grafana Cloud Fleet Management (#1989)
1 parent 39ecb81 commit 683e6c1

Some content is hidden

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

53 files changed

+3123
-7
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/internal/resources/cloud/* @grafana/platform-monitoring @grafana/grafana-com-maintainers
55
/internal/resources/cloudprovider/* @grafana/platform-monitoring @grafana/middleware-apps
66
/internal/resources/connections/* @grafana/platform-monitoring @grafana/middleware-apps
7+
/internal/resources/fleetmanagement/* @grafana/platform-monitoring @grafana/fleet-management-backend
78
/internal/resources/machinelearning/* @grafana/platform-monitoring @grafana/machine-learning
89
/internal/resources/oncall/* @grafana/platform-monitoring @grafana/grafana-irm-backend
910
/internal/resources/slo/* @grafana/platform-monitoring @grafana/slo-squad

.github/workflows/acc-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jobs:
4848
GRAFANA_CLOUD_PROVIDER_ACCESS_TOKEN=cloudprovider-tests:access-token
4949
GRAFANA_CLOUD_PROVIDER_AWS_ROLE_ARN=cloudprovider-tests:aws-role-arn
5050
GRAFANA_CLOUD_PROVIDER_TEST_STACK_ID=cloudprovider-tests:test-stack-id
51+
GRAFANA_FLEET_MANAGEMENT_AUTH=cloud-instance-tests:fleet-management-auth
52+
GRAFANA_FLEET_MANAGEMENT_URL=cloud-instance-tests:fleet-management-url
5153
- uses: iFaxity/wait-on-action@a7d13170ec542bdca4ef8ac4b15e9c6aa00a6866 # v1.2.1
5254
with:
5355
resource: ${{ env.GRAFANA_URL }}

docs/data-sources/cloud_stack.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ available at “https://<stack_slug>.grafana.net".
4141
- `alertmanager_user_id` (Number) User ID of the Alertmanager instance configured for this stack.
4242
- `cluster_slug` (String) Slug of the cluster where this stack resides.
4343
- `description` (String) Description of stack.
44+
- `fleet_management_name` (String) Name of the Fleet Management instance configured for this stack.
45+
- `fleet_management_status` (String) Status of the Fleet Management instance configured for this stack.
46+
- `fleet_management_url` (String) Base URL of the Fleet Management instance configured for this stack.
47+
- `fleet_management_user_id` (Number) User ID of the Fleet Management instance configured for this stack.
4448
- `graphite_name` (String)
4549
- `graphite_status` (String)
4650
- `graphite_url` (String)

docs/index.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ resource "grafana_oncall_escalation" "example_notify_step" {
255255
- `cloud_provider_url` (String) A Grafana Cloud Provider backend address. May alternatively be set via the `GRAFANA_CLOUD_PROVIDER_URL` environment variable.
256256
- `connections_api_access_token` (String, Sensitive) A Grafana Connections API access token. May alternatively be set via the `GRAFANA_CONNECTIONS_API_ACCESS_TOKEN` environment variable.
257257
- `connections_api_url` (String) A Grafana Connections API address. May alternatively be set via the `GRAFANA_CONNECTIONS_API_URL` environment variable.
258+
- `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.
259+
- `fleet_management_url` (String) A Grafana Fleet Management API address. May alternatively be set via the `GRAFANA_FLEET_MANAGEMENT_URL` environment variable.
258260
- `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.
259261
- `insecure_skip_verify` (Boolean) Skip TLS certificate verification. May alternatively be set via the `GRAFANA_INSECURE_SKIP_VERIFY` environment variable.
260262
- `oncall_access_token` (String, Sensitive) A Grafana OnCall access token. May alternatively be set via the `GRAFANA_ONCALL_ACCESS_TOKEN` environment variable.
@@ -450,6 +452,91 @@ provider "grafana" {
450452
}
451453
```
452454

455+
### Managing Grafana Fleet Management
456+
457+
```terraform
458+
// Variables
459+
variable "cloud_access_policy_token" {
460+
type = string
461+
description = "Cloud access policy token with scopes: accesspolicies:read|write|delete, stacks:read"
462+
}
463+
464+
variable "stack_slug" {
465+
type = string
466+
description = "Subdomain that the Grafana Cloud instance is available at: https://<stack_slug>.grafana.net"
467+
}
468+
469+
// Step 1: Retrieve stack details
470+
provider "grafana" {
471+
alias = "cloud"
472+
473+
cloud_access_policy_token = var.cloud_access_policy_token
474+
}
475+
476+
data "grafana_cloud_stack" "stack" {
477+
provider = grafana.cloud
478+
479+
slug = var.stack_slug
480+
}
481+
482+
// Step 2: Create an access policy and token for Fleet Management
483+
resource "grafana_cloud_access_policy" "policy" {
484+
provider = grafana.cloud
485+
486+
name = "fleet-management-policy"
487+
region = data.grafana_cloud_stack.stack.region_slug
488+
489+
scopes = [
490+
"fleet-management:read",
491+
"fleet-management:write"
492+
]
493+
494+
realm {
495+
type = "stack"
496+
identifier = data.grafana_cloud_stack.stack.id
497+
}
498+
}
499+
500+
resource "grafana_cloud_access_policy_token" "token" {
501+
provider = grafana.cloud
502+
503+
name = "fleet-management-token"
504+
region = grafana_cloud_access_policy.policy.region
505+
access_policy_id = grafana_cloud_access_policy.policy.policy_id
506+
}
507+
508+
// Step 3: Interact with Fleet Management
509+
provider "grafana" {
510+
alias = "fm"
511+
512+
fleet_management_auth = "${data.grafana_cloud_stack.stack.fleet_management_user_id}:${grafana_cloud_access_policy_token.token.token}"
513+
fleet_management_url = data.grafana_cloud_stack.stack.fleet_management_url
514+
}
515+
516+
resource "grafana_fleet_management_collector" "collector" {
517+
provider = grafana.fm
518+
519+
id = "my_collector"
520+
remote_attributes = {
521+
"env" = "PROD",
522+
"owner" = "TEAM-A"
523+
}
524+
enabled = true
525+
}
526+
527+
resource "grafana_fleet_management_pipeline" "pipeline" {
528+
provider = grafana.fm
529+
530+
name = "my_pipeline"
531+
contents = file("config.alloy")
532+
matchers = [
533+
"collector.os=\"linux\"",
534+
"env=\"PROD\""
535+
]
536+
enabled = true
537+
}
538+
```
539+
453540
## Authentication
454541

455542
One, or many, of the following authentication settings must be set. Each authentication setting allows a subset of resources to be used
@@ -483,3 +570,10 @@ To create one, follow the instructions in the [obtaining cloud provider access t
483570
An access policy token created on the [Grafana Cloud Portal](https://grafana.com/docs/grafana-cloud/account-management/authentication-and-permissions/access-policies/using-an-access-policy-token/) to manage
484571
connections resources, such as Metrics Endpoint jobs.
485572
For guidance on creating one, see section [obtaining connections access token](#obtaining-connections-access-token).
573+
574+
### `fleet_management_auth`
575+
576+
[Grafana Fleet Management](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/api-reference/)
577+
uses basic auth to allow access to the API, where the username is the Fleet Management instance ID and the
578+
password is the API token. You can access the instance ID and request a new Fleet Management API token on the
579+
Connections -> Collector -> Fleet Management page, in the API tab.

docs/resources/cloud_stack.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ resource "grafana_cloud_stack" "test" {
5353
- `alertmanager_url` (String) Base URL of the Alertmanager instance configured for this stack.
5454
- `alertmanager_user_id` (Number) User ID of the Alertmanager instance configured for this stack.
5555
- `cluster_slug` (String) Slug of the cluster where this stack resides.
56+
- `fleet_management_name` (String) Name of the Fleet Management instance configured for this stack.
57+
- `fleet_management_status` (String) Status of the Fleet Management instance configured for this stack.
58+
- `fleet_management_url` (String) Base URL of the Fleet Management instance configured for this stack.
59+
- `fleet_management_user_id` (Number) User ID of the Fleet Management instance configured for this stack.
5660
- `graphite_name` (String)
5761
- `graphite_status` (String)
5862
- `graphite_url` (String)
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_fleet_management_collector Resource - terraform-provider-grafana"
4+
subcategory: "Fleet Management"
5+
description: |-
6+
Manages Grafana Fleet Management collectors.
7+
Official documentation https://grafana.com/docs/grafana-cloud/send-data/fleet-management/API documentation https://grafana.com/docs/grafana-cloud/send-data/fleet-management/api-reference/collector-api/
8+
Note: Fleet Management is in public preview https://grafana.com/docs/release-life-cycle/#public-preview and this resource is experimental. Grafana Labs offers limited support, and breaking changes might occur.
9+
Required access policy scopes:
10+
fleet-management:readfleet-management:write
11+
---
12+
13+
# grafana_fleet_management_collector (Resource)
14+
15+
Manages Grafana Fleet Management collectors.
16+
17+
* [Official documentation](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/)
18+
* [API documentation](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/api-reference/collector-api/)
19+
20+
**Note:** Fleet Management is in [public preview](https://grafana.com/docs/release-life-cycle/#public-preview) and this resource is experimental. Grafana Labs offers limited support, and breaking changes might occur.
21+
22+
Required access policy scopes:
23+
24+
* fleet-management:read
25+
* fleet-management:write
26+
27+
## Example Usage
28+
29+
```terraform
30+
resource "grafana_fleet_management_collector" "test" {
31+
id = "my_collector"
32+
remote_attributes = {
33+
"env" = "PROD",
34+
"owner" = "TEAM-A"
35+
}
36+
enabled = true
37+
}
38+
```
39+
40+
<!-- schema generated by tfplugindocs -->
41+
## Schema
42+
43+
### Required
44+
45+
- `id` (String) ID of the collector
46+
47+
### Optional
48+
49+
- `enabled` (Boolean) Whether the collector is enabled or not
50+
- `remote_attributes` (Map of String) Remote attributes for the collector
51+
52+
## Import
53+
54+
Import is supported using the following syntax:
55+
56+
```shell
57+
terraform import grafana_fleet_management_collector.name "{{ id }}"
58+
```
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "grafana_fleet_management_pipeline Resource - terraform-provider-grafana"
4+
subcategory: "Fleet Management"
5+
description: |-
6+
Manages Grafana Fleet Management pipelines.
7+
Official documentation https://grafana.com/docs/grafana-cloud/send-data/fleet-management/API documentation https://grafana.com/docs/grafana-cloud/send-data/fleet-management/api-reference/pipeline-api/
8+
Note: Fleet Management is in public preview https://grafana.com/docs/release-life-cycle/#public-preview and this resource is experimental. Grafana Labs offers limited support, and breaking changes might occur.
9+
Required access policy scopes:
10+
fleet-management:readfleet-management:write
11+
---
12+
13+
# grafana_fleet_management_pipeline (Resource)
14+
15+
Manages Grafana Fleet Management pipelines.
16+
17+
* [Official documentation](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/)
18+
* [API documentation](https://grafana.com/docs/grafana-cloud/send-data/fleet-management/api-reference/pipeline-api/)
19+
20+
**Note:** Fleet Management is in [public preview](https://grafana.com/docs/release-life-cycle/#public-preview) and this resource is experimental. Grafana Labs offers limited support, and breaking changes might occur.
21+
22+
Required access policy scopes:
23+
24+
* fleet-management:read
25+
* fleet-management:write
26+
27+
## Example Usage
28+
29+
```terraform
30+
resource "grafana_fleet_management_pipeline" "test" {
31+
name = "my_pipeline"
32+
contents = file("config.alloy")
33+
matchers = [
34+
"collector.os=~\".*\"",
35+
"env=\"PROD\""
36+
]
37+
enabled = true
38+
}
39+
```
40+
41+
<!-- schema generated by tfplugindocs -->
42+
## Schema
43+
44+
### Required
45+
46+
- `contents` (String) Configuration contents of the pipeline to be used by collectors
47+
- `name` (String) Name of the pipeline which is the unique identifier for the pipeline
48+
49+
### Optional
50+
51+
- `enabled` (Boolean) Whether the pipeline is enabled for collectors
52+
- `matchers` (List of String) Used to match against collectors and assign pipelines to them; follows the syntax of Prometheus Alertmanager matchers
53+
54+
### Read-Only
55+
56+
- `id` (String) Server-assigned ID of the pipeline
57+
58+
## Import
59+
60+
Import is supported using the following syntax:
61+
62+
```shell
63+
terraform import grafana_fleet_management_pipeline.name "{{ name }}"
64+
```
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Variables
2+
variable "cloud_access_policy_token" {
3+
type = string
4+
description = "Cloud access policy token with scopes: accesspolicies:read|write|delete, stacks:read"
5+
}
6+
7+
variable "stack_slug" {
8+
type = string
9+
description = "Subdomain that the Grafana Cloud instance is available at: https://<stack_slug>.grafana.net"
10+
}
11+
12+
// Step 1: Retrieve stack details
13+
provider "grafana" {
14+
alias = "cloud"
15+
16+
cloud_access_policy_token = var.cloud_access_policy_token
17+
}
18+
19+
data "grafana_cloud_stack" "stack" {
20+
provider = grafana.cloud
21+
22+
slug = var.stack_slug
23+
}
24+
25+
// Step 2: Create an access policy and token for Fleet Management
26+
resource "grafana_cloud_access_policy" "policy" {
27+
provider = grafana.cloud
28+
29+
name = "fleet-management-policy"
30+
region = data.grafana_cloud_stack.stack.region_slug
31+
32+
scopes = [
33+
"fleet-management:read",
34+
"fleet-management:write"
35+
]
36+
37+
realm {
38+
type = "stack"
39+
identifier = data.grafana_cloud_stack.stack.id
40+
}
41+
}
42+
43+
resource "grafana_cloud_access_policy_token" "token" {
44+
provider = grafana.cloud
45+
46+
name = "fleet-management-token"
47+
region = grafana_cloud_access_policy.policy.region
48+
access_policy_id = grafana_cloud_access_policy.policy.policy_id
49+
}
50+
51+
// Step 3: Interact with Fleet Management
52+
provider "grafana" {
53+
alias = "fm"
54+
55+
fleet_management_auth = "${data.grafana_cloud_stack.stack.fleet_management_user_id}:${grafana_cloud_access_policy_token.token.token}"
56+
fleet_management_url = data.grafana_cloud_stack.stack.fleet_management_url
57+
}
58+
59+
resource "grafana_fleet_management_collector" "collector" {
60+
provider = grafana.fm
61+
62+
id = "my_collector"
63+
remote_attributes = {
64+
"env" = "PROD",
65+
"owner" = "TEAM-A"
66+
}
67+
enabled = true
68+
}
69+
70+
resource "grafana_fleet_management_pipeline" "pipeline" {
71+
provider = grafana.fm
72+
73+
name = "my_pipeline"
74+
contents = file("config.alloy")
75+
matchers = [
76+
"collector.os=\"linux\"",
77+
"env=\"PROD\""
78+
]
79+
enabled = true
80+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import grafana_fleet_management_collector.name "{{ id }}"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "grafana_fleet_management_collector" "test" {
2+
id = "my_collector"
3+
remote_attributes = {
4+
"env" = "PROD",
5+
"owner" = "TEAM-A"
6+
}
7+
enabled = true
8+
}

0 commit comments

Comments
 (0)