Skip to content

Commit 214e9fd

Browse files
committed
docs: document stackSecretRef and stack connection secrets
Add documentation for the new stackSecretRef field on ProviderConfig, including how Stack connection secrets are produced, key remapping (oncall_api_url -> oncall_url, id -> stack_id), precedence order, and a complete example showing the Stack -> Secret -> ProviderConfig chain.
1 parent 8ea2dea commit 214e9fd

File tree

1 file changed

+98
-3
lines changed

1 file changed

+98
-3
lines changed

docs/providerconfig-secret-fields.md

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,98 @@ The following table lists all fields that can be configured in the secret, along
5353
| `stack_id` | Grafana Cloud stack ID (required for k6 resources) | ✅ Yes | `spec.stackId` |
5454
| `k6_access_token` | Access token for k6 Cloud API | ❌ No | N/A |
5555

56+
## Stack Secret Reference
57+
58+
The ProviderConfig supports an optional `stackSecretRef` field that references a Kubernetes Secret produced by a `grafana_cloud_stack` resource (managed or observed) via its `writeConnectionSecretToRef`. This secret contains all the Stack's `atProvider` fields as individual keys using their Terraform attribute names.
59+
60+
When `stackSecretRef` is set, the secret's keys are merged into the credential map with the following key remapping applied:
61+
62+
| Stack secret key | Remapped to |
63+
|------------------|-------------|
64+
| `oncall_api_url` | `oncall_url` |
65+
| `id` | `stack_id` |
66+
67+
All other keys are passed through unchanged (e.g., `url`, `fleet_management_url`, `org_id`).
68+
69+
### Precedence (lowest to highest)
70+
71+
1. **Primary credential secret** (`credentials.secretRef`) — base credentials
72+
2. **Stack secret** (`stackSecretRef`) — overrides the primary secret
73+
3. **ProviderConfig spec fields** (`url`, `oncallUrl`, etc.) — overrides both secrets
74+
75+
### Example: Using Stack Secret with ProviderConfig
76+
77+
**Step 1: Create a Stack that writes its details to a Secret:**
78+
```yaml
79+
apiVersion: cloud.grafana.m.crossplane.io/v1alpha1
80+
kind: Stack
81+
metadata:
82+
name: my-stack
83+
namespace: default
84+
spec:
85+
forProvider:
86+
name: my-stack
87+
slug: my-stack
88+
writeConnectionSecretToRef:
89+
name: my-stack-details
90+
```
91+
92+
**Step 2: Create a StackServiceAccountToken that writes auth to a Secret:**
93+
```yaml
94+
apiVersion: cloud.grafana.m.crossplane.io/v1alpha1
95+
kind: StackServiceAccountToken
96+
metadata:
97+
name: my-stack-sa-token
98+
namespace: default
99+
spec:
100+
forProvider:
101+
stackSlugRef:
102+
name: my-stack
103+
serviceAccountRef:
104+
name: my-stack-sa
105+
name: crossplane
106+
writeConnectionSecretToRef:
107+
name: my-stack-token
108+
```
109+
110+
**Step 3: Reference both secrets in a ProviderConfig:**
111+
```yaml
112+
apiVersion: grafana.m.crossplane.io/v1beta1
113+
kind: ProviderConfig
114+
metadata:
115+
name: my-stack-config
116+
namespace: default
117+
spec:
118+
credentials:
119+
source: Secret
120+
secretRef:
121+
name: my-stack-token
122+
namespace: default
123+
key: instanceCredentials
124+
stackSecretRef:
125+
name: my-stack-details
126+
namespace: default
127+
```
128+
129+
The ProviderConfig will read:
130+
- `auth` and `url` from the `instanceCredentials` key in `my-stack-token`
131+
- `oncall_url` (remapped from `oncall_api_url`), `fleet_management_url`, `org_id`, `stack_id` (remapped from `id`), and all other Stack fields from `my-stack-details`
132+
- Stack secret values override primary credential values where keys overlap (e.g., `url`)
133+
134+
### Available keys in the Stack connection secret
135+
136+
The Stack connection secret contains all scalar `atProvider` fields. Key fields relevant to ProviderConfig:
137+
138+
| Key | Description | Maps to ProviderConfig |
139+
|-----|-------------|----------------------|
140+
| `url` | Grafana instance URL | `url` |
141+
| `oncall_api_url` | OnCall API URL (remapped to `oncall_url`) | `oncallUrl` |
142+
| `fleet_management_url` | Fleet Management URL | `fleetManagementUrl` |
143+
| `id` | Stack numeric ID (remapped to `stack_id`) | `stackId` |
144+
| `org_id` | Organization ID | `orgId` |
145+
146+
Additional informational keys include: `alertmanager_url`, `prometheus_url`, `logs_url`, `traces_url`, `graphite_url`, `profiles_url`, `otlp_url`, `influx_url`, `slug`, `name`, `status`, `region_slug`, and all service-specific names, statuses, and user IDs.
147+
56148
## Override Behavior
57149

58150
When a field is marked as "Overridable by ProviderConfig":
@@ -167,6 +259,9 @@ Grafana OnCall resources can be authenticated in two ways:
167259
For more information on the Grafana Terraform provider configuration, see the [official documentation](https://registry.terraform.io/providers/grafana/grafana/latest/docs).
168260

169261
The implementation can be found in:
170-
- Secret field processing: `internal/clients/grafana.go:201-235`
171-
- ProviderConfig overrides: `internal/clients/grafana.go:237-263`
172-
- ProviderConfig spec definition: `apis/cluster/v1beta1/types.go:14-36`
262+
- Secret field processing: `internal/clients/grafana.go`
263+
- Stack secret merging: `internal/clients/grafana.go` (`mergeStackSecret`)
264+
- ProviderConfig spec definition: `apis/cluster/v1beta1/types.go` and `apis/namespaced/v1beta1/types.go`
265+
- Managed Stack connection details: `config/grafana/cloud.go` (`AdditionalConnectionDetailsFn`)
266+
- Observed Stack connection details: generated in `internal/controller/namespaced/observed/cloud/zz_stack_spec.go` (`ConnectionDetailsFn`)
267+
- Connection details controller support: `pkg/tfdatasource/controller.go`

0 commit comments

Comments
 (0)