<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Service accounts on Grafana Labs</title><link>https://grafana.com/docs/grafana/v12.4/administration/service-accounts/</link><description>Recent content in Service accounts on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v12.4/administration/service-accounts/index.xml" rel="self" type="application/rss+xml"/><item><title>Migrate API keys to service account tokens</title><link>https://grafana.com/docs/grafana/v12.4/administration/service-accounts/migrate-api-keys/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/administration/service-accounts/migrate-api-keys/</guid><content><![CDATA[&lt;h1 id=&#34;migrate-api-keys-to-service-account-tokens&#34;&gt;Migrate API keys to service account tokens&lt;/h1&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;API keys are deprecated. 
    &lt;a href=&#34;/docs/grafana/v12.4/administration/service-accounts/&#34;&gt;Service accounts&lt;/a&gt; now replace API keys for authenticating with the &lt;strong&gt;HTTP APIs&lt;/strong&gt; and interacting with Grafana.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;API keys specify a role—either &lt;strong&gt;Admin&lt;/strong&gt;, &lt;strong&gt;Editor&lt;/strong&gt;, or &lt;strong&gt;Viewer&lt;/strong&gt;—that determine the permissions associated with interacting with Grafana.&lt;/p&gt;
&lt;p&gt;Compared to API keys, service accounts have limited scopes that provide more security. For more information on the benefits of service accounts, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/administration/service-accounts/#service-account-benefits&#34;&gt;service account benefits&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;When you migrate an API key to a service account, a service account is created with a service account token. Your existing API key—now migrated to a service account token—will continue working as before.&lt;/p&gt;
&lt;p&gt;To find the migrated API keys, click &lt;strong&gt;Administration&lt;/strong&gt; in the left-side menu, then &lt;strong&gt;Users and access -&amp;gt; Service Accounts&lt;/strong&gt;, select the service account, and locate the &lt;strong&gt;Token&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&#34;migrate-api-keys-using-the-grafana-user-interface&#34;&gt;Migrate API keys using the Grafana user interface&lt;/h2&gt;
&lt;p&gt;This section shows you how to migrate API keys to Grafana service accounts using the Grafana user interface. You can choose to migrate a single API key or all API keys. When you migrate all API keys, you can no longer create API keys and must use service accounts instead.&lt;/p&gt;
&lt;h4 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h4&gt;
&lt;p&gt;To follow these instructions, you need at least one of the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Administrator permissions&lt;/li&gt;
&lt;li&gt;Editor permissions&lt;/li&gt;
&lt;li&gt;Service account writer&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information about permissions, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/administration/roles-and-permissions/&#34;&gt;Roles and permissions&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;steps&#34;&gt;Steps&lt;/h4&gt;
&lt;p&gt;To migrate all API keys to service accounts, complete the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Sign in to Grafana, point to &lt;strong&gt;Administration&lt;/strong&gt;, &lt;strong&gt;Users and access&lt;/strong&gt;, and click &lt;strong&gt;API Keys&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;In the top of the page, find the section which says &lt;strong&gt;Switch from API keys to service accounts&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Migrate to service accounts now&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;A confirmation window will appear, asking to confirm the migration. Click &lt;strong&gt;Yes, migrate now&lt;/strong&gt; if you are willing to continue.&lt;/li&gt;
&lt;li&gt;Once migration is successful, you can choose to forever hide the API keys page. Click &lt;strong&gt;Hide API keys page forever&lt;/strong&gt; if you want to do that.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;To migrate a single API key to a service account, complete the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Sign in to Grafana.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Administration&lt;/strong&gt; in the left-side menu, &lt;strong&gt;Users and access&lt;/strong&gt;, and select &lt;strong&gt;API Keys&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Find the API Key you want to migrate.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Migrate to service account&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;migrate-api-keys-using-the-http-api&#34;&gt;Migrate API keys using the HTTP API&lt;/h2&gt;
&lt;p&gt;This section shows you how to programmatically migrate API keys to Grafana service accounts using the HTTP API. For API additional information, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/developers/http_api/serviceaccount/&#34;&gt;Service account HTTP APIs&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;before-you-begin-1&#34;&gt;Before you begin&lt;/h4&gt;
&lt;p&gt;To follow these instructions, you need one of the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Administrator permissions&lt;/li&gt;
&lt;li&gt;Editor permissions&lt;/li&gt;
&lt;li&gt;Service account writer&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;steps-1&#34;&gt;Steps&lt;/h4&gt;
&lt;p&gt;Complete the following steps to migrate from API keys to service accounts for API:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Call the &lt;code&gt;POST /api/serviceaccounts&lt;/code&gt; endpoint and the &lt;code&gt;POST /api/serviceaccounts/&amp;lt;id&amp;gt;/tokens&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This action generates a service account token.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Store the ID and secret that the system returns to you.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Pass the token in the &lt;code&gt;Authorization&lt;/code&gt; header, prefixed with &lt;code&gt;Bearer&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This action authenticates API requests.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SATs used for authentication&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Remove code that handles the old &lt;code&gt;/api/auth/keys&lt;/code&gt; endpoint.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Track the &lt;a href=&#34;http://localhost:3000/org/apikeys&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;API keys&lt;/a&gt; in use and migrate them to SATs.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;example&#34;&gt;Example&lt;/h4&gt;
&lt;p&gt;Your current setup&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;sh&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sh&#34;&gt;curl -X POST -H &amp;#34;Content-Type: application/json&amp;#34; -d &amp;#39;{&amp;#34;name&amp;#34;: &amp;#34;my-api-key&amp;#34;, &amp;#34;role&amp;#34;: &amp;#34;Viewer&amp;#34;}&amp;#39; http://admin:admin@localhost:3000/api/auth/keys

