grafana / crossplane-provider-grafana

Crossplane provider of https://github.com/grafana/terraform-provider-grafana. Generated by https://github.com/upbound/upjet
Apache License 2.0
26 stars 14 forks source link

use provider with OSS installation? #32

Closed davidgiga1993 closed 7 months ago

davidgiga1993 commented 1 year ago

So far I haven't found a way to specify the url of the oss installation that should be used. Is this even possible or is this provider only for the cloud instances?

patst commented 1 year ago

works fine for us. You can take a look at the terraform grafana-provider configuration and just put that in the secret with the connection details. The secrets content could look like this:

 {
            "auth": "admin:<supersecret>",
            "url": "https://grafana.your.domain.org"
          }
davidgiga1993 commented 1 year ago

Ah I thought it should go into the provider config directly, which confused me since it's not in the CRD spec for that. Maybe it would help others to document this in the readme?

mrchypark commented 1 year ago

Now I understand, so I'm leaving a record.

First, we deploy provider-grafana.

# provider.yaml
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
  name: provider-grafana
spec:
  package: xpkg.upbound.io/grafana/provider-grafana:v0.6.0
kubectl apply -f provider.yaml

Now, create a JSON file in the format mentioned in the above conversation.

# grafana-secret.json
{
    "auth": "admin:a234!56gsd@deW",
    "url": "http://grafana.default.svc.cluster.local:8880"
}

Turn this JSON into a k8s secret.

kubectl create secret generic grafana-secret -n upbound-system --from-file=auth=grafana-secret.json

Make a ProviderConfig that uses this secret.

# providerConfig.yaml
apiVersion: grafana.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
  name: grafana-config
spec:
  credentials:
    secretRef:
      key: auth
      name: grafana-secret
      namespace: upbound-system
    source: Secret

Now you can use it to create resources.

Thank you both for giving me hints to solve the problem.

paulschroeder-tomtom commented 5 months ago

Hey, I cannot seem to get it to work. Our GF instance resides under https://grafana.<domain>.com, I set up the PC like so:

---
apiVersion: v1
kind: Secret
metadata:
  name: grafana.cloud.token
  namespace: crossplane-system
type: Opaque
stringData:
  credentials: |
    {
      "cloud_api_key": "<token>",
      "url": "https://grafana.<domain>.com"
    }
---
apiVersion: grafana.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
  name: grafana.cloud
spec:
  credentials:
    source: Secret
    secretRef:
      name: grafana.cloud.token
      namespace: crossplane-system
      key: credentials

And the dashboard:

---
apiVersion: oss.grafana.crossplane.io/v1alpha1
kind: Dashboard
metadata:
  name: test-dashboard
spec:
  forProvider:
    folderRef:
      name: test-folder
    configJson: |
      {
        "title": "Crossplane Test!",
        "uid": "crossplane"
      }
  providerConfigRef:
    name: grafana.cloud

But the provider still seem to hit the public GF instance:

$ k logs -n crossplane-system provider-grafana-<id> -f --tail=60
2024/03/28 15:18:05 [TRACE] Waiting 10s before next try
2024/03/28 15:18:15 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:18:15 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:18:25 [TRACE] Waiting 10s before next try
2024/03/28 15:18:27 [WARN] WaitForState timeout after 2m0s
2024/03/28 15:18:27 [WARN] WaitForState starting 30s refresh grace period
2024/03/28 15:18:28 [DEBUG] Waiting for state to become: [success]
2024/03/28 15:18:28 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:18:28 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:18:38 [TRACE] Waiting 500ms before next try
2024/03/28 15:18:38 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:18:38 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:18:48 [TRACE] Waiting 1s before next try
2024/03/28 15:18:49 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:18:49 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:18:59 [TRACE] Waiting 2s before next try
2024/03/28 15:19:01 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:19:02 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:19:12 [TRACE] Waiting 4s before next try
2024/03/28 15:19:16 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:19:16 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:19:26 [TRACE] Waiting 8s before next try
2024/03/28 15:19:34 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:19:34 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:19:44 [TRACE] Waiting 10s before next try
2024/03/28 15:19:54 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:19:54 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:20:04 [TRACE] Waiting 10s before next try
2024/03/28 15:20:14 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:20:14 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:20:24 [TRACE] Waiting 10s before next try
2024/03/28 15:20:28 [WARN] WaitForState timeout after 2m0s
2024/03/28 15:20:28 [WARN] WaitForState starting 30s refresh grace period
2024/03/28 15:20:28 [DEBUG] Waiting for state to become: [success]
2024/03/28 15:20:28 [DEBUG] POST https://grafana.com/api/instances
2024/03/28 15:20:28 [DEBUG] GET https://grafana.com/api/instances/tomtom
2024/03/28 15:20:38 [TRACE] Waiting 500ms before next try

How do I configure it correctly?

julienduchesne commented 5 months ago

I added an example here: https://github.com/grafana/crossplane-provider-grafana/blob/main/examples/oss.yaml