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

ProviderRevision stuck #114

Closed josemrs closed 6 months ago

josemrs commented 6 months ago

I'm trying to get Crospplane working to help deploying dashboards and Rules. Stacks, tokens and other stuff will be handled by terraform

I deployed Crossplane, DeploymentRuntimeConfig and Provider. It was "working" fine at the beginning. I tried to create a dashboard when I found this issue:

Message: apply failed: the Grafana client is required forgrafana_dashboard. Set the auth and url provider attributes:

While I was messing around to get it working by adding GRAFANA_URL as env for the package-runtime container in the DeploymentRuntimeConfig I end up with:

Message: cannot establish control of object: accesspolicytokens.cloud.grafana.crossplane.io is already controlled by ProviderRevision provider-grafana-cloud-eaec2240d152 (UID 511249f2-fed9-4de1-b0e8-ddf36bf2424d)

It has happened a few other times and I totally removed as much Crossplane as I could and start from scratch. I does not seem to work this time and the error comes back as soon as I deploy the Provider.

What am I doing wrong or missing?

Following the resources I'm deploying:

apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
  name: grafana-cloud-drc
  namespace: crossplane
  labels:
        someLabels: EngOps
spec:
  deploymentTemplate:
    metadata:
      labels:
        someLabels: EngOps
    spec:
      selector: {}
      template:
        spec:
          containers:
            - name: package-runtime
              env:
                - name: GRAFANA_URL
                  value: https://<stackname>.grafana.net
        metadata:
          labels:
            someLabels: EngOps
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
  name: provider-grafana-cloud
  namespace: crossplane
spec:
  package: xpkg.upbound.io/grafana/provider-grafana:v0.12.0
  runtimeConfigRef:
    apiVersion: pkg.crossplane.io/v1beta1
    kind: DeploymentRuntimeConfig
    name: grafana-cloud-drc
apiVersion: v1
kind: Secret
metadata:
  name: grafana-cloud-creds
  namespace: crossplane
type: Opaque
stringData:
  credentials: |
    {
      "cloud_api_key": "REDACTED="
    }
apiVersion: grafana.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
  name: provider-grafana-cloud-pc
spec:
  credentials:
    source: Secret
    secretRef:
      name: grafana-cloud-creds
      namespace: crossplane
      key: credentials
apiVersion: cloud.grafana.crossplane.io/v1alpha1
kind: AccessPolicyToken
metadata:
  name: stack-token
spec:
  forProvider:
    accessPolicyId: REDACTED
    displayName: crossplane-created-token
    name: crossplane-created-token
    region: prod-us-east-0
  providerConfigRef:
    name: provider-grafana-cloud-pc
  writeConnectionSecretToRef:
    name: stack-token-secret
    namespace: crossplane
apiVersion: grafana.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
  name: provider-config
spec:
  credentials:
    source: Secret
    secretRef:
      name: stack-token-secret
      namespace: crossplane
      key: cloudCredentials

apiVersion: oss.grafana.crossplane.io/v1alpha1
kind: Folder
metadata:
  name: test-folder
  namespace: crossplane
spec:
  forProvider:
    title: 'Crossplane Folder Test'
  providerConfigRef:
    name:  provider-config
josemrs commented 6 months ago

It seems I managed to unlock myself. There was a accesspolicies.cloud.grafana.crossplane.io left over.

Also, I forgot to mention, the error was self-referencing provider-grafana-cloud-eaec2240d152 was in an event of the provider-grafana-cloud-eaec2240d152 resource itself.

julienduchesne commented 6 months ago

Access policies were bugged in the previous versions. Now fixed in the latest version. That might be why they were stuck. I'll consider this fixed but please do open a new issue if you encounter issues in the future!