PolicyAttachmentArgs

data class PolicyAttachmentArgs(val groups: Output<List<String>>? = null, val name: Output<String>? = null, val policyArn: Output<String>? = null, val roles: Output<List<String>>? = null, val users: Output<List<String>>? = null) : ConvertibleToJava<PolicyAttachmentArgs>

Attaches a Managed IAM Policy to user(s), role(s), and/or group(s) !>WARNING: The aws.iam.PolicyAttachment resource creates exclusive attachments of IAM policies. Across the entire AWS account, all of the users/roles/groups to which a single policy is attached must be declared by a single aws.iam.PolicyAttachment resource. This means that even any users/roles/groups that have the attached policy via any other mechanism (including other resources managed by this provider) will have that attached policy revoked by this resource. Consider aws.iam.RolePolicyAttachment, aws.iam.UserPolicyAttachment, or aws.iam.GroupPolicyAttachment instead. These resources do not enforce exclusive attachment of an IAM policy.

NOTE: The usage of this resource conflicts with the aws.iam.GroupPolicyAttachment, aws.iam.RolePolicyAttachment, and aws.iam.UserPolicyAttachment resources 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 the provider will show a permanent difference.

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.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.Group;
import com.pulumi.aws.iam.Policy;
import com.pulumi.aws.iam.PolicyArgs;
import com.pulumi.aws.iam.PolicyAttachment;
import com.pulumi.aws.iam.PolicyAttachmentArgs;
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 user = new User("user");
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()
.assumeRolePolicy(assumeRole.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json()))
.build());
var group = new Group("group");
final var policyPolicyDocument = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.effect("Allow")
.actions("ec2:Describe*")
.resources("*")
.build())
.build());
var policyPolicy = new Policy("policyPolicy", PolicyArgs.builder()
.description("A test policy")
.policy(policyPolicyDocument.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json()))
.build());
var test_attach = new PolicyAttachment("test-attach", PolicyAttachmentArgs.builder()
.users(user.name())
.roles(role.name())
.groups(group.name())
.policyArn(policyPolicy.arn())
.build());
}
}

Constructors

Link copied to clipboard
constructor(groups: Output<List<String>>? = null, name: Output<String>? = null, policyArn: Output<String>? = null, roles: Output<List<String>>? = null, users: Output<List<String>>? = null)

Properties

Link copied to clipboard
val groups: Output<List<String>>? = null

The group(s) the policy should be applied to

Link copied to clipboard
val name: Output<String>? = null

The name of the attachment. This cannot be an empty string.

Link copied to clipboard
val policyArn: Output<String>? = null

The ARN of the policy you want to apply

Link copied to clipboard
val roles: Output<List<String>>? = null

The role(s) the policy should be applied to

Link copied to clipboard
val users: Output<List<String>>? = null

The user(s) the policy should be applied to

Functions

Link copied to clipboard
open override fun toJava(): PolicyAttachmentArgs