@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
182 lines • 7.15 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.ResourcePolicy = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* Manages an Amazon Managed Service for Prometheus (AMP) Resource Policy.
*
* Resource-based policies allow you to grant permissions to other AWS accounts or services to access your Prometheus workspace. This enables cross-account access and fine-grained permissions for workspace sharing.
*
* ## Example Usage
*
* ### Basic Resource Policy
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const exampleWorkspace = new aws.amp.Workspace("example", {alias: "example-workspace"});
* const current = aws.getCallerIdentity({});
* const example = pulumi.all([current, exampleWorkspace.arn]).apply(([current, arn]) => aws.iam.getPolicyDocumentOutput({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "AWS",
* identifiers: [current.accountId],
* }],
* actions: [
* "aps:RemoteWrite",
* "aps:QueryMetrics",
* "aps:GetSeries",
* "aps:GetLabels",
* "aps:GetMetricMetadata",
* ],
* resources: [arn],
* }],
* }));
* const exampleResourcePolicy = new aws.amp.ResourcePolicy("example", {
* workspaceId: exampleWorkspace.id,
* policyDocument: example.apply(example => example.json),
* });
* ```
*
* ### Cross-Account Access
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const example = new aws.amp.Workspace("example", {alias: "example-workspace"});
* const crossAccount = aws.iam.getPolicyDocumentOutput({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "AWS",
* identifiers: ["arn:aws:iam::123456789012:root"],
* }],
* actions: [
* "aps:RemoteWrite",
* "aps:QueryMetrics",
* ],
* resources: [example.arn],
* }],
* });
* const crossAccountResourcePolicy = new aws.amp.ResourcePolicy("cross_account", {
* workspaceId: example.id,
* policyDocument: crossAccount.apply(crossAccount => crossAccount.json),
* });
* ```
*
* ### Service-Specific Access
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const example = new aws.amp.Workspace("example", {alias: "example-workspace"});
* const serviceAccess = aws.iam.getPolicyDocumentOutput({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "Service",
* identifiers: ["grafana.amazonaws.com"],
* }],
* actions: [
* "aps:QueryMetrics",
* "aps:GetSeries",
* "aps:GetLabels",
* "aps:GetMetricMetadata",
* ],
* resources: [example.arn],
* }],
* });
* const serviceAccessResourcePolicy = new aws.amp.ResourcePolicy("service_access", {
* workspaceId: example.id,
* policyDocument: serviceAccess.apply(serviceAccess => serviceAccess.json),
* });
* ```
*
* ## Supported Actions
*
* The following actions are supported in resource policies for Prometheus workspaces:
*
* * `aps:RemoteWrite` - Allows writing metrics to the workspace
* * `aps:QueryMetrics` - Allows querying metrics from the workspace
* * `aps:GetSeries` - Allows retrieving time series data
* * `aps:GetLabels` - Allows retrieving label names and values
* * `aps:GetMetricMetadata` - Allows retrieving metric metadata
*
* ## Notes
*
* * Only Prometheus-compatible APIs can be used for workspace sharing. Non-Prometheus-compatible APIs added to the policy will be ignored.
* * If your workspace uses customer-managed KMS keys for encryption, you must grant the principals in your resource-based policy access to those KMS keys through KMS grants.
* * The resource ARN in the policy document must match the workspace ARN that the policy is being attached to.
* * Resource policies enable cross-account access and fine-grained permissions for Prometheus workspaces.
*
* ## Import
*
* Using `pulumi import`, import AMP Resource Policies using the workspace ID. For example:
*
* ```sh
* $ pulumi import aws:amp/resourcePolicy:ResourcePolicy example ws-12345678-90ab-cdef-1234-567890abcdef
* ```
*/
class ResourcePolicy extends pulumi.CustomResource {
/**
* Get an existing ResourcePolicy 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 ResourcePolicy(name, state, { ...opts, id: id });
}
/**
* Returns true if the given object is an instance of ResourcePolicy. 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'] === ResourcePolicy.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["policyDocument"] = state?.policyDocument;
resourceInputs["region"] = state?.region;
resourceInputs["revisionId"] = state?.revisionId;
resourceInputs["timeouts"] = state?.timeouts;
resourceInputs["workspaceId"] = state?.workspaceId;
}
else {
const args = argsOrState;
if (args?.policyDocument === undefined && !opts.urn) {
throw new Error("Missing required property 'policyDocument'");
}
if (args?.workspaceId === undefined && !opts.urn) {
throw new Error("Missing required property 'workspaceId'");
}
resourceInputs["policyDocument"] = args?.policyDocument;
resourceInputs["region"] = args?.region;
resourceInputs["revisionId"] = args?.revisionId;
resourceInputs["timeouts"] = args?.timeouts;
resourceInputs["workspaceId"] = args?.workspaceId;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(ResourcePolicy.__pulumiType, name, resourceInputs, opts);
}
}
exports.ResourcePolicy = ResourcePolicy;
/** @internal */
ResourcePolicy.__pulumiType = 'aws:amp/resourcePolicy:ResourcePolicy';
//# sourceMappingURL=resourcePolicy.js.map