
com.pulumi.aws.iam.RolePolicy Maven / Gradle / Ivy
// *** WARNING: this file was generated by pulumi-java-gen. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package com.pulumi.aws.iam;
import com.pulumi.aws.Utilities;
import com.pulumi.aws.iam.RolePolicyArgs;
import com.pulumi.aws.iam.inputs.RolePolicyState;
import com.pulumi.core.Output;
import com.pulumi.core.annotations.Export;
import com.pulumi.core.annotations.ResourceType;
import com.pulumi.core.internal.Codegen;
import java.lang.String;
import javax.annotation.Nullable;
/**
* Provides an IAM role inline policy.
*
* > **NOTE:** For a given role, this resource is incompatible with using the `aws.iam.Role` resource `inline_policy` 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
*
* <!--Start PulumiCodeChooser -->
*
* {@code
* 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.List;
* import java.util.ArrayList;
* 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());
*
* }
* }
* }
*
* <!--End PulumiCodeChooser -->
*
* ## Import
*
* Using `pulumi import`, import IAM Role Policies using the `role_name:role_policy_name`. For example:
*
* ```sh
* $ pulumi import aws:iam/rolePolicy:RolePolicy mypolicy role_of_mypolicy_name:mypolicy_name
* ```
*
*/
@ResourceType(type="aws:iam/rolePolicy:RolePolicy")
public class RolePolicy extends com.pulumi.resources.CustomResource {
/**
* The name of the role policy. If omitted, this provider will
* assign a random, unique name.
*
*/
@Export(name="name", refs={String.class}, tree="[0]")
private Output name;
/**
* @return The name of the role policy. If omitted, this provider will
* assign a random, unique name.
*
*/
public Output name() {
return this.name;
}
/**
* Creates a unique name beginning with the specified
* prefix. Conflicts with `name`.
*
*/
@Export(name="namePrefix", refs={String.class}, tree="[0]")
private Output namePrefix;
/**
* @return Creates a unique name beginning with the specified
* prefix. Conflicts with `name`.
*
*/
public Output namePrefix() {
return this.namePrefix;
}
/**
* The inline policy document. This is a JSON formatted string. For more information about building IAM policy documents with the provider, see the AWS IAM Policy Document Guide
*
*/
@Export(name="policy", refs={String.class}, tree="[0]")
private Output policy;
/**
* @return The inline policy document. This is a JSON formatted string. For more information about building IAM policy documents with the provider, see the AWS IAM Policy Document Guide
*
*/
public Output policy() {
return this.policy;
}
/**
* The name of the IAM role to attach to the policy.
*
*/
@Export(name="role", refs={String.class}, tree="[0]")
private Output role;
/**
* @return The name of the IAM role to attach to the policy.
*
*/
public Output role() {
return this.role;
}
/**
*
* @param name The _unique_ name of the resulting resource.
*/
public RolePolicy(java.lang.String name) {
this(name, RolePolicyArgs.Empty);
}
/**
*
* @param name The _unique_ name of the resulting resource.
* @param args The arguments to use to populate this resource's properties.
*/
public RolePolicy(java.lang.String name, RolePolicyArgs args) {
this(name, args, null);
}
/**
*
* @param name The _unique_ name of the resulting resource.
* @param args The arguments to use to populate this resource's properties.
* @param options A bag of options that control this resource's behavior.
*/
public RolePolicy(java.lang.String name, RolePolicyArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) {
super("aws:iam/rolePolicy:RolePolicy", name, makeArgs(args, options), makeResourceOptions(options, Codegen.empty()), false);
}
private RolePolicy(java.lang.String name, Output id, @Nullable RolePolicyState state, @Nullable com.pulumi.resources.CustomResourceOptions options) {
super("aws:iam/rolePolicy:RolePolicy", name, state, makeResourceOptions(options, id), false);
}
private static RolePolicyArgs makeArgs(RolePolicyArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) {
if (options != null && options.getUrn().isPresent()) {
return null;
}
return args == null ? RolePolicyArgs.Empty : args;
}
private static com.pulumi.resources.CustomResourceOptions makeResourceOptions(@Nullable com.pulumi.resources.CustomResourceOptions options, @Nullable Output id) {
var defaultOptions = com.pulumi.resources.CustomResourceOptions.builder()
.version(Utilities.getVersion())
.build();
return com.pulumi.resources.CustomResourceOptions.merge(defaultOptions, options, id);
}
/**
* Get an existing Host resource's state with the given name, ID, and optional extra
* properties used to qualify the lookup.
*
* @param name The _unique_ name of the resulting resource.
* @param id The _unique_ provider ID of the resource to lookup.
* @param state
* @param options Optional settings to control the behavior of the CustomResource.
*/
public static RolePolicy get(java.lang.String name, Output id, @Nullable RolePolicyState state, @Nullable com.pulumi.resources.CustomResourceOptions options) {
return new RolePolicy(name, id, state, options);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy