Terraform Deploy Cloud Stack Service Account

Hi guys, I am trying to deploy a service account to our grafana cloud stack, however it seems like there is an issue with the terraform provider right now - or maybe I am doing something wrong…

  • What Grafana version and what operating system are you using?
    Grafana Cloud Stack

  • What are you trying to achieve?
    Deploy a Cloud Stack Service Account via Terraform Provider

  • How are you trying to achieve it?
    Using Terraform Grafana Provider Version 2.12.2

  • What happened?

Using following Code

Set ENV vars:


Using Terraform Provider 2.12.2
provider "grafana" {
  cloud_api_url = "https://****.grafana.net/"

resource "grafana_cloud_stack_service_account" "cloud_sa" {
  stack_slug  = "****"
  name        = "github service account"
  role        = "Admin"
  is_disabled = false

resource "grafana_cloud_stack_service_account_token" "github" {
  name               = "github_key"
  stack_slug         = "****"
  service_account_id = grafana_cloud_stack_service_account.cloud_sa.id

  • What did you expect to happen?
    Service Accounts gets deployed in cloud stack

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

│ Error: 404 Not Found
│   with grafana_cloud_stack_service_account.cloud_sa,
│   on grafana.tf line 5, in resource "grafana_cloud_stack_service_account" "cloud_sa":
│    5: resource "grafana_cloud_stack_service_account" "cloud_sa" {

Terraform Debug Output:

2024-02-29T12:09:56.266+0100 [ERROR] provider.terraform-provider-grafana_v2.12.2: Response contains error diagnostic: diagnostic_summary="404 Not Found" tf_provider_addr=registry.terraform.io/grafana/grafana @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/diag/diagnostics.go:62 diagnostic_detail="" diagnostic_severity=ERROR tf_proto_version=5.4 tf_req_id=3e72fb93-6778-3679-d392-3644bf4e7ee5 tf_resource_type=grafana_cloud_stack_service_account tf_rpc=ApplyResourceChange @module=sdk.proto timestamp="2024-02-29T12:09:56.266+0100"
2024-02-29T12:09:56.267+0100 [DEBUG] State storage *cloud.State declined to persist a state snapshot
2024-02-29T12:09:56.267+0100 [ERROR] vertex "grafana_cloud_stack_service_account.cloud_sa" error: 404 Not Found
2024-02-29T12:09:56.267+0100 [DEBUG] cloud/state: state read serial is: 8; serial is: 8
2024-02-29T12:09:56.267+0100 [DEBUG] cloud/state: state read lineage is: 6f5c1b36-eb43-9e38-e789-ba14c23eb394; lineage is: 6f5c1b36-eb43-9e38-e789-ba14c23eb394

I think you need cloud_api_key only:

provider "grafana" {
  alias         = "cloud"
  cloud_api_key = "my-token"

Documentation says its deprecated and I should use cloud_access_policy_token

  • cloud_api_key (String, Sensitive, Deprecated) Deprecated: Use cloud_access_policy_token instead

Correct, also doc is not saying that you need any URL, so try to use just cloud_access_policy_token or cloud_api_key, nothing else.