UNPKG

@studion/infra-code-blocks

Version:
56 lines (55 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CloudWatchLogsConnection = 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 CloudWatchLogsConnection extends connection_1.GrafanaConnection { name; dataSource; rolePolicy; constructor(name, args, opts = {}) { super('studion:grafana:CloudWatchLogsConnection', name, args, opts); const region = (0, resolve_aws_region_1.resolveAwsRegion)(args, this); this.name = name; this.rolePolicy = this.createRolePolicy(); this.dataSource = this.createDataSource(region); this.registerOutputs(); } createRolePolicy() { const policy = aws.iam.getPolicyDocumentOutput({ statements: [ { effect: 'Allow', actions: [ 'logs:DescribeLogGroups', 'logs:GetLogGroupFields', 'logs:StartQuery', 'logs:StopQuery', 'logs:GetQueryResults', 'logs:GetLogEvents', ], resources: ['*'], }, ], }); return new aws.iam.RolePolicy(`${this.name}-cloudwatch-logs-policy`, { role: this.role.id, policy: policy.json, }, { parent: this }); } createDataSource(region) { return new grafana.oss.DataSource(`${this.name}-cloudwatch-logs-datasource`, { name: this.dataSourceName, type: 'cloudwatch', jsonDataEncoded: pulumi.jsonStringify({ authType: 'grafana_assume_role', assumeRoleArn: this.role.arn, defaultRegion: region, }), }, { parent: this }); } } exports.CloudWatchLogsConnection = CloudWatchLogsConnection;