Class RolePolicy


  • public class RolePolicy
    extends com.pulumi.resources.CustomResource
    Provides an IAM role inline policy. > **NOTE:** For a given role, this resource is incompatible with using the `aws.iam.Role` resource `inlinePolicy` argument. When using that argument and this resource, both will attempt to manage the role's inline policies and the provider will show a permanent difference. > **NOTE:** We suggest using explicit JSON encoding or `aws.iam.getPolicyDocument` when assigning a value to `policy`. They seamlessly translate configuration to JSON, enabling you to maintain consistency within your configuration without the need for context switches. Also, you can sidestep potential complications arising from formatting discrepancies, whitespace inconsistencies, and other nuances inherent to JSON. ## Example Usage
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.iam.Role;
     import com.pulumi.aws.iam.RoleArgs;
     import com.pulumi.aws.iam.RolePolicy;
     import com.pulumi.aws.iam.RolePolicyArgs;
     import static com.pulumi.codegen.internal.Serialization.*;
     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 testRole = new Role("testRole", RoleArgs.builder()
                 .name("test_role")
                 .assumeRolePolicy(serializeJson(
                     jsonObject(
                         jsonProperty("Version", "2012-10-17"),
                         jsonProperty("Statement", jsonArray(jsonObject(
                             jsonProperty("Action", "sts:AssumeRole"),
                             jsonProperty("Effect", "Allow"),
                             jsonProperty("Sid", ""),
                             jsonProperty("Principal", jsonObject(
                                 jsonProperty("Service", "ec2.amazonaws.com")
                             ))
                         )))
                     )))
                 .build());
     
             var testPolicy = new RolePolicy("testPolicy", RolePolicyArgs.builder()
                 .name("test_policy")
                 .role(testRole.id())
                 .policy(serializeJson(
                     jsonObject(
                         jsonProperty("Version", "2012-10-17"),
                         jsonProperty("Statement", jsonArray(jsonObject(
                             jsonProperty("Action", jsonArray("ec2:Describe*")),
                             jsonProperty("Effect", "Allow"),
                             jsonProperty("Resource", "*")
                         )))
                     )))
                 .build());
     
         }
     }
     
     
    ## Import ### Identity Schema #### Required * `role` (String) Name of the IAM role. * `name` (String) Name of the role policy. #### Optional * `accountId` (String) AWS Account where this resource is managed. Using `pulumi import`, import IAM Role Policies using the `role_name:role_policy_name`. For example: ```sh $ pulumi import aws:iam/rolePolicy:RolePolicy example role_of_mypolicy_name:mypolicy_name ```
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pulumi.resources.CustomResource

        com.pulumi.resources.CustomResource.CustomResourceInternal
      • Nested classes/interfaces inherited from class com.pulumi.resources.Resource

        com.pulumi.resources.Resource.LazyField<T extends java.lang.Object>, com.pulumi.resources.Resource.LazyFields, com.pulumi.resources.Resource.ResourceInternal
    • Field Summary

      • Fields inherited from class com.pulumi.resources.Resource

        childResources, remote
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static RolePolicy get​(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, RolePolicyState 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> name()  
      com.pulumi.core.Output<java.lang.String> namePrefix()  
      com.pulumi.core.Output<java.lang.String> policy()  
      com.pulumi.core.Output<java.lang.String> role()  
      • Methods inherited from class com.pulumi.resources.CustomResource

        getId, id, idFuture
      • Methods inherited from class com.pulumi.resources.Resource

        getChildResources, getResourceName, getResourceType, getUrn, pulumiChildResources, pulumiResourceName, pulumiResourceType, urn
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RolePolicy

        public RolePolicy​(java.lang.String name)
        Parameters:
        name - The _unique_ name of the resulting resource.
      • RolePolicy

        public RolePolicy​(java.lang.String name,
                          RolePolicyArgs args)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
      • RolePolicy

        public RolePolicy​(java.lang.String name,
                          RolePolicyArgs 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

      • name

        public com.pulumi.core.Output<java.lang.String> name()
        Returns:
        The name of the role policy. If omitted, the provider will assign a random, unique name.
      • namePrefix

        public com.pulumi.core.Output<java.lang.String> namePrefix()
        Returns:
        Creates a unique name beginning with the specified prefix. Conflicts with `name`.
      • policy

        public com.pulumi.core.Output<java.lang.String> policy()
        Returns:
        The inline policy document. This is a JSON formatted string. For more information about building IAM policy documents with Pulumi, see the AWS IAM Policy Document Guide
      • role

        public com.pulumi.core.Output<java.lang.String> role()
        Returns:
        The name of the IAM role to attach to the policy.
      • get

        public static RolePolicy get​(java.lang.String name,
                                     com.pulumi.core.Output<java.lang.String> id,
                                     @Nullable
                                     RolePolicyState 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.