# response from the api
{&amp;#34;id&amp;#34;:2,&amp;#34;name&amp;#34;:&amp;#34;my-api-key&amp;#34;,&amp;#34;key&amp;#34;:&amp;#34;eyJrIjoiTFRSN1RBOVc3SGhjblc0bWZodXZ3MnNDcU92Um5VZUIiLKJuIjoibXktYXBpLWtleSIsImlkIjoxfQ==&amp;#34;}%&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;New setup&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;sh&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sh&#34;&gt;# create a service account
curl -X POST -H &amp;#34;Content-Type: application/json&amp;#34; -d &amp;#39;{&amp;#34;name&amp;#34;: &amp;#34;my-service-account&amp;#34;, &amp;#34;role&amp;#34;: &amp;#34;Viewer&amp;#34;}&amp;#39; http://admin:admin@localhost:3000/api/serviceaccounts

# response with the created service account id,name, login
{&amp;#34;id&amp;#34;:1,&amp;#34;name&amp;#34;:&amp;#34;my-service-account&amp;#34;,&amp;#34;login&amp;#34;:&amp;#34;sa-my-service-account&amp;#34;,&amp;#34;orgId&amp;#34;:1,&amp;#34;isDisabled&amp;#34;:false,&amp;#34;role&amp;#34;:&amp;#34;Viewer&amp;#34;,&amp;#34;tokens&amp;#34;:0,&amp;#34;avatarUrl&amp;#34;:&amp;#34;&amp;#34;}%

# create the service account token with the service account id 1 - /serviceaccounts/{id} returned from the previous step
curl -X POST -H &amp;#34;Content-Type: application/json&amp;#34; -d &amp;#39;{&amp;#34;name&amp;#34;: &amp;#34;my-service-account-token&amp;#34;}&amp;#39; http://admin:admin@localhost:3000/api/serviceaccounts/1/tokens

# response with the created SAT id,name and key.
{&amp;#34;id&amp;#34;:2,&amp;#34;name&amp;#34;:&amp;#34;my-service-account-token&amp;#34;,&amp;#34;key&amp;#34;:&amp;#34;glsa_iNValIdinValiDinvalidinvalidinva_5b582697&amp;#34;}%

# now you can authenticate the same way as you did with the API key
curl --request GET --url http://localhost:3000/api/folders --header &amp;#39;Authorization: Bearer glsa_iNValIdinValiDinvalidinvalidinva_5b582697&amp;#39;

# response
[{&amp;#34;id&amp;#34;:1,&amp;#34;uid&amp;#34;:&amp;#34;a5261a84-eebc-4733-83a9-61f4713561d1&amp;#34;,&amp;#34;title&amp;#34;:&amp;#34;gdev dashboards&amp;#34;}]%&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;migrate-api-keys-using-terraform&#34;&gt;Migrate API keys using Terraform&lt;/h2&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The terraform resource &lt;code&gt;api_key&lt;/code&gt; is removed from the Grafana Terraform Provider in v3.0.0.
Before you migrate and remove the use of the resource, you should pin your terraform version to a version less-than or equal-to v2.19.0.
For more information, refer to the &lt;a href=&#34;https://github.com/grafana/terraform-provider-grafana/releases/tag/v3.0.0&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Terraform Provider release notes&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;To pin the Grafana Terraform Provider to v2.19.0:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;hcl&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;terraform {
  required_providers {
    grafana = {
      source  = &amp;#34;grafana/grafana&amp;#34;
      version = &amp;#34;2.19.0&amp;#34;
    }
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This section shows you how to migrate your Terraform configuration for API keys to Grafana service accounts. For additional information, refer to &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/service_account_token&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Service Accounts in Terraform&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;steps-2&#34;&gt;Steps&lt;/h4&gt;
&lt;p&gt;Complete the following steps to migrate from API keys to service accounts using Terraform:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Generate &lt;code&gt;grafana_service_account&lt;/code&gt; and &lt;code&gt;grafana_service_account_token&lt;/code&gt; resources.&lt;/li&gt;
&lt;li&gt;Specify the desired scopes and expiration date when creating the service account.&lt;/li&gt;
&lt;li&gt;Use the token returned from &lt;code&gt;grafana_service_account_token&lt;/code&gt; to authenticate the API requests.&lt;/li&gt;
&lt;li&gt;Remove the terraform configuration for creating your &lt;code&gt;grafana_api_key&lt;/code&gt; resources.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Example: your current Terraform configuration&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;tf&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-tf&#34;&gt;terraform {
  required_providers {
    grafana = {
      source  = &amp;#34;grafana/grafana&amp;#34;
    }
  }
}

# configure the provider with basic auth
provider &amp;#34;grafana&amp;#34; {
  url  = &amp;#34;http://localhost:3000&amp;#34;
  auth = &amp;#34;admin:admin&amp;#34;
}

resource &amp;#34;grafana_api_key&amp;#34; &amp;#34;foo&amp;#34; {
  name = &amp;#34;key_foo&amp;#34;
  role = &amp;#34;Viewer&amp;#34;
}

resource &amp;#34;grafana_api_key&amp;#34; &amp;#34;bar&amp;#34; {
  name            = &amp;#34;key_bar&amp;#34;
  role            = &amp;#34;Admin&amp;#34;
  seconds_to_live = 30
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Your new Terraform configuration&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; you can create multiple tokens using one service account.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;tf&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-tf&#34;&gt;terraform {
  required_providers {
    grafana = {
      source  = &amp;#34;grafana/grafana&amp;#34;
    }
  }
}

# configure the provider with basic auth
provider &amp;#34;grafana&amp;#34; {
  url  = &amp;#34;http://localhost:3000&amp;#34;
  auth = &amp;#34;admin:admin&amp;#34;
}

# Creating a service account in Grafana instance to be used as auth and attach tokens
# notice we can attach multiple tokens to one service account
resource &amp;#34;grafana_service_account&amp;#34; &amp;#34;sa-admin&amp;#34; {
  name             = &amp;#34;sa-admin&amp;#34;
  role             = &amp;#34;Admin&amp;#34;
}

