@pulumiverse/grafana
Version:
A Pulumi package for creating and managing grafana.
191 lines • 7.87 kB
JavaScript
;
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stack = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* Manages the Asserts Stack configuration.
*
* This resource configures the Asserts stack with the required API tokens for integration
* with Grafana Cloud services. It performs the full onboarding flow:
* 1. Provisions API tokens
* 2. Configures datasets (auto-detected or manually specified)
* 3. Enables the stack
*
* By default, datasets are auto-configured based on detected metrics. To manually configure
* datasets (e.g., when using non-standard label names), use the `dataset` block.
*
* The `cloudAccessPolicyToken` is used internally for GCom API access, Mimir metrics
* authentication, and assertion detector webhook authentication. Create a Cloud Access Policy
* with the following scopes: `stacks:read`, `metrics:read`, `metrics:write`.
*
* The `grafanaToken` is a Grafana Service Account token used for installing dashboards
* and Grafana Managed Alerts.
*
* ## Example Usage
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as grafana from "@pulumiverse/grafana";
*
* const config = new pulumi.Config();
* // The Grafana Cloud stack ID
* const stackId = config.require("stackId");
* // Example: Asserts Stack with Cloud Access Policy Token
* //
* // This example shows how to configure the Asserts stack using existing
* // Terraform resources to create the required tokens.
* //
* // The resource performs the full onboarding flow:
* // 1. Provisions API tokens
* // 2. Auto-configures datasets based on available metrics
* // 3. Enables the stack with the configured datasets
* // Step 1: Create a Cloud Access Policy with required scopes
* const asserts = new grafana.cloud.AccessPolicy("asserts", {
* name: "asserts-stack-policy",
* displayName: "Asserts Stack Policy",
* scopes: [
* "stacks:read",
* "metrics:read",
* "metrics:write",
* ],
* realms: [{
* type: "stack",
* identifier: stackId,
* }],
* });
* // Step 2: Create a token from the Cloud Access Policy
* const assertsAccessPolicyToken = new grafana.cloud.AccessPolicyToken("asserts", {
* name: "asserts-stack-token",
* accessPolicyId: asserts.policyId,
* });
* // The Grafana Cloud stack slug
* const stackSlug = config.require("stackSlug");
* // Step 3: Create a Grafana Service Account for dashboards and Grafana Managed Alerts
* // Required permissions: dashboards:create/write/read, folders:create/write/read/delete,
* // datasources:read/query, alert.provisioning:write, alert.notifications.provisioning:write,
* // alert.notifications:write, alert.rules:read/create/delete
* const assertsStackServiceAccount = new grafana.cloud.StackServiceAccount("asserts", {
* stackSlug: stackSlug,
* name: "asserts-managed-alerts-sa",
* role: "Admin",
* isDisabled: false,
* });
* const assertsStackServiceAccountToken = new grafana.cloud.StackServiceAccountToken("asserts", {
* stackSlug: stackSlug,
* serviceAccountId: assertsStackServiceAccount.id,
* name: "asserts-managed-alerts-token",
* });
* // Step 4: Configure the Asserts Stack (auto-detect datasets)
* const main = new grafana.assert.Stack("main", {
* cloudAccessPolicyToken: assertsAccessPolicyToken.token,
* grafanaToken: assertsStackServiceAccountToken.key,
* });
* // Alternative: Configure the Asserts Stack with manual dataset configuration.
* // Use this when your metrics use non-standard labels (e.g., a custom environment label).
* const custom = new grafana.assert.Stack("custom", {
* cloudAccessPolicyToken: assertsAccessPolicyToken.token,
* grafanaToken: assertsStackServiceAccountToken.key,
* datasets: [
* {
* type: "kubernetes",
* filterGroups: [{
* envLabel: "deployment_environment",
* siteLabel: "cluster",
* envLabelValues: [
* "production",
* "staging",
* ],
* siteLabelValues: [
* "us-east-1",
* "eu-west-1",
* ],
* }],
* },
* {
* type: "prometheus",
* filterGroups: [{
* envLabel: "environment",
* envName: "prod",
* filters: [{
* name: "region",
* operator: "=~",
* values: [
* "us-.*",
* "eu-.*",
* ],
* }],
* }],
* },
* ],
* });
* export const stackEnabled = main.enabled;
* export const stackStatus = main.status;
* export const stackVersion = main.version;
* ```
*
* ## Import
*
* ```sh
* terraform import grafana_asserts_stack.name "{{ id }}"
* ```
*/
class Stack extends pulumi.CustomResource {
/**
* Get an existing Stack resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state Any extra arguments used during the lookup.
* @param opts Optional settings to control the behavior of the CustomResource.
*/
static get(name, id, state, opts) {
return new Stack(name, state, { ...opts, id: id });
}
/**
* Returns true if the given object is an instance of Stack. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
static isInstance(obj) {
if (obj === undefined || obj === null) {
return false;
}
return obj['__pulumiType'] === Stack.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["cloudAccessPolicyToken"] = state?.cloudAccessPolicyToken;
resourceInputs["datasets"] = state?.datasets;
resourceInputs["enabled"] = state?.enabled;
resourceInputs["grafanaToken"] = state?.grafanaToken;
resourceInputs["status"] = state?.status;
resourceInputs["version"] = state?.version;
}
else {
const args = argsOrState;
if (args?.cloudAccessPolicyToken === undefined && !opts.urn) {
throw new Error("Missing required property 'cloudAccessPolicyToken'");
}
resourceInputs["cloudAccessPolicyToken"] = args?.cloudAccessPolicyToken ? pulumi.secret(args.cloudAccessPolicyToken) : undefined;
resourceInputs["datasets"] = args?.datasets;
resourceInputs["grafanaToken"] = args?.grafanaToken ? pulumi.secret(args.grafanaToken) : undefined;
resourceInputs["enabled"] = undefined /*out*/;
resourceInputs["status"] = undefined /*out*/;
resourceInputs["version"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
const secretOpts = { additionalSecretOutputs: ["cloudAccessPolicyToken", "grafanaToken"] };
opts = pulumi.mergeOptions(opts, secretOpts);
super(Stack.__pulumiType, name, resourceInputs, opts);
}
}
exports.Stack = Stack;
/** @internal */
Stack.__pulumiType = 'grafana:assert/stack:Stack';
//# sourceMappingURL=stack.js.map