Skip to content

Commit da5da7c

Browse files
Docs + provider config: Deprecate cloud_api_key (#1366)
Related to #1365 We should now be using Cloud Access Policy tokens, not API keys. Let's deprecate the whole "API Key" naming to remove confusion
1 parent 7bd9ba7 commit da5da7c

File tree

8 files changed

+57
-121
lines changed

8 files changed

+57
-121
lines changed

.github/workflows/cloud-acc-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
uses: grafana/shared-workflows/actions/get-vault-secrets@main
2626
with:
2727
repo_secrets: |
28-
GRAFANA_CLOUD_API_KEY=cloud-tests:api-key
28+
GRAFANA_CLOUD_ACCESS_POLICY_TOKEN=cloud-tests:api-key
2929
GRAFANA_CLOUD_ORG=cloud-tests:org
3030
- run: make testacc-cloud-api
3131
env:

docs/index.md

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ resource "grafana_oncall_escalation" "example_notify_step" {
206206

207207
- `auth` (String, Sensitive) API token, basic auth in the `username:password` format or `anonymous` (string literal). May alternatively be set via the `GRAFANA_AUTH` environment variable.
208208
- `ca_cert` (String) Certificate CA bundle (file path or literal value) to use to verify the Grafana server's certificate. May alternatively be set via the `GRAFANA_CA_CERT` environment variable.
209-
- `cloud_api_key` (String, Sensitive) Access Policy Token (or API key) for Grafana Cloud. May alternatively be set via the `GRAFANA_CLOUD_API_KEY` environment variable.
209+
- `cloud_access_policy_token` (String, Sensitive) Access Policy Token for Grafana Cloud. May alternatively be set via the `GRAFANA_CLOUD_ACCESS_POLICY_TOKEN` environment variable.
210+
- `cloud_api_key` (String, Sensitive, Deprecated) Deprecated: Use `cloud_access_policy_token` instead.
210211
- `cloud_api_url` (String) Grafana Cloud's API URL. May alternatively be set via the `GRAFANA_CLOUD_API_URL` environment variable.
211212
- `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.
212213
- `insecure_skip_verify` (Boolean) Skip TLS certificate verification. May alternatively be set via the `GRAFANA_INSECURE_SKIP_VERIFY` environment variable.
@@ -230,57 +231,16 @@ One, or many, of the following authentication settings must be set. Each authent
230231
### `auth`
231232

232233
This can be a Grafana API key, basic auth `username:password`, or a
233-
[Grafana API key](https://grafana.com/docs/grafana/latest/developers/http_api/create-api-tokens-for-org/).
234+
[Grafana Service Account token](https://grafana.com/docs/grafana/latest/developers/http_api/create-api-tokens-for-org/).
234235

235-
### `cloud_api_key`
236+
### `cloud_access_policy_token`
236237

237238
An access policy token created on the [Grafana Cloud Portal](https://grafana.com/docs/grafana-cloud/account-management/authentication-and-permissions/create-api-key/).
238239

239240
### `sm_access_token`
240241

241-
[Synthetic Monitoring](https://grafana.com/docs/grafana-cloud/monitor-public-endpoints/)
242-
endpoints require a dedicated access token. You may obtain an access token with its
243-
[Registration API](https://github.com/grafana/synthetic-monitoring-api-go-client/blob/main/docs/API.md#registration-api).
244-
245-
```console
246-
curl \
247-
-X POST \
248-
-H 'Content-type: application/json; charset=utf-8' \
249-
-H "Authorization: Bearer $GRAFANA_CLOUD_API_KEY" \
250-
-d '{"stackId": <stack-id>, "metricsInstanceId": <metrics-instance-id>, "logsInstanceId": <logs-instance-id>}' \
251-
"$SM_API_URL/api/v1/register/install"
252-
```
253-
254-
`GRAFANA_CLOUD_API_KEY` is an API key created on the
255-
[Grafana Cloud Portal](https://grafana.com/docs/grafana-cloud/account-management/authentication-and-permissions/create-api-key/).
256-
It must have the `MetricsPublisher` role.
257-
258-
`SM_API_URL` is the URL of the Synthetic Monitoring API.
259-
Based on the region of your Grafana Cloud stack, you need to use a different API URL.
260-
261-
Please [see API docs](https://github.com/grafana/synthetic-monitoring-api-go-client/blob/main/docs/API.md#api-url) to find `SM_API_URL` for your region.
262-
263-
`stackId`, `metricsInstanceId`, and `logsInstanceId` may also be obtained on
264-
the portal. First, you need to create a Stack by clicking "Add Stack". When it's
265-
created you will be taken to its landing page on the portal. Get your `stackId`
266-
from the URL in your browser:
267-
268-
```
269-
https://grafana.com/orgs/<org-slug>/stacks/<stack-id>
270-
```
271-
272-
Next, go to "Details" for Prometheus. Again, get `metricsInstanceId` from your URL:
273-
274-
```
275-
https://grafana.com/orgs/<org-slug>/hosted-metrics/<metrics-instance-id>
276-
```
277-
278-
Finally, go back to your stack page, and go to "Details" for Loki to get
279-
`logsInstanceId`.
280-
281-
```
282-
https://grafana.com/orgs/<org-slug>/hosted-logs/<logs-instance-id>
283-
```
242+
[Grafana Synthetic Monitoring](https://grafana.com/docs/grafana-cloud/monitor-public-endpoints/) uses distinct tokens for API access.
243+
You can use the `grafana_synthetic_monitoring_installation` resource as shown above or you can request a new Synthetic Monitoring API key in Synthetics -> Config page.
284244

285245
### `oncall_access_token`
286246

internal/provider/configure_clients.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func createClients(providerConfig frameworkProviderConfig) (*common.Client, erro
4040
return nil, err
4141
}
4242
}
43-
if !providerConfig.CloudAPIKey.IsNull() {
43+
if !providerConfig.CloudAccessPolicyToken.IsNull() {
4444
if err := createCloudClient(c, providerConfig); err != nil {
4545
return nil, err
4646
}
@@ -146,7 +146,7 @@ func createCloudClient(client *common.Client, providerConfig frameworkProviderCo
146146
openAPIConfig.Host = parsedURL.Host
147147
openAPIConfig.Scheme = "https"
148148
openAPIConfig.HTTPClient = getRetryClient(providerConfig)
149-
openAPIConfig.DefaultHeader["Authorization"] = "Bearer " + providerConfig.CloudAPIKey.ValueString()
149+
openAPIConfig.DefaultHeader["Authorization"] = "Bearer " + providerConfig.CloudAccessPolicyToken.ValueString()
150150
httpHeaders, err := getHTTPHeadersMap(providerConfig)
151151
if err != nil {
152152
return err

internal/provider/framework_provider.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type frameworkProviderConfig struct {
3232

3333
StoreDashboardSha256 types.Bool `tfsdk:"store_dashboard_sha256"`
3434

35-
CloudAPIKey types.String `tfsdk:"cloud_api_key"`
36-
CloudAPIURL types.String `tfsdk:"cloud_api_url"`
35+
CloudAccessPolicyToken types.String `tfsdk:"cloud_access_policy_token"`
36+
CloudAPIURL types.String `tfsdk:"cloud_api_url"`
3737

3838
SMAccessToken types.String `tfsdk:"sm_access_token"`
3939
SMURL types.String `tfsdk:"sm_url"`
@@ -52,7 +52,8 @@ func (c *frameworkProviderConfig) SetDefaults() error {
5252
c.TLSKey = envDefaultFuncString(c.TLSKey, "GRAFANA_TLS_KEY")
5353
c.TLSCert = envDefaultFuncString(c.TLSCert, "GRAFANA_TLS_CERT")
5454
c.CACert = envDefaultFuncString(c.CACert, "GRAFANA_CA_CERT")
55-
c.CloudAPIKey = envDefaultFuncString(c.CloudAPIKey, "GRAFANA_CLOUD_API_KEY")
55+
c.CloudAccessPolicyToken = envDefaultFuncString(c.CloudAccessPolicyToken, "GRAFANA_CLOUD_ACCESS_POLICY_TOKEN")
56+
c.CloudAccessPolicyToken = envDefaultFuncString(c.CloudAccessPolicyToken, "GRAFANA_CLOUD_API_KEY") // Backwards compatibility. TODO: Remove once cloud_api_key is removed
5657
c.CloudAPIURL = envDefaultFuncString(c.CloudAPIURL, "GRAFANA_CLOUD_API_URL", "https://grafana.com")
5758
c.SMAccessToken = envDefaultFuncString(c.SMAccessToken, "GRAFANA_SM_ACCESS_TOKEN")
5859
c.SMURL = envDefaultFuncString(c.SMURL, "GRAFANA_SM_URL", "https://synthetic-monitoring-api.grafana.net")
@@ -170,10 +171,16 @@ func (p *frameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
170171
MarkdownDescription: "Set to true if you want to save only the sha256sum instead of complete dashboard model JSON in the tfstate.",
171172
},
172173

174+
"cloud_access_policy_token": schema.StringAttribute{
175+
Optional: true,
176+
Sensitive: true,
177+
MarkdownDescription: "Access Policy Token for Grafana Cloud. May alternatively be set via the `GRAFANA_CLOUD_ACCESS_POLICY_TOKEN` environment variable.",
178+
},
173179
"cloud_api_key": schema.StringAttribute{
174180
Optional: true,
175181
Sensitive: true,
176-
MarkdownDescription: "Access Policy Token (or API key) for Grafana Cloud. May alternatively be set via the `GRAFANA_CLOUD_API_KEY` environment variable.",
182+
DeprecationMessage: "Use `cloud_access_policy_token` instead.",
183+
MarkdownDescription: "Deprecated: Use `cloud_access_policy_token` instead.",
177184
},
178185
"cloud_api_url": schema.StringAttribute{
179186
Optional: true,

internal/provider/legacy_provider.go

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,23 @@ func Provider(version string) *schema.Provider {
222222
Description: "Skip TLS certificate verification. May alternatively be set via the `GRAFANA_INSECURE_SKIP_VERIFY` environment variable.",
223223
},
224224

225+
"cloud_access_policy_token": {
226+
Type: schema.TypeString,
227+
Optional: true,
228+
Sensitive: true,
229+
ConflictsWith: []string{"cloud_api_key"},
230+
Description: "Access Policy Token for Grafana Cloud. May alternatively be set via the `GRAFANA_CLOUD_ACCESS_POLICY_TOKEN` environment variable.",
231+
},
225232
"cloud_api_key": {
226233
Type: schema.TypeString,
227234
Optional: true,
228235
Sensitive: true,
229-
Description: "Access Policy Token (or API key) for Grafana Cloud. May alternatively be set via the `GRAFANA_CLOUD_API_KEY` environment variable.",
236+
Deprecated: "Use `cloud_access_policy_token` instead.",
237+
Description: "Deprecated: Use `cloud_access_policy_token` instead.",
230238
},
231239
"cloud_api_url": {
232240
Type: schema.TypeString,
233241
Optional: true,
234-
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_CLOUD_API_URL", "https://grafana.com"),
235242
Description: "Grafana Cloud's API URL. May alternatively be set via the `GRAFANA_CLOUD_API_URL` environment variable.",
236243
ValidateFunc: validation.IsURLWithHTTPorHTTPS,
237244
},
@@ -310,25 +317,28 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
310317
}
311318

312319
cfg := frameworkProviderConfig{
313-
Auth: stringValueOrNull(d, "auth"),
314-
URL: stringValueOrNull(d, "url"),
315-
OrgID: int64ValueOrNull(d, "org_id"),
316-
TLSKey: stringValueOrNull(d, "tls_key"),
317-
TLSCert: stringValueOrNull(d, "tls_cert"),
318-
CACert: stringValueOrNull(d, "ca_cert"),
319-
InsecureSkipVerify: boolValueOrNull(d, "insecure_skip_verify"),
320-
CloudAPIKey: stringValueOrNull(d, "cloud_api_key"),
321-
CloudAPIURL: stringValueOrNull(d, "cloud_api_url"),
322-
SMAccessToken: stringValueOrNull(d, "sm_access_token"),
323-
SMURL: stringValueOrNull(d, "sm_url"),
324-
OncallAccessToken: stringValueOrNull(d, "oncall_access_token"),
325-
OncallURL: stringValueOrNull(d, "oncall_url"),
326-
StoreDashboardSha256: boolValueOrNull(d, "store_dashboard_sha256"),
327-
HTTPHeaders: headers,
328-
Retries: int64ValueOrNull(d, "retries"),
329-
RetryStatusCodes: statusCodes,
330-
RetryWait: types.Int64Value(int64(d.Get("retry_wait").(int))),
331-
UserAgent: types.StringValue(p.UserAgent("terraform-provider-grafana", version)),
320+
Auth: stringValueOrNull(d, "auth"),
321+
URL: stringValueOrNull(d, "url"),
322+
OrgID: int64ValueOrNull(d, "org_id"),
323+
TLSKey: stringValueOrNull(d, "tls_key"),
324+
TLSCert: stringValueOrNull(d, "tls_cert"),
325+
CACert: stringValueOrNull(d, "ca_cert"),
326+
InsecureSkipVerify: boolValueOrNull(d, "insecure_skip_verify"),
327+
CloudAccessPolicyToken: stringValueOrNull(d, "cloud_access_policy_token"),
328+
CloudAPIURL: stringValueOrNull(d, "cloud_api_url"),
329+
SMAccessToken: stringValueOrNull(d, "sm_access_token"),
330+
SMURL: stringValueOrNull(d, "sm_url"),
331+
OncallAccessToken: stringValueOrNull(d, "oncall_access_token"),
332+
OncallURL: stringValueOrNull(d, "oncall_url"),
333+
StoreDashboardSha256: boolValueOrNull(d, "store_dashboard_sha256"),
334+
HTTPHeaders: headers,
335+
Retries: int64ValueOrNull(d, "retries"),
336+
RetryStatusCodes: statusCodes,
337+
RetryWait: types.Int64Value(int64(d.Get("retry_wait").(int))),
338+
UserAgent: types.StringValue(p.UserAgent("terraform-provider-grafana", version)),
339+
}
340+
if cfg.CloudAccessPolicyToken.IsNull() {
341+
cfg.CloudAccessPolicyToken = stringValueOrNull(d, "cloud_api_key") // TODO: Remove once `cloud_api_key` is removed
332342
}
333343
if err := cfg.SetDefaults(); err != nil {
334344
return nil, diag.FromErr(err)

internal/provider/legacy_provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestProviderConfigure(t *testing.T) {
121121
{
122122
name: "grafana cloud config from env",
123123
env: map[string]string{
124-
"GRAFANA_CLOUD_API_KEY": "testtest",
124+
"GRAFANA_CLOUD_ACCESS_POLICY_TOKEN": "testtest",
125125
},
126126
},
127127
{

internal/testutils/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func CheckCloudAPITestsEnabled(t *testing.T) {
136136
t.Skip("TF_ACC_CLOUD_API must be set to a truthy value for Cloud API acceptance tests")
137137
}
138138

139-
CheckEnvVarsSet(t, "GRAFANA_CLOUD_API_KEY", "GRAFANA_CLOUD_ORG")
139+
CheckEnvVarsSet(t, "GRAFANA_CLOUD_ACCESS_POLICY_TOKEN", "GRAFANA_CLOUD_ORG")
140140
}
141141

142142
// CheckCloudInstanceTestsEnabled checks if tests that run on cloud instances are enabled. This should be the first line of any test that tests Grafana Cloud Pro features

templates/index.md.tmpl

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,57 +37,16 @@ One, or many, of the following authentication settings must be set. Each authent
3737
### `auth`
3838

3939
This can be a Grafana API key, basic auth `username:password`, or a
40-
[Grafana API key](https://grafana.com/docs/grafana/latest/developers/http_api/create-api-tokens-for-org/).
40+
[Grafana Service Account token](https://grafana.com/docs/grafana/latest/developers/http_api/create-api-tokens-for-org/).
4141

42-
### `cloud_api_key`
42+
### `cloud_access_policy_token`
4343

4444
An access policy token created on the [Grafana Cloud Portal](https://grafana.com/docs/grafana-cloud/account-management/authentication-and-permissions/create-api-key/).
4545

4646
### `sm_access_token`
4747

48-
[Synthetic Monitoring](https://grafana.com/docs/grafana-cloud/monitor-public-endpoints/)
49-
endpoints require a dedicated access token. You may obtain an access token with its
50-
[Registration API](https://github.com/grafana/synthetic-monitoring-api-go-client/blob/main/docs/API.md#registration-api).
51-
52-
```console
53-
curl \
54-
-X POST \
55-
-H 'Content-type: application/json; charset=utf-8' \
56-
-H "Authorization: Bearer $GRAFANA_CLOUD_API_KEY" \
57-
-d '{"stackId": <stack-id>, "metricsInstanceId": <metrics-instance-id>, "logsInstanceId": <logs-instance-id>}' \
58-
"$SM_API_URL/api/v1/register/install"
59-
```
60-
61-
`GRAFANA_CLOUD_API_KEY` is an API key created on the
62-
[Grafana Cloud Portal](https://grafana.com/docs/grafana-cloud/account-management/authentication-and-permissions/create-api-key/).
63-
It must have the `MetricsPublisher` role.
64-
65-
`SM_API_URL` is the URL of the Synthetic Monitoring API.
66-
Based on the region of your Grafana Cloud stack, you need to use a different API URL.
67-
68-
Please [see API docs](https://github.com/grafana/synthetic-monitoring-api-go-client/blob/main/docs/API.md#api-url) to find `SM_API_URL` for your region.
69-
70-
`stackId`, `metricsInstanceId`, and `logsInstanceId` may also be obtained on
71-
the portal. First, you need to create a Stack by clicking "Add Stack". When it's
72-
created you will be taken to its landing page on the portal. Get your `stackId`
73-
from the URL in your browser:
74-
75-
```
76-
https://grafana.com/orgs/<org-slug>/stacks/<stack-id>
77-
```
78-
79-
Next, go to "Details" for Prometheus. Again, get `metricsInstanceId` from your URL:
80-
81-
```
82-
https://grafana.com/orgs/<org-slug>/hosted-metrics/<metrics-instance-id>
83-
```
84-
85-
Finally, go back to your stack page, and go to "Details" for Loki to get
86-
`logsInstanceId`.
87-
88-
```
89-
https://grafana.com/orgs/<org-slug>/hosted-logs/<logs-instance-id>
90-
```
48+
[Grafana Synthetic Monitoring](https://grafana.com/docs/grafana-cloud/monitor-public-endpoints/) uses distinct tokens for API access.
49+
You can use the `grafana_synthetic_monitoring_installation` resource as shown above or you can request a new Synthetic Monitoring API key in Synthetics -> Config page.
9150

9251
### `oncall_access_token`
9352

0 commit comments

Comments
 (0)