Package com.pulumi.aws.iam
Class UserPolicy
- java.lang.Object
-
- com.pulumi.resources.Resource
-
- com.pulumi.resources.CustomResource
-
- com.pulumi.aws.iam.UserPolicy
-
public class UserPolicy extends com.pulumi.resources.CustomResourceProvides 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
## 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 ```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()); } }
-
-
Constructor Summary
Constructors Constructor Description UserPolicy(java.lang.String name)UserPolicy(java.lang.String name, UserPolicyArgs args)UserPolicy(java.lang.String name, UserPolicyArgs args, com.pulumi.resources.CustomResourceOptions options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static UserPolicyget(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()
-
-
-
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.
-
-