@studion/infra-code-blocks
Version:
Studion common infra components
49 lines (48 loc) • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GrafanaConnection = void 0;
const aws = require("@pulumi/aws");
const pulumi = require("@pulumi/pulumi");
const common_tags_1 = require("../../../shared/common-tags");
class GrafanaConnection extends pulumi.ComponentResource {
name;
role;
dataSourceName;
stack;
constructor(type, name, args, opts = {}) {
super(type, name, {}, opts);
this.name = name;
this.dataSourceName = args.dataSourceName ?? `${name}-datasource`;
this.stack = pulumi.output(args.stack);
this.role = this.createIamRole(args.awsAccountId);
this.registerOutputs();
}
createIamRole(awsAccountId) {
const assumeRolePolicy = aws.iam.getPolicyDocumentOutput({
statements: [
{
effect: 'Allow',
principals: [
{
type: 'AWS',
identifiers: [`arn:aws:iam::${awsAccountId}:root`],
},
],
actions: ['sts:AssumeRole'],
conditions: [
{
test: 'StringEquals',
variable: 'sts:ExternalId',
values: [this.stack.id],
},
],
},
],
});
return new aws.iam.Role(`${this.name}-grafana-iam-role`, {
assumeRolePolicy: assumeRolePolicy.json,
tags: common_tags_1.commonTags,
}, { parent: this });
}
}
exports.GrafanaConnection = GrafanaConnection;