# Creating a service account token in Grafana instance to be used for creating resources in Grafana instance
resource &amp;#34;grafana_service_account_token&amp;#34; &amp;#34;sat-bar&amp;#34; {
  name           = &amp;#34;sat-bar&amp;#34;
  service_account_id = grafana_service_account.sa-admin.id
}

# Creating a service account token in Grafana instance to be used for creating resources in Grafana instance
resource &amp;#34;grafana_service_account_token&amp;#34; &amp;#34;sat-foo&amp;#34; {
  name           = &amp;#34;sat-foo&amp;#34;
  service_account_id = grafana_service_account.sa-admin.id
  seconds_to_live    = 30
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;migrate-cloud-stack-api-keys-using-terraform&#34;&gt;Migrate Cloud Stack API keys using Terraform&lt;/h2&gt;
&lt;p&gt;This section shows you how to migrate your Terraform configuration for Grafana cloud stack API keys to Grafana cloud stack service accounts.&lt;/p&gt;
&lt;p&gt;For migration your cloud stack api keys, use the &lt;code&gt;grafana_cloud_stack_service_account&lt;/code&gt; and &lt;code&gt;gafana_cloud_stack_service_account_token&lt;/code&gt; resources. For additional information, refer to &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/cloud_stack_service_account&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Cloud Stack Service Accounts in Terraform&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This is only relevant for Grafana Cloud &lt;strong&gt;Stack&lt;/strong&gt; API keys &lt;code&gt;grafana_cloud_stack_api_key&lt;/code&gt;. Grafana Cloud API keys resource &lt;code&gt;grafana_cloud_api_key&lt;/code&gt; are not deprecated and should be used for authentication for managing your Grafana cloud.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h4 id=&#34;steps-3&#34;&gt;Steps&lt;/h4&gt;
&lt;p&gt;Complete the following steps to migrate from cloud stack API keys to cloud stack service accounts using Terraform:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Generate &lt;code&gt;grafana_cloud_stack_service_account&lt;/code&gt; and &lt;code&gt;grafana_cloud_stack_service_account_token&lt;/code&gt; resources.&lt;/li&gt;
&lt;li&gt;Specify the desired scopes and expiration date when creating the service account.&lt;/li&gt;
&lt;li&gt;Use the token returned from &lt;code&gt;grafana_cloud_stack_service_account_token&lt;/code&gt; to authenticate the API requests.&lt;/li&gt;
&lt;li&gt;Remove the Terraform configuration for creating your &lt;code&gt;grafana_cloud_stack_api_key&lt;/code&gt; resources.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Example: Your current Terraform configuration&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;tf&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-tf&#34;&gt;terraform {
  required_providers {
    grafana = {
      source = &amp;#34;grafana/grafana&amp;#34;
    }
  }
}

# Declaring the first provider to be only used for creating the cloud-stack
provider &amp;#34;grafana&amp;#34; {
  alias = &amp;#34;cloud&amp;#34;

  cloud_api_key = &amp;#34;&amp;lt;API-Key&amp;gt;&amp;#34;
}

resource &amp;#34;grafana_cloud_stack&amp;#34; &amp;#34;my_stack&amp;#34; {
  provider = grafana.cloud

  name        = &amp;#34;my_stack&amp;#34;
  slug        = &amp;#34;my_stack&amp;#34;
  region_slug = &amp;#34;eu&amp;#34; # Example “us”,”eu” etc
}

# Creating a Grafana API key to be used as auth
resource &amp;#34;grafana_cloud_stack_api_key&amp;#34; &amp;#34;management&amp;#34; {
  provider = grafana.cloud

  stack_slug = grafana_cloud_stack.my_stack.slug
  name       = &amp;#34;management-key&amp;#34;
  role       = &amp;#34;Admin&amp;#34;
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Your new Terraform configuration&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;tf&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-tf&#34;&gt;terraform {
  required_providers {
    grafana = {
      source = &amp;#34;grafana/grafana&amp;#34;
    }
  }
}

# Declaring the first provider to be only used for creating the cloud-stack
provider &amp;#34;grafana&amp;#34; {
  alias = &amp;#34;cloud&amp;#34;

  cloud_api_key = &amp;#34;&amp;lt;API-Key&amp;gt;&amp;#34;
}

resource &amp;#34;grafana_cloud_stack&amp;#34; &amp;#34;my_stack&amp;#34; {
  provider = grafana.cloud

  name        = &amp;#34;my_stack&amp;#34;
  slug        = &amp;#34;my_stack&amp;#34;
  region_slug = &amp;#34;eu&amp;#34; # Example “us”,”eu” etc
}

# Creating a grafana cloud stack service account
resource &amp;#34;grafana_cloud_stack_service_account&amp;#34; &amp;#34;mystack_cloud-stack_service_account&amp;#34; {
  provider   = grafana.cloud
  stack_slug = grafana_cloud_stack.my_stack.slug

  name = &amp;#34;mystack-cloud-stack-sa&amp;#34;
  role = &amp;#34;Admin&amp;#34;
}

# Creating a grafana cloud stack service account token
resource &amp;#34;grafana_cloud_stack_service_account_token&amp;#34; &amp;#34;mystack_cloud-stack_service-account_token&amp;#34; {
  provider   = grafana.cloud
  stack_slug = grafana_cloud_stack.my_stack.slug

  name               = &amp;#34;mystack-cloud-stack-sa-token&amp;#34;
  service_account_id = grafana_cloud_stack_service_account.mystack_cloud-stack_service_account.id
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="migrate-api-keys-to-service-account-tokens">Migrate API keys to service account tokens&lt;/h1>
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>API keys are deprecated.
&lt;a href="/docs/grafana/v12.4/administration/service-accounts/">Service accounts&lt;/a> now replace API keys for authenticating with the &lt;strong>HTTP APIs&lt;/strong> and interacting with Grafana.&lt;/p></description></item></channel></rss>