Class UserPolicy


  • public class UserPolicy
    extends com.pulumi.resources.CustomResource
    Provides an IAM policy attached to a user. > **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.User;
     import com.pulumi.aws.iam.UserArgs;
     import com.pulumi.aws.iam.UserPolicy;
     import com.pulumi.aws.iam.UserPolicyArgs;
     import com.pulumi.aws.iam.AccessKey;
     import com.pulumi.aws.iam.AccessKeyArgs;
     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 lb = new User("lb", UserArgs.builder()
                 .name("loadbalancer")
                 .path("/system/")
                 .build());
     
             var lbRo = new UserPolicy("lbRo", UserPolicyArgs.builder()
                 .name("test")
                 .user(lb.name())
                 .policy(serializeJson(
                     jsonObject(
                         jsonProperty("Version", "2012-10-17"),
                         jsonProperty("Statement", jsonArray(jsonObject(
                             jsonProperty("Action", jsonArray("ec2:Describe*")),
                             jsonProperty("Effect", "Allow"),
                             jsonProperty("Resource", "*")
                         )))
                     )))
                 .build());
     
             var lbAccessKey = new AccessKey("lbAccessKey", AccessKeyArgs.builder()
                 .user(lb.name())
                 .build());
     
         }
     }
     
     
    ## Import ### Identity Schema #### Required * `user` (String) Name of the IAM user. * `name` (String) Name of the user policy. #### Optional * `accountId` (String) AWS Account where this resource is managed. Using `pulumi import`, import IAM User Policies using a `:` delimited string separating `user` and `name`. For example: ```sh $ pulumi import aws:iam/userPolicy:UserPolicy example my-user:my-policy ```
    • 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 UserPolicy get​(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, UserPolicyState 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> user()  
      • 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

      • UserPolicy

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

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

        public UserPolicy​(java.lang.String name,
                          UserPolicyArgs 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 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 policy document. This is a JSON formatted string.
      • user

        public com.pulumi.core.Output<java.lang.String> user()
        Returns:
        IAM user to which to attach this policy.
      • get

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