com.pulumi.aws.iam.RolePolicyAttachment Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws Show documentation
Show all versions of aws Show documentation
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
The newest version!
// *** 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.RolePolicyAttachmentArgs;
import com.pulumi.aws.iam.inputs.RolePolicyAttachmentState;
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;
/**
* Attaches 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 `managed_policy_arns` 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
*
* <!--Start PulumiCodeChooser -->
*
* {@code
* 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.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.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) {
* final var assumeRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
* .statements(GetPolicyDocumentStatementArgs.builder()
* .effect("Allow")
* .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
* .type("Service")
* .identifiers("ec2.amazonaws.com")
* .build())
* .actions("sts:AssumeRole")
* .build())
* .build());
*
* var role = new Role("role", RoleArgs.builder()
* .name("test-role")
* .assumeRolePolicy(assumeRole.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.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.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json()))
* .build());
*
* var test_attach = new RolePolicyAttachment("test-attach", RolePolicyAttachmentArgs.builder()
* .role(role.name())
* .policyArn(policyPolicy.arn())
* .build());
*
* }
* }
* }
*
* <!--End PulumiCodeChooser -->
*
* ## Import
*
* 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 test-attach test-role/arn:aws:iam::xxxxxxxxxxxx:policy/test-policy
* ```
*
*/
@ResourceType(type="aws:iam/rolePolicyAttachment:RolePolicyAttachment")
public class RolePolicyAttachment extends com.pulumi.resources.CustomResource {
/**
* The ARN of the policy you want to apply
*
*/
@Export(name="policyArn", refs={String.class}, tree="[0]")
private Output policyArn;
/**
* @return The ARN of the policy you want to apply
*
*/
public Output policyArn() {
return this.policyArn;
}
/**
* The name of the IAM role to which the policy should be applied
*
*/
@Export(name="role", refs={String.class}, tree="[0]")
private Output role;
/**
* @return The name of the IAM role to which the policy should be applied
*
*/
public Output role() {
return this.role;
}
/**
*
* @param name The _unique_ name of the resulting resource.
*/
public RolePolicyAttachment(java.lang.String name) {
this(name, RolePolicyAttachmentArgs.Empty);
}
/**
*
* @param name The _unique_ name of the resulting resource.
* @param args The arguments to use to populate this resource's properties.
*/
public RolePolicyAttachment(java.lang.String name, RolePolicyAttachmentArgs 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 RolePolicyAttachment(java.lang.String name, RolePolicyAttachmentArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) {
super("aws:iam/rolePolicyAttachment:RolePolicyAttachment", name, makeArgs(args, options), makeResourceOptions(options, Codegen.empty()), false);
}
private RolePolicyAttachment(java.lang.String name, Output id, @Nullable RolePolicyAttachmentState state, @Nullable com.pulumi.resources.CustomResourceOptions options) {
super("aws:iam/rolePolicyAttachment:RolePolicyAttachment", name, state, makeResourceOptions(options, id), false);
}
private static RolePolicyAttachmentArgs makeArgs(RolePolicyAttachmentArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) {
if (options != null && options.getUrn().isPresent()) {
return null;
}
return args == null ? RolePolicyAttachmentArgs.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 RolePolicyAttachment get(java.lang.String name, Output id, @Nullable RolePolicyAttachmentState state, @Nullable com.pulumi.resources.CustomResourceOptions options) {
return new RolePolicyAttachment(name, id, state, options);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy