Skip to content

Commit 8ee2168

Browse files
Merge branch 'master' into feat/audit-trail-event-data-source
2 parents 0e92ab4 + 122b030 commit 8ee2168

16 files changed

+2211
-3732
lines changed

docs/data-sources/cockpit_grafana.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,33 @@ output "grafana_connection_info" {
6161
}
6262
```
6363

64+
### Using the Grafana Terraform provider
65+
66+
When you need to configure Grafana resources programmatically, supply the IAM secret key as an `X-Auth-Token` header. The Grafana provider itself stays in `anonymous` mode.
67+
68+
```terraform
69+
variable "scaleway_secret_key" {
70+
description = "Scaleway IAM secret key reused by the Grafana provider"
71+
type = string
72+
sensitive = true
73+
}
74+
75+
data "scaleway_cockpit_grafana" "main" {
76+
project_id = scaleway_account_project.project.id
77+
}
78+
79+
provider "grafana" {
80+
url = data.scaleway_cockpit_grafana.main.grafana_url
81+
auth = "anonymous"
82+
83+
http_headers = {
84+
"X-Auth-Token" = var.scaleway_secret_key
85+
}
86+
}
87+
```
88+
89+
Keep the secret key in a secure backend (environment variables, Vault, etc.) and never commit it to source control.
90+
6491
## Argument Reference
6592

6693
- `project_id` - (Optional) The ID of the project the Grafana instance is associated with. If not provided, the default project configured in the provider is used.

docs/resources/cockpit_grafana_user.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ output "grafana_url" {
3838
}
3939
```
4040

41+
### Programmatic access with the Grafana provider
42+
43+
To automate Grafana configuration (e.g., dashboards, alerting) with Terraform, reuse your Scaleway IAM secret as an `X-Auth-Token` header. The Grafana provider must run in `anonymous` mode because user/password authentication is deprecated.
44+
45+
```terraform
46+
variable "scaleway_secret_key" {
47+
description = "Scaleway IAM secret key used for both the Scaleway and Grafana providers"
48+
type = string
49+
sensitive = true
50+
}
51+
52+
data "scaleway_cockpit_grafana" "main" {
53+
project_id = scaleway_account_project.project.id
54+
}
55+
56+
provider "grafana" {
57+
url = data.scaleway_cockpit_grafana.main.grafana_url
58+
auth = "anonymous"
59+
60+
http_headers = {
61+
"X-Auth-Token" = var.scaleway_secret_key
62+
}
63+
}
64+
```
65+
66+
The header `X-Auth-Token` is mandatory when Grafana users are disabled. Store the IAM secret key securely (environment variable, secrets manager, etc.) and avoid committing it to version control.
67+
4168
### Create a Grafana user (Deprecated)
4269

4370
The following command allows you to create a Grafana user within a specific Scaleway Project.

internal/acctest/acctest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type TestTools struct {
3333

3434
var foldersUsingVCRv4 = []string{
3535
"audittrail",
36+
"account",
3637
"container",
3738
"instance",
3839
"k8s",

internal/services/account/project_data_source_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package account_test
22

33
import (
44
"fmt"
5+
"strconv"
56
"testing"
67

78
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -125,6 +126,11 @@ func TestAccDataSourceProject_List(t *testing.T) {
125126
orgID = dummyOrgID
126127
}
127128

129+
projectID, projectIDExists := tt.Meta.ScwClient().GetDefaultProjectID()
130+
if !projectIDExists {
131+
t.Skip("no default project ID")
132+
}
133+
128134
resource.ParallelTest(t, resource.TestCase{
129135
ProtoV6ProviderFactories: tt.ProviderFactories,
130136
CheckDestroy: resource.ComposeTestCheckFunc(
@@ -137,11 +143,21 @@ func TestAccDataSourceProject_List(t *testing.T) {
137143
organization_id = "%s"
138144
}`, orgID),
139145
Check: resource.ComposeTestCheckFunc(
140-
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.#", "8"),
141-
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.0.id", "6867048b-fe12-4e96-835e-41c79a39604b"),
142-
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.1.id", "8cc8dd4d-a094-407a-89a3-9d004674e936"),
146+
resource.TestCheckResourceAttrSet("data.scaleway_account_projects.projects", "projects.#"),
147+
resource.TestCheckResourceAttrWith("data.scaleway_account_projects.projects", "projects.#", func(value string) error {
148+
count, err := strconv.Atoi(value)
149+
if err != nil {
150+
return err
151+
}
152+
153+
if count < 1 {
154+
return fmt.Errorf("expected at least one project, got %d", count)
155+
}
156+
157+
return nil
158+
}),
159+
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.0.id", projectID),
143160
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.0.name", "default"),
144-
resource.TestCheckResourceAttr("data.scaleway_account_projects.projects", "projects.1.name", "tf_tests_container_trigger_sqs"),
145161
),
146162
},
147163
},

0 commit comments

Comments
 (0)