1. Packages
  2. Grafana Cloud
  3. API Docs
  4. alerting
  5. alerting/v0alpha1
  6. RecordingRule
Viewing docs for Grafana v2.24.0
published on Friday, Apr 10, 2026 by pulumiverse
grafana logo
Viewing docs for Grafana v2.24.0
published on Friday, Apr 10, 2026 by pulumiverse

    Manages Grafana Recording Rules.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as grafana from "@pulumiverse/grafana";
    
    const recordingruleFolder = new grafana.oss.Folder("recordingrule_folder", {title: "Alert Rule Folder"});
    const example = new grafana.alerting.v0alpha1.RecordingRule("example", {
        metadata: {
            uid: "example-recording-rule",
            folderUid: recordingruleFolder.uid,
        },
        spec: {
            title: "Example Recording Rule",
            trigger: {
                interval: "1m",
            },
            paused: true,
            expressions: {
                A: JSON.stringify({
                    model: {
                        editorMode: "code",
                        expr: "count(up{})",
                        instant: true,
                        intervalMs: 1000,
                        legendFormat: "__auto",
                        maxDataPoints: 43200,
                        range: false,
                        refId: "A",
                    },
                    datasource_uid: "ds_uid",
                    relative_time_range: {
                        from: "600s",
                        to: "0s",
                    },
                    query_type: "",
                    source: true,
                }),
            },
            targetDatasourceUid: "target_ds_uid",
            metric: "tf-metric",
            labels: {
                foo: "bar",
            },
        },
    });
    
    import pulumi
    import json
    import pulumiverse_grafana as grafana
    
    recordingrule_folder = grafana.oss.Folder("recordingrule_folder", title="Alert Rule Folder")
    example = grafana.alerting.v0alpha1.RecordingRule("example",
        metadata={
            "uid": "example-recording-rule",
            "folder_uid": recordingrule_folder.uid,
        },
        spec={
            "title": "Example Recording Rule",
            "trigger": {
                "interval": "1m",
            },
            "paused": True,
            "expressions": {
                "A": json.dumps({
                    "model": {
                        "editorMode": "code",
                        "expr": "count(up{})",
                        "instant": True,
                        "intervalMs": 1000,
                        "legendFormat": "__auto",
                        "maxDataPoints": 43200,
                        "range": False,
                        "refId": "A",
                    },
                    "datasource_uid": "ds_uid",
                    "relative_time_range": {
                        "from": "600s",
                        "to": "0s",
                    },
                    "query_type": "",
                    "source": True,
                }),
            },
            "target_datasource_uid": "target_ds_uid",
            "metric": "tf-metric",
            "labels": {
                "foo": "bar",
            },
        })
    
    package main
    
    import (
    	"encoding/json"
    
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumiverse/pulumi-grafana/sdk/v2/go/grafana/alerting"
    	alertingv0alpha1 "github.com/pulumiverse/pulumi-grafana/sdk/v2/go/grafana/alerting/v0alpha1"
    	"github.com/pulumiverse/pulumi-grafana/sdk/v2/go/grafana/oss"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		recordingruleFolder, err := oss.NewFolder(ctx, "recordingrule_folder", &oss.FolderArgs{
    			Title: pulumi.String("Alert Rule Folder"),
    		})
    		if err != nil {
    			return err
    		}
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"model": map[string]interface{}{
    				"editorMode":    "code",
    				"expr":          "count(up{})",
    				"instant":       true,
    				"intervalMs":    1000,
    				"legendFormat":  "__auto",
    				"maxDataPoints": 43200,
    				"range":         false,
    				"refId":         "A",
    			},
    			"datasource_uid": "ds_uid",
    			"relative_time_range": map[string]interface{}{
    				"from": "600s",
    				"to":   "0s",
    			},
    			"query_type": "",
    			"source":     true,
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		_, err = alerting.NewRecordingRule(ctx, "example", &alerting.RecordingRuleArgs{
    			Metadata: &alertingv0alpha1.RecordingRuleMetadataArgs{
    				Uid:       pulumi.String("example-recording-rule"),
    				FolderUid: recordingruleFolder.Uid,
    			},
    			Spec: &alertingv0alpha1.RecordingRuleSpecArgs{
    				Title: pulumi.String("Example Recording Rule"),
    				Trigger: &alertingv0alpha1.RecordingRuleSpecTriggerArgs{
    					Interval: pulumi.String("1m"),
    				},
    				Paused: pulumi.Bool(true),
    				Expressions: pulumi.StringMap{
    					"A": pulumi.String(pulumi.String(json0)),
    				},
    				TargetDatasourceUid: pulumi.String("target_ds_uid"),
    				Metric:              pulumi.String("tf-metric"),
    				Labels: pulumi.StringMap{
    					"foo": pulumi.String("bar"),
    				},
    			},
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using Grafana = Pulumiverse.Grafana;
    
    return await Deployment.RunAsync(() => 
    {
        var recordingruleFolder = new Grafana.Oss.Folder("recordingrule_folder", new()
        {
            Title = "Alert Rule Folder",
        });
    
        var example = new Grafana.Alerting.V0Alpha1.RecordingRule("example", new()
        {
            Metadata = new Grafana.Alerting.V0Alpha1.Inputs.RecordingRuleMetadataArgs
            {
                Uid = "example-recording-rule",
                FolderUid = recordingruleFolder.Uid,
            },
            Spec = new Grafana.Alerting.V0Alpha1.Inputs.RecordingRuleSpecArgs
            {
                Title = "Example Recording Rule",
                Trigger = new Grafana.Alerting.V0Alpha1.Inputs.RecordingRuleSpecTriggerArgs
                {
                    Interval = "1m",
                },
                Paused = true,
                Expressions = 
                {
                    { "A", JsonSerializer.Serialize(new Dictionary<string, object?>
                    {
                        ["model"] = new Dictionary<string, object?>
                        {
                            ["editorMode"] = "code",
                            ["expr"] = "count(up{})",
                            ["instant"] = true,
                            ["intervalMs"] = 1000,
                            ["legendFormat"] = "__auto",
                            ["maxDataPoints"] = 43200,
                            ["range"] = false,
                            ["refId"] = "A",
                        },
                        ["datasource_uid"] = "ds_uid",
                        ["relative_time_range"] = new Dictionary<string, object?>
                        {
                            ["from"] = "600s",
                            ["to"] = "0s",
                        },
                        ["query_type"] = "",
                        ["source"] = true,
                    }) },
                },
                TargetDatasourceUid = "target_ds_uid",
                Metric = "tf-metric",
                Labels = 
                {
                    { "foo", "bar" },
                },
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.grafana.oss.Folder;
    import com.pulumi.grafana.oss.FolderArgs;
    import com.pulumi.grafana.alerting_v0alpha1.RecordingRule;
    import com.pulumi.grafana.alerting_v0alpha1.RecordingRuleArgs;
    import com.pulumi.grafana.alerting.inputs.RecordingRuleMetadataArgs;
    import com.pulumi.grafana.alerting.inputs.RecordingRuleSpecArgs;
    import com.pulumi.grafana.alerting.inputs.RecordingRuleSpecTriggerArgs;
    import static com.pulumi.codegen.internal.Serialization.*;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var recordingruleFolder = new Folder("recordingruleFolder", FolderArgs.builder()
                .title("Alert Rule Folder")
                .build());
    
            var example = new RecordingRule("example", RecordingRuleArgs.builder()
                .metadata(RecordingRuleMetadataArgs.builder()
                    .uid("example-recording-rule")
                    .folderUid(recordingruleFolder.uid())
                    .build())
                .spec(RecordingRuleSpecArgs.builder()
                    .title("Example Recording Rule")
                    .trigger(RecordingRuleSpecTriggerArgs.builder()
                        .interval("1m")
                        .build())
                    .paused(true)
                    .expressions(Map.of("A", serializeJson(
                        jsonObject(
                            jsonProperty("model", jsonObject(
                                jsonProperty("editorMode", "code"),
                                jsonProperty("expr", "count(up{})"),
                                jsonProperty("instant", true),
                                jsonProperty("intervalMs", 1000),
                                jsonProperty("legendFormat", "__auto"),
                                jsonProperty("maxDataPoints", 43200),
                                jsonProperty("range", false),
                                jsonProperty("refId", "A")
                            )),
                            jsonProperty("datasource_uid", "ds_uid"),
                            jsonProperty("relative_time_range", jsonObject(
                                jsonProperty("from", "600s"),
                                jsonProperty("to", "0s")
                            )),
                            jsonProperty("query_type", ""),
                            jsonProperty("source", true)
                        ))))
                    .targetDatasourceUid("target_ds_uid")
                    .metric("tf-metric")
                    .labels(Map.of("foo", "bar"))
                    .build())
                .build());
    
        }
    }
    
    resources:
      recordingruleFolder:
        type: grafana:oss:Folder
        name: recordingrule_folder
        properties:
          title: Alert Rule Folder
      example:
        type: grafana:alerting/v0alpha1:RecordingRule
        properties:
          metadata:
            uid: example-recording-rule
            folderUid: ${recordingruleFolder.uid}
          spec:
            title: Example Recording Rule
            trigger:
              interval: 1m
            paused: true
            expressions:
              A:
                fn::toJSON:
                  model:
                    editorMode: code
                    expr: count(up{})
                    instant: true
                    intervalMs: 1000
                    legendFormat: __auto
                    maxDataPoints: 43200
                    range: false
                    refId: A
                  datasource_uid: ds_uid
                  relative_time_range:
                    from: 600s
                    to: 0s
                  query_type: ""
                  source: true
            targetDatasourceUid: target_ds_uid
            metric: tf-metric
            labels:
              foo: bar
    

    Create RecordingRule Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new RecordingRule(name: string, args?: RecordingRuleArgs, opts?: CustomResourceOptions);
    @overload
    def RecordingRule(resource_name: str,
                      args: Optional[RecordingRuleArgs] = None,
                      opts: Optional[ResourceOptions] = None)
    
    @overload
    def RecordingRule(resource_name: str,
                      opts: Optional[ResourceOptions] = None,
                      metadata: Optional[RecordingRuleMetadataArgs] = None,
                      options: Optional[RecordingRuleOptionsArgs] = None,
                      spec: Optional[RecordingRuleSpecArgs] = None)
    func NewRecordingRule(ctx *Context, name string, args *RecordingRuleArgs, opts ...ResourceOption) (*RecordingRule, error)
    public RecordingRule(string name, RecordingRuleArgs? args = null, CustomResourceOptions? opts = null)
    public RecordingRule(String name, RecordingRuleArgs args)
    public RecordingRule(String name, RecordingRuleArgs args, CustomResourceOptions options)
    
    type: grafana:alerting/v0alpha1/recordingRule:RecordingRule
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args RecordingRuleArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args RecordingRuleArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args RecordingRuleArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args RecordingRuleArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args RecordingRuleArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    RecordingRule Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The RecordingRule resource accepts the following input properties:

    Metadata RecordingRuleMetadataArgs
    The metadata of the resource.
    Options RecordingRuleOptionsArgs
    Options for applying the resource.
    Spec RecordingRuleSpecArgs
    The spec of the resource.
    metadata RecordingRuleMetadata
    The metadata of the resource.
    options RecordingRuleOptions
    Options for applying the resource.
    spec RecordingRuleSpec
    The spec of the resource.
    metadata RecordingRuleMetadata
    The metadata of the resource.
    options RecordingRuleOptions
    Options for applying the resource.
    spec RecordingRuleSpec
    The spec of the resource.
    metadata RecordingRuleMetadataArgs
    The metadata of the resource.
    options RecordingRuleOptionsArgs
    Options for applying the resource.
    spec RecordingRuleSpecArgs
    The spec of the resource.
    metadata Property Map
    The metadata of the resource.
    options Property Map
    Options for applying the resource.
    spec Property Map
    The spec of the resource.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the RecordingRule resource produces the following output properties:

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing RecordingRule Resource

    Get an existing RecordingRule resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: RecordingRuleState, opts?: CustomResourceOptions): RecordingRule
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            metadata: Optional[RecordingRuleMetadataArgs] = None,
            options: Optional[RecordingRuleOptionsArgs] = None,
            spec: Optional[RecordingRuleSpecArgs] = None) -> RecordingRule
    func GetRecordingRule(ctx *Context, name string, id IDInput, state *RecordingRuleState, opts ...ResourceOption) (*RecordingRule, error)
    public static RecordingRule Get(string name, Input<string> id, RecordingRuleState? state, CustomResourceOptions? opts = null)
    public static RecordingRule get(String name, Output<String> id, RecordingRuleState state, CustomResourceOptions options)
    resources:  _:    type: grafana:alerting/v0alpha1/recordingRule:RecordingRule    get:      id: ${id}
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Metadata RecordingRuleMetadataArgs
    The metadata of the resource.
    Options RecordingRuleOptionsArgs
    Options for applying the resource.
    Spec RecordingRuleSpecArgs
    The spec of the resource.
    metadata RecordingRuleMetadata
    The metadata of the resource.
    options RecordingRuleOptions
    Options for applying the resource.
    spec RecordingRuleSpec
    The spec of the resource.
    metadata RecordingRuleMetadata
    The metadata of the resource.
    options RecordingRuleOptions
    Options for applying the resource.
    spec RecordingRuleSpec
    The spec of the resource.
    metadata RecordingRuleMetadataArgs
    The metadata of the resource.
    options RecordingRuleOptionsArgs
    Options for applying the resource.
    spec RecordingRuleSpecArgs
    The spec of the resource.
    metadata Property Map
    The metadata of the resource.
    options Property Map
    Options for applying the resource.
    spec Property Map
    The spec of the resource.

    Supporting Types

    RecordingRuleMetadata, RecordingRuleMetadataArgs

    Uid string
    The unique identifier of the resource.
    Annotations Dictionary<string, string>
    Annotations of the resource.
    FolderUid string
    The UID of the folder to save the resource in.
    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.
    Uid string
    The unique identifier of the resource.
    Annotations map[string]string
    Annotations of the resource.
    FolderUid string
    The UID of the folder to save the resource in.
    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.
    uid String
    The unique identifier of the resource.
    annotations Map<String,String>
    Annotations of the resource.
    folderUid String
    The UID of the folder to save the resource in.
    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.
    uid string
    The unique identifier of the resource.
    annotations {[key: string]: string}
    Annotations of the resource.
    folderUid string
    The UID of the folder to save the resource in.
    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.
    uid str
    The unique identifier of the resource.
    annotations Mapping[str, str]
    Annotations of the resource.
    folder_uid str
    The UID of the folder to save the resource in.
    url str
    The full URL of the resource.
    uuid str
    The globally unique identifier of a resource, used by the API for tracking.
    version str
    The version of the resource.
    uid String
    The unique identifier of the resource.
    annotations Map<String>
    Annotations of the resource.
    folderUid String
    The UID of the folder to save the resource in.
    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.

    RecordingRuleOptions, RecordingRuleOptionsArgs

    Overwrite bool
    Set to true if you want to overwrite existing resource with newer version, same resource title in folder or same resource uid.
    Overwrite bool
    Set to true if you want to overwrite existing resource with newer version, same resource title in folder or same resource uid.
    overwrite Boolean
    Set to true if you want to overwrite existing resource with newer version, same resource title in folder or same resource uid.
    overwrite boolean
    Set to true if you want to overwrite existing resource with newer version, same resource title in folder or same resource uid.
    overwrite bool
    Set to true if you want to overwrite existing resource with newer version, same resource title in folder or same resource uid.
    overwrite Boolean
    Set to true if you want to overwrite existing resource with newer version, same resource title in folder or same resource uid.

    RecordingRuleSpec, RecordingRuleSpecArgs

    Expressions Dictionary<string, string>
    A sequence of stages that describe the contents of the rule. Each value is a JSON string representing an expression object.
    Metric string
    The name of the metric to write to.
    TargetDatasourceUid string
    The UID of the datasource to write the metric to.
    Title string
    The title of the recording rule.
    Labels Dictionary<string, string>
    Key-value pairs to attach to the recorded metric.
    Paused bool
    Sets whether the recording rule should be paused or not.
    Trigger Pulumiverse.Grafana.Alerting.V0Alpha1.Inputs.RecordingRuleSpecTrigger
    The trigger configuration for the recording rule.
    Expressions map[string]string
    A sequence of stages that describe the contents of the rule. Each value is a JSON string representing an expression object.
    Metric string
    The name of the metric to write to.
    TargetDatasourceUid string
    The UID of the datasource to write the metric to.
    Title string
    The title of the recording rule.
    Labels map[string]string
    Key-value pairs to attach to the recorded metric.
    Paused bool
    Sets whether the recording rule should be paused or not.
    Trigger RecordingRuleSpecTrigger
    The trigger configuration for the recording rule.
    expressions Map<String,String>
    A sequence of stages that describe the contents of the rule. Each value is a JSON string representing an expression object.
    metric String
    The name of the metric to write to.
    targetDatasourceUid String
    The UID of the datasource to write the metric to.
    title String
    The title of the recording rule.
    labels Map<String,String>
    Key-value pairs to attach to the recorded metric.
    paused Boolean
    Sets whether the recording rule should be paused or not.
    trigger RecordingRuleSpecTrigger
    The trigger configuration for the recording rule.
    expressions {[key: string]: string}
    A sequence of stages that describe the contents of the rule. Each value is a JSON string representing an expression object.
    metric string
    The name of the metric to write to.
    targetDatasourceUid string
    The UID of the datasource to write the metric to.
    title string
    The title of the recording rule.
    labels {[key: string]: string}
    Key-value pairs to attach to the recorded metric.
    paused boolean
    Sets whether the recording rule should be paused or not.
    trigger RecordingRuleSpecTrigger
    The trigger configuration for the recording rule.
    expressions Mapping[str, str]
    A sequence of stages that describe the contents of the rule. Each value is a JSON string representing an expression object.
    metric str
    The name of the metric to write to.
    target_datasource_uid str
    The UID of the datasource to write the metric to.
    title str
    The title of the recording rule.
    labels Mapping[str, str]
    Key-value pairs to attach to the recorded metric.
    paused bool
    Sets whether the recording rule should be paused or not.
    trigger RecordingRuleSpecTrigger
    The trigger configuration for the recording rule.
    expressions Map<String>
    A sequence of stages that describe the contents of the rule. Each value is a JSON string representing an expression object.
    metric String
    The name of the metric to write to.
    targetDatasourceUid String
    The UID of the datasource to write the metric to.
    title String
    The title of the recording rule.
    labels Map<String>
    Key-value pairs to attach to the recorded metric.
    paused Boolean
    Sets whether the recording rule should be paused or not.
    trigger Property Map
    The trigger configuration for the recording rule.

    RecordingRuleSpecTrigger, RecordingRuleSpecTriggerArgs

    Interval string
    The interval at which the recording rule should be evaluated.
    Interval string
    The interval at which the recording rule should be evaluated.
    interval String
    The interval at which the recording rule should be evaluated.
    interval string
    The interval at which the recording rule should be evaluated.
    interval str
    The interval at which the recording rule should be evaluated.
    interval String
    The interval at which the recording rule should be evaluated.

    Package Details

    Repository
    grafana pulumiverse/pulumi-grafana
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the grafana Terraform Provider.
    grafana logo
    Viewing docs for Grafana v2.24.0
    published on Friday, Apr 10, 2026 by pulumiverse
      Try Pulumi Cloud free. Your team will thank you.