--- # generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "grafana_apps_queries_query_v1 Resource - terraform-provider-grafana" subcategory: "Grafana Apps" description: |- Manages Grafana Saved Queries, also known as the Query Library, using the Grafana App Platform API (queries.grafana.app/v1). The datasource query stored in each target, the target's variable replacements, and a variable's value list definition are passed as raw JSON strings (use jsonencode()) because their shape depends on the datasource. Query Library documentation https://grafana.com/docs/grafana/latest/explore/query-management/ --- # grafana_apps_queries_query_v1 (Resource) Manages Grafana Saved Queries, also known as the Query Library, using the Grafana App Platform API (`queries.grafana.app/v1`). The datasource query stored in each target, the target's variable replacements, and a variable's value list definition are passed as raw JSON strings (use `jsonencode()`) because their shape depends on the datasource. * [Query Library documentation](https://grafana.com/docs/grafana/latest/explore/query-management/) ## Example Usage ```terraform resource "grafana_apps_queries_query_v1" "example" { metadata { uid = "example-saved-query" } spec { title = "Requests per second" description = "Prometheus rate of HTTP requests" is_visible = true tags = ["http", "prometheus"] targets { properties_json = jsonencode({ refId = "A" expr = "rate(http_requests_total[$__rate_interval])" datasource = { type = "prometheus" uid = "my-prometheus-uid" } }) } } } ``` ## Schema ### Optional - `metadata` (Block, Optional) The metadata of the resource. (see [below for nested schema](#nestedblock--metadata)) - `options` (Block, Optional) Options for applying the resource. (see [below for nested schema](#nestedblock--options)) - `spec` (Block, Optional) The spec of the resource. (see [below for nested schema](#nestedblock--spec)) ### Read-Only - `id` (String) The ID of the resource derived from UUID. ### Nested Schema for `metadata` Required: - `uid` (String) The unique identifier of the resource. Optional: - `folder_uid` (String) The UID of the folder to save the resource in. For example, it's supported for dashboards and folders. To know if it's supported for the specific resource you're using check the documentation. - `org_id` (Number) The Grafana organization ID this resource belongs to, for self-hosted OSS or Enterprise Grafana. When set, it overrides the provider's `org_id` for this resource only, so a single provider configuration can manage App Platform resources across multiple organizations. Not supported on Grafana Cloud (configure a stack with `stack_id` instead). Changing this value forces the resource to be recreated in the new organization. Read-Only: - `annotations` (Map of String) Annotations of the resource. - `url` (String) The full URL of the resource. - `uuid` (String) The globally unique identifier of a resource, used by the API for tracking. - `version` (String) The version of the resource. ### Nested Schema for `options` Optional: - `manager_identity` (String) Override the identity stamped on this resource's manager metadata. Defaults to "grafana-terraform-provider". Use this to distinguish resources managed by different Terraform workspaces targeting the same Grafana instance. - `overwrite` (Boolean) Set to true if you want to overwrite existing resource with newer version, same resource title in folder or same resource uid. ### Nested Schema for `spec` Required: - `title` (String) The display name of the saved query. Optional: - `description` (String) A longer description of the saved query. - `is_locked` (Boolean) Whether the saved query is locked and cannot be edited in the UI. This is purely for UI display purposes and not for security. - `is_visible` (Boolean) Whether the saved query is visible in the query library. - `tags` (Set of String) The tags used to filter the saved query. - `targets` (Block List) The query targets that make up the saved query. At least one target is required. (see [below for nested schema](#nestedblock--spec--targets)) - `vars` (Block List) The template variables that can be interpolated into the query targets. (see [below for nested schema](#nestedblock--spec--vars)) ### Nested Schema for `spec.targets` Required: - `properties_json` (String) The datasource query for the target, as a JSON string (use jsonencode()). Optional: - `data_type` (String) The returned Dataplane frame type for the target. - `variables_json` (String) The variable replacements to apply to the target, as a JSON string (use jsonencode()). ### Nested Schema for `spec.vars` Required: - `key` (String) The name of the variable. Optional: - `default_values` (List of String) The values used when no value is selected during render. - `value_list_definition_json` (String) The definition (as a JSON string) used by the frontend to fetch the list of selectable values. ## Import Import is supported using the following syntax: ```shell #!/bin/bash # Import an existing saved query by its UID terraform import grafana_apps_queries_query_v1.example example-saved-query ```