Package com.pulumi.aws.iam
Class RolePolicyAttachment
- java.lang.Object
-
- com.pulumi.resources.Resource
-
- com.pulumi.resources.CustomResource
-
- com.pulumi.aws.iam.RolePolicyAttachment
-
public class RolePolicyAttachment extends com.pulumi.resources.CustomResourceAttaches a Managed IAM Policy to an IAM role > **NOTE:** The usage of this resource conflicts with the `aws.iam.PolicyAttachment` resource 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 Pulumi will show a permanent difference. ## Example Usage
## Import ### Identity Schema #### Required * `role` (String) Name of the IAM role. * `policyArn` (String) ARN of the IAM policy. #### Optional * `accountId` (String) AWS Account where this resource is managed. Using `pulumi import`, import IAM role policy attachments using the role name and policy ARN separated by `/`. For example: ```sh $ pulumi import aws:iam/rolePolicyAttachment:RolePolicyAttachment example test-role/arn:aws:iam::xxxxxxxxxxxx:policy/test-policy ```package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; 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.Policy; import com.pulumi.aws.iam.PolicyArgs; import com.pulumi.aws.iam.RolePolicyAttachment; import com.pulumi.aws.iam.RolePolicyAttachmentArgs; 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) { 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("test-role") .assumeRolePolicy(assumeRole.json()) .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("test-policy") .description("A test policy") .policy(policy.json()) .build()); var test_attach = new RolePolicyAttachment("test-attach", RolePolicyAttachmentArgs.builder() .role(role.name()) .policyArn(policyPolicy.arn()) .build()); } }
-
-
Constructor Summary
Constructors Constructor Description RolePolicyAttachment(java.lang.String name)RolePolicyAttachment(java.lang.String name, RolePolicyAttachmentArgs args)RolePolicyAttachment(java.lang.String name, RolePolicyAttachmentArgs args, com.pulumi.resources.CustomResourceOptions options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static RolePolicyAttachmentget(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, RolePolicyAttachmentState 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.lang.String>policyArn()com.pulumi.core.Output<java.lang.String>role()
-
-
-
Constructor Detail
-
RolePolicyAttachment
public RolePolicyAttachment(java.lang.String name)
- Parameters:
name- The _unique_ name of the resulting resource.
-
RolePolicyAttachment
public RolePolicyAttachment(java.lang.String name, RolePolicyAttachmentArgs args)- Parameters:
name- The _unique_ name of the resulting resource.args- The arguments to use to populate this resource's properties.
-
RolePolicyAttachment
public RolePolicyAttachment(java.lang.String name, RolePolicyAttachmentArgs 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
-
policyArn
public com.pulumi.core.Output<java.lang.String> policyArn()
- Returns:
- The ARN of the policy you want to apply
-
role
public com.pulumi.core.Output<java.lang.String> role()
- Returns:
- The name of the IAM role to which the policy should be applied
-
get
public static RolePolicyAttachment get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, @Nullable RolePolicyAttachmentState 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.
-
-