@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
114 lines • 5.7 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.PolicyAttachment = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* Attaches a Managed IAM Policy to user(s), role(s), and/or group(s)
*
* !> **WARNING:** The aws.iam.PolicyAttachment resource creates **exclusive** attachments of IAM policies. Across the entire AWS account, all of the users/roles/groups to which a single policy is attached must be declared by a single aws.iam.PolicyAttachment resource. This means that even any users/roles/groups that have the attached policy via any other mechanism (including other resources managed by this provider) will have that attached policy revoked by this resource. Consider `aws.iam.RolePolicyAttachment`, `aws.iam.UserPolicyAttachment`, or `aws.iam.GroupPolicyAttachment` instead. These resources do not enforce exclusive attachment of an IAM policy.
*
* > **NOTE:** The usage of this resource conflicts with the `aws.iam.GroupPolicyAttachment`, `aws.iam.RolePolicyAttachment`, and `aws.iam.UserPolicyAttachment` resources and will permanently show a difference if both are defined.
*
* > **NOTE:** For a given role, this resource is incompatible with using the `aws.iam.Role` resource `managedPolicyArns` argument. When using that argument and this resource, both will attempt to manage the role's managed policy attachments and the provider will show a permanent difference.
*
* > **NOTE:** To ensure Pulumi correctly manages dependencies during updates, use a reference to the IAM resource when defining the `policyArn` for `aws.iam.PolicyAttachment`, rather than constructing the ARN directly. For example, use `policyArn = aws_iam_policy.example.arn` instead of `policyArn = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/Example"`. Failing to do so may lead to errors like `DeleteConflict: Cannot delete a policy attached to entities` or `NoSuchEntity`.
*
* ## Example Usage
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const user = new aws.iam.User("user", {name: "test-user"});
* const assumeRole = aws.iam.getPolicyDocument({
* statements: [{
* effect: "Allow",
* principals: [{
* type: "Service",
* identifiers: ["ec2.amazonaws.com"],
* }],
* actions: ["sts:AssumeRole"],
* }],
* });
* const role = new aws.iam.Role("role", {
* name: "test-role",
* assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json),
* });
* const group = new aws.iam.Group("group", {name: "test-group"});
* const policy = aws.iam.getPolicyDocument({
* statements: [{
* effect: "Allow",
* actions: ["ec2:Describe*"],
* resources: ["*"],
* }],
* });
* const policyPolicy = new aws.iam.Policy("policy", {
* name: "test-policy",
* description: "A test policy",
* policy: policy.then(policy => policy.json),
* });
* const test_attach = new aws.iam.PolicyAttachment("test-attach", {
* name: "test-attachment",
* users: [user.name],
* roles: [role.name],
* groups: [group.name],
* policyArn: policyPolicy.arn,
* });
* ```
*/
class PolicyAttachment extends pulumi.CustomResource {
/**
* Get an existing PolicyAttachment 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 PolicyAttachment(name, state, { ...opts, id: id });
}
/**
* Returns true if the given object is an instance of PolicyAttachment. 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'] === PolicyAttachment.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["groups"] = state?.groups;
resourceInputs["name"] = state?.name;
resourceInputs["policyArn"] = state?.policyArn;
resourceInputs["roles"] = state?.roles;
resourceInputs["users"] = state?.users;
}
else {
const args = argsOrState;
if (args?.policyArn === undefined && !opts.urn) {
throw new Error("Missing required property 'policyArn'");
}
resourceInputs["groups"] = args?.groups;
resourceInputs["name"] = args?.name;
resourceInputs["policyArn"] = args?.policyArn;
resourceInputs["roles"] = args?.roles;
resourceInputs["users"] = args?.users;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(PolicyAttachment.__pulumiType, name, resourceInputs, opts);
}
}
exports.PolicyAttachment = PolicyAttachment;
/** @internal */
PolicyAttachment.__pulumiType = 'aws:iam/policyAttachment:PolicyAttachment';
//# sourceMappingURL=policyAttachment.js.map
;