UNPKG

@studion/infra-code-blocks

Version:
56 lines (55 loc) 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AMPConnection = void 0; const aws = require("@pulumi/aws"); const pulumi = require("@pulumi/pulumi"); const grafana = require("@pulumiverse/grafana"); const resolve_aws_region_1 = require("../../../shared/resolve-aws-region"); const connection_1 = require("./connection"); class AMPConnection extends connection_1.GrafanaConnection { name; dataSource; rolePolicy; constructor(name, args, opts = {}) { super('studion:grafana:AMPConnection', name, args, opts); const region = (0, resolve_aws_region_1.resolveAwsRegion)(args, this); this.name = name; this.rolePolicy = this.createRolePolicy(); this.dataSource = this.createDataSource(args.endpoint, region); this.registerOutputs(); } createRolePolicy() { const policy = aws.iam.getPolicyDocumentOutput({ statements: [ { effect: 'Allow', actions: [ 'aps:GetSeries', 'aps:GetLabels', 'aps:GetMetricMetadata', 'aps:QueryMetrics', ], resources: ['*'], }, ], }); return new aws.iam.RolePolicy(`${this.name}-amp-policy`, { role: this.role.id, policy: policy.json, }, { parent: this }); } createDataSource(endpoint, region) { return new grafana.oss.DataSource(`${this.name}-amp-datasource`, { name: this.dataSourceName, type: 'grafana-amazonprometheus-datasource', url: endpoint, jsonDataEncoded: pulumi.jsonStringify({ sigV4Auth: true, sigV4AuthType: 'grafana_assume_role', sigV4Region: region, sigV4AssumeRoleArn: this.role.arn, }), }, { parent: this }); } } exports.AMPConnection = AMPConnection;