1. Packages
  2. Grafana Cloud
  3. API Docs
  4. getDataSource
Grafana v0.5.1 published on Wednesday, Jun 12, 2024 by pulumiverse

grafana.getDataSource

Explore with Pulumi AI

grafana logo
Grafana v0.5.1 published on Wednesday, Jun 12, 2024 by pulumiverse

    Get details about a Grafana Datasource querying by either name, uid or ID

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as grafana from "@pulumi/grafana";
    import * as grafana from "@pulumiverse/grafana";
    
    const prometheus = new grafana.DataSource("prometheus", {
        type: "prometheus",
        uid: "prometheus-ds-test-uid",
        url: "https://my-instance.com",
        basicAuthEnabled: true,
        basicAuthUsername: "username",
        jsonDataEncoded: JSON.stringify({
            httpMethod: "POST",
            prometheusType: "Mimir",
            prometheusVersion: "2.4.0",
        }),
        secureJsonDataEncoded: JSON.stringify({
            basicAuthPassword: "password",
        }),
    });
    const fromName = grafana.getDataSourceOutput({
        name: prometheus.name,
    });
    const fromId = grafana.getDataSourceOutput({
        id: prometheus.id,
    });
    const fromUid = grafana.getDataSourceOutput({
        uid: prometheus.uid,
    });
    
    import pulumi
    import json
    import pulumi_grafana as grafana
    import pulumiverse_grafana as grafana
    
    prometheus = grafana.DataSource("prometheus",
        type="prometheus",
        uid="prometheus-ds-test-uid",
        url="https://my-instance.com",
        basic_auth_enabled=True,
        basic_auth_username="username",
        json_data_encoded=json.dumps({
            "httpMethod": "POST",
            "prometheusType": "Mimir",
            "prometheusVersion": "2.4.0",
        }),
        secure_json_data_encoded=json.dumps({
            "basicAuthPassword": "password",
        }))
    from_name = grafana.get_data_source_output(name=prometheus.name)
    from_id = grafana.get_data_source_output(id=prometheus.id)
    from_uid = grafana.get_data_source_output(uid=prometheus.uid)
    
    package main
    
    import (
    	"encoding/json"
    
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumiverse/pulumi-grafana/sdk/go/grafana"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		tmpJSON0, err := json.Marshal(map[string]interface{}{
    			"httpMethod":        "POST",
    			"prometheusType":    "Mimir",
    			"prometheusVersion": "2.4.0",
    		})
    		if err != nil {
    			return err
    		}
    		json0 := string(tmpJSON0)
    		tmpJSON1, err := json.Marshal(map[string]interface{}{
    			"basicAuthPassword": "password",
    		})
    		if err != nil {
    			return err
    		}
    		json1 := string(tmpJSON1)
    		prometheus, err := grafana.NewDataSource(ctx, "prometheus", &grafana.DataSourceArgs{
    			Type:                  pulumi.String("prometheus"),
    			Uid:                   pulumi.String("prometheus-ds-test-uid"),
    			Url:                   pulumi.String("https://my-instance.com"),
    			BasicAuthEnabled:      pulumi.Bool(true),
    			BasicAuthUsername:     pulumi.String("username"),
    			JsonDataEncoded:       pulumi.String(json0),
    			SecureJsonDataEncoded: pulumi.String(json1),
    		})
    		if err != nil {
    			return err
    		}
    		_ = grafana.LookupDataSourceOutput(ctx, grafana.GetDataSourceOutputArgs{
    			Name: prometheus.Name,
    		}, nil)
    		_ = grafana.LookupDataSourceOutput(ctx, grafana.GetDataSourceOutputArgs{
    			Id: prometheus.ID(),
    		}, nil)
    		_ = grafana.LookupDataSourceOutput(ctx, grafana.GetDataSourceOutputArgs{
    			Uid: prometheus.Uid,
    		}, nil)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using System.Text.Json;
    using Pulumi;
    using Grafana = Pulumi.Grafana;
    using Grafana = Pulumiverse.Grafana;
    
    return await Deployment.RunAsync(() => 
    {
        var prometheus = new Grafana.DataSource("prometheus", new()
        {
            Type = "prometheus",
            Uid = "prometheus-ds-test-uid",
            Url = "https://my-instance.com",
            BasicAuthEnabled = true,
            BasicAuthUsername = "username",
            JsonDataEncoded = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["httpMethod"] = "POST",
                ["prometheusType"] = "Mimir",
                ["prometheusVersion"] = "2.4.0",
            }),
            SecureJsonDataEncoded = JsonSerializer.Serialize(new Dictionary<string, object?>
            {
                ["basicAuthPassword"] = "password",
            }),
        });
    
        var fromName = Grafana.GetDataSource.Invoke(new()
        {
            Name = prometheus.Name,
        });
    
        var fromId = Grafana.GetDataSource.Invoke(new()
        {
            Id = prometheus.Id,
        });
    
        var fromUid = Grafana.GetDataSource.Invoke(new()
        {
            Uid = prometheus.Uid,
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.grafana.DataSource;
    import com.pulumi.grafana.DataSourceArgs;
    import com.pulumi.grafana.GrafanaFunctions;
    import com.pulumi.grafana.inputs.GetDataSourceArgs;
    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 prometheus = new DataSource("prometheus", DataSourceArgs.builder()        
                .type("prometheus")
                .uid("prometheus-ds-test-uid")
                .url("https://my-instance.com")
                .basicAuthEnabled(true)
                .basicAuthUsername("username")
                .jsonDataEncoded(serializeJson(
                    jsonObject(
                        jsonProperty("httpMethod", "POST"),
                        jsonProperty("prometheusType", "Mimir"),
                        jsonProperty("prometheusVersion", "2.4.0")
                    )))
                .secureJsonDataEncoded(serializeJson(
                    jsonObject(
                        jsonProperty("basicAuthPassword", "password")
                    )))
                .build());
    
            final var fromName = GrafanaFunctions.getDataSource(GetDataSourceArgs.builder()
                .name(prometheus.name())
                .build());
    
            final var fromId = GrafanaFunctions.getDataSource(GetDataSourceArgs.builder()
                .id(prometheus.id())
                .build());
    
            final var fromUid = GrafanaFunctions.getDataSource(GetDataSourceArgs.builder()
                .uid(prometheus.uid())
                .build());
    
        }
    }
    
    resources:
      prometheus:
        type: grafana:DataSource
        properties:
          type: prometheus
          uid: prometheus-ds-test-uid
          url: https://my-instance.com
          basicAuthEnabled: true
          basicAuthUsername: username
          jsonDataEncoded:
            fn::toJSON:
              httpMethod: POST
              prometheusType: Mimir
              prometheusVersion: 2.4.0
          secureJsonDataEncoded:
            fn::toJSON:
              basicAuthPassword: password
    variables:
      fromName:
        fn::invoke:
          Function: grafana:getDataSource
          Arguments:
            name: ${prometheus.name}
      fromId:
        fn::invoke:
          Function: grafana:getDataSource
          Arguments:
            id: ${prometheus.id}
      fromUid:
        fn::invoke:
          Function: grafana:getDataSource
          Arguments:
            uid: ${prometheus.uid}
    

    Using getDataSource

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getDataSource(args: GetDataSourceArgs, opts?: InvokeOptions): Promise<GetDataSourceResult>
    function getDataSourceOutput(args: GetDataSourceOutputArgs, opts?: InvokeOptions): Output<GetDataSourceResult>
    def get_data_source(id: Optional[str] = None,
                        name: Optional[str] = None,
                        org_id: Optional[str] = None,
                        uid: Optional[str] = None,
                        opts: Optional[InvokeOptions] = None) -> GetDataSourceResult
    def get_data_source_output(id: Optional[pulumi.Input[str]] = None,
                        name: Optional[pulumi.Input[str]] = None,
                        org_id: Optional[pulumi.Input[str]] = None,
                        uid: Optional[pulumi.Input[str]] = None,
                        opts: Optional[InvokeOptions] = None) -> Output[GetDataSourceResult]
    func LookupDataSource(ctx *Context, args *LookupDataSourceArgs, opts ...InvokeOption) (*LookupDataSourceResult, error)
    func LookupDataSourceOutput(ctx *Context, args *LookupDataSourceOutputArgs, opts ...InvokeOption) LookupDataSourceResultOutput

    > Note: This function is named LookupDataSource in the Go SDK.

    public static class GetDataSource 
    {
        public static Task<GetDataSourceResult> InvokeAsync(GetDataSourceArgs args, InvokeOptions? opts = null)
        public static Output<GetDataSourceResult> Invoke(GetDataSourceInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetDataSourceResult> getDataSource(GetDataSourceArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: grafana:index/getDataSource:getDataSource
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Id string
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    Name string
    OrgId string
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    Uid string
    Id string
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    Name string
    OrgId string
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    Uid string
    id String
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    name String
    orgId String
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    uid String
    id string
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    name string
    orgId string
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    uid string
    id str
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    name str
    org_id str
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    uid str
    id String
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    name String
    orgId String
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    uid String

    getDataSource Result

    The following output properties are available:

    AccessMode string
    The method by which Grafana will access the data source: proxy or direct.
    BasicAuthEnabled bool
    Whether to enable basic auth for the data source.
    BasicAuthUsername string
    Basic auth username.
    DatabaseName string
    (Required by some data source types) The name of the database to use on the selected data source server.
    Id string
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    IsDefault bool
    Whether to set the data source as default. This should only be true to a single data source.
    JsonDataEncoded string
    Serialized JSON string containing the json data. This attribute can be used to pass configuration options to the data source. To figure out what options a datasource has available, see its docs or inspect the network data when saving it from the Grafana UI. Note that keys in this map are usually camelCased.
    Name string
    Type string
    The data source type. Must be one of the supported data source keywords.
    Uid string
    Url string
    The URL for the data source. The type of URL required varies depending on the chosen data source type.
    Username string
    (Required by some data source types) The username to use to authenticate to the data source.
    OrgId string
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    AccessMode string
    The method by which Grafana will access the data source: proxy or direct.
    BasicAuthEnabled bool
    Whether to enable basic auth for the data source.
    BasicAuthUsername string
    Basic auth username.
    DatabaseName string
    (Required by some data source types) The name of the database to use on the selected data source server.
    Id string
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    IsDefault bool
    Whether to set the data source as default. This should only be true to a single data source.
    JsonDataEncoded string
    Serialized JSON string containing the json data. This attribute can be used to pass configuration options to the data source. To figure out what options a datasource has available, see its docs or inspect the network data when saving it from the Grafana UI. Note that keys in this map are usually camelCased.
    Name string
    Type string
    The data source type. Must be one of the supported data source keywords.
    Uid string
    Url string
    The URL for the data source. The type of URL required varies depending on the chosen data source type.
    Username string
    (Required by some data source types) The username to use to authenticate to the data source.
    OrgId string
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    accessMode String
    The method by which Grafana will access the data source: proxy or direct.
    basicAuthEnabled Boolean
    Whether to enable basic auth for the data source.
    basicAuthUsername String
    Basic auth username.
    databaseName String
    (Required by some data source types) The name of the database to use on the selected data source server.
    id String
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    isDefault Boolean
    Whether to set the data source as default. This should only be true to a single data source.
    jsonDataEncoded String
    Serialized JSON string containing the json data. This attribute can be used to pass configuration options to the data source. To figure out what options a datasource has available, see its docs or inspect the network data when saving it from the Grafana UI. Note that keys in this map are usually camelCased.
    name String
    type String
    The data source type. Must be one of the supported data source keywords.
    uid String
    url String
    The URL for the data source. The type of URL required varies depending on the chosen data source type.
    username String
    (Required by some data source types) The username to use to authenticate to the data source.
    orgId String
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    accessMode string
    The method by which Grafana will access the data source: proxy or direct.
    basicAuthEnabled boolean
    Whether to enable basic auth for the data source.
    basicAuthUsername string
    Basic auth username.
    databaseName string
    (Required by some data source types) The name of the database to use on the selected data source server.
    id string
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    isDefault boolean
    Whether to set the data source as default. This should only be true to a single data source.
    jsonDataEncoded string
    Serialized JSON string containing the json data. This attribute can be used to pass configuration options to the data source. To figure out what options a datasource has available, see its docs or inspect the network data when saving it from the Grafana UI. Note that keys in this map are usually camelCased.
    name string
    type string
    The data source type. Must be one of the supported data source keywords.
    uid string
    url string
    The URL for the data source. The type of URL required varies depending on the chosen data source type.
    username string
    (Required by some data source types) The username to use to authenticate to the data source.
    orgId string
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    access_mode str
    The method by which Grafana will access the data source: proxy or direct.
    basic_auth_enabled bool
    Whether to enable basic auth for the data source.
    basic_auth_username str
    Basic auth username.
    database_name str
    (Required by some data source types) The name of the database to use on the selected data source server.
    id str
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    is_default bool
    Whether to set the data source as default. This should only be true to a single data source.
    json_data_encoded str
    Serialized JSON string containing the json data. This attribute can be used to pass configuration options to the data source. To figure out what options a datasource has available, see its docs or inspect the network data when saving it from the Grafana UI. Note that keys in this map are usually camelCased.
    name str
    type str
    The data source type. Must be one of the supported data source keywords.
    uid str
    url str
    The URL for the data source. The type of URL required varies depending on the chosen data source type.
    username str
    (Required by some data source types) The username to use to authenticate to the data source.
    org_id str
    The Organization ID. If not set, the Org ID defined in the provider block will be used.
    accessMode String
    The method by which Grafana will access the data source: proxy or direct.
    basicAuthEnabled Boolean
    Whether to enable basic auth for the data source.
    basicAuthUsername String
    Basic auth username.
    databaseName String
    (Required by some data source types) The name of the database to use on the selected data source server.
    id String
    Deprecated: Use uid instead of id

    Deprecated: Use uid instead of id

    isDefault Boolean
    Whether to set the data source as default. This should only be true to a single data source.
    jsonDataEncoded String
    Serialized JSON string containing the json data. This attribute can be used to pass configuration options to the data source. To figure out what options a datasource has available, see its docs or inspect the network data when saving it from the Grafana UI. Note that keys in this map are usually camelCased.
    name String
    type String
    The data source type. Must be one of the supported data source keywords.
    uid String
    url String
    The URL for the data source. The type of URL required varies depending on the chosen data source type.
    username String
    (Required by some data source types) The username to use to authenticate to the data source.
    orgId String
    The Organization ID. If not set, the Org ID defined in the provider block will be used.

    Package Details

    Repository
    grafana pulumiverse/pulumi-grafana
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the grafana Terraform Provider.
    grafana logo
    Grafana v0.5.1 published on Wednesday, Jun 12, 2024 by pulumiverse