Package com.pulumi.aws.iam
Class PolicyAttachment
- java.lang.Object
-
- com.pulumi.resources.Resource
-
- com.pulumi.resources.CustomResource
-
- com.pulumi.aws.iam.PolicyAttachment
-
public class PolicyAttachment extends com.pulumi.resources.CustomResourceAttaches 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 Usagepackage generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.aws.iam.User; import com.pulumi.aws.iam.UserArgs; import com.pulumi.aws.iam.IamFunctions; import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs; import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs; import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs; import com.pulumi.aws.iam.Role; import com.pulumi.aws.iam.RoleArgs; import com.pulumi.aws.iam.Group; import com.pulumi.aws.iam.GroupArgs; import com.pulumi.aws.iam.Policy; import com.pulumi.aws.iam.PolicyArgs; import com.pulumi.aws.iam.PolicyAttachment; import com.pulumi.aws.iam.PolicyAttachmentArgs; import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var user = new User("user", UserArgs.builder() .name("example-user") .build()); final var assumeRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder() .statements(GetPolicyDocumentStatementArgs.builder() .principals(GetPolicyDocumentStatementPrincipalArgs.builder() .type("Service") .identifiers("ec2.amazonaws.com") .build()) .effect("Allow") .actions("sts:AssumeRole") .build()) .build()); var role = new Role("role", RoleArgs.builder() .name("example-role") .assumeRolePolicy(assumeRole.json()) .build()); var group = new Group("group", GroupArgs.builder() .name("example-group") .build()); final var policy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder() .statements(GetPolicyDocumentStatementArgs.builder() .effect("Allow") .actions("ec2:Describe*") .resources("*") .build()) .build()); var policyPolicy = new Policy("policyPolicy", PolicyArgs.builder() .name("example-policy") .description("An example policy") .policy(policy.json()) .build()); var example_attach = new PolicyAttachment("example-attach", PolicyAttachmentArgs.builder() .name("example-attachment") .users(user.name()) .roles(role.name()) .groups(group.name()) .policyArn(policyPolicy.arn()) .build()); } }
-
-
Constructor Summary
Constructors Constructor Description PolicyAttachment(java.lang.String name)PolicyAttachment(java.lang.String name, PolicyAttachmentArgs args)PolicyAttachment(java.lang.String name, PolicyAttachmentArgs args, com.pulumi.resources.CustomResourceOptions options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PolicyAttachmentget(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, PolicyAttachmentState state, com.pulumi.resources.CustomResourceOptions options)Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>>groups()com.pulumi.core.Output<java.lang.String>name()com.pulumi.core.Output<java.lang.String>policyArn()com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>>roles()com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>>users()
-
-
-
Constructor Detail
-
PolicyAttachment
public PolicyAttachment(java.lang.String name)
- Parameters:
name- The _unique_ name of the resulting resource.
-
PolicyAttachment
public PolicyAttachment(java.lang.String name, PolicyAttachmentArgs args)- Parameters:
name- The _unique_ name of the resulting resource.args- The arguments to use to populate this resource's properties.
-
PolicyAttachment
public PolicyAttachment(java.lang.String name, PolicyAttachmentArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options)- Parameters:
name- The _unique_ name of the resulting resource.args- The arguments to use to populate this resource's properties.options- A bag of options that control this resource's behavior.
-
-
Method Detail
-
groups
public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> groups()
- Returns:
- Group(s) the policy should be applied to.
-
name
public com.pulumi.core.Output<java.lang.String> name()
- Returns:
- Name of the attachment. This cannot be an empty string.
-
policyArn
public com.pulumi.core.Output<java.lang.String> policyArn()
- Returns:
- ARN of the policy you want to apply. Typically this should be a reference to the ARN of another resource to ensure dependency ordering, such as `aws_iam_policy.example.arn`.
-
roles
public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> roles()
- Returns:
- Role(s) the policy should be applied to.
-
users
public com.pulumi.core.Output<java.util.Optional<java.util.List<java.lang.String>>> users()
- Returns:
- User(s) the policy should be applied to.
-
get
public static PolicyAttachment get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, @Nullable PolicyAttachmentState state, @Nullable com.pulumi.resources.CustomResourceOptions options)
Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.- Parameters:
name- The _unique_ name of the resulting resource.id- The _unique_ provider ID of the resource to lookup.state-options- Optional settings to control the behavior of the CustomResource.
-
-