com.pulumi.aws.iam.PolicyAttachment 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.
// *** 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.PolicyAttachmentArgs;
import com.pulumi.aws.iam.inputs.PolicyAttachmentState;
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 java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
/**
* ## 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.User;
* import com.pulumi.aws.iam.UserArgs;
* 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.GroupArgs;
* 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", UserArgs.builder()
* .name("test-user")
* .build());
*
* 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());
*
* var group = new Group("group", GroupArgs.builder()
* .name("test-group")
* .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 PolicyAttachment("test-attach", PolicyAttachmentArgs.builder()
* .name("test-attachment")
* .users(user.name())
* .roles(role.name())
* .groups(group.name())
* .policyArn(policyPolicy.arn())
* .build());
*
* }
* }
* }
*
* <!--End PulumiCodeChooser -->
*
*/
@ResourceType(type="aws:iam/policyAttachment:PolicyAttachment")
public class PolicyAttachment extends com.pulumi.resources.CustomResource {
/**
* Group(s) the policy should be applied to.
*
*/
@Export(name="groups", refs={List.class,String.class}, tree="[0,1]")
private Output* @Nullable */ List> groups;
/**
* @return Group(s) the policy should be applied to.
*
*/
public Output>> groups() {
return Codegen.optional(this.groups);
}
/**
* Name of the attachment. This cannot be an empty string.
*
*/
@Export(name="name", refs={String.class}, tree="[0]")
private Output name;
/**
* @return Name of the attachment. This cannot be an empty string.
*
*/
public Output name() {
return this.name;
}
/**
* ARN of the policy you want to apply. Typically this should be a reference to the ARN of another resource to ensure dependency ordering, such as `aws_iam_policy.example.arn`.
*
*/
@Export(name="policyArn", refs={String.class}, tree="[0]")
private Output policyArn;
/**
* @return ARN of the policy you want to apply. Typically this should be a reference to the ARN of another resource to ensure dependency ordering, such as `aws_iam_policy.example.arn`.
*
*/
public Output policyArn() {
return this.policyArn;
}
/**
* Role(s) the policy should be applied to.
*
*/
@Export(name="roles", refs={List.class,String.class}, tree="[0,1]")
private Output* @Nullable */ List> roles;
/**
* @return Role(s) the policy should be applied to.
*
*/
public Output>> roles() {
return Codegen.optional(this.roles);
}
/**
* User(s) the policy should be applied to.
*
*/
@Export(name="users", refs={List.class,String.class}, tree="[0,1]")
private Output* @Nullable */ List> users;
/**
* @return User(s) the policy should be applied to.
*
*/
public Output>> users() {
return Codegen.optional(this.users);
}
/**
*
* @param name The _unique_ name of the resulting resource.
*/
public PolicyAttachment(java.lang.String name) {
this(name, PolicyAttachmentArgs.Empty);
}
/**
*
* @param name The _unique_ name of the resulting resource.
* @param args The arguments to use to populate this resource's properties.
*/
public PolicyAttachment(java.lang.String name, PolicyAttachmentArgs 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 PolicyAttachment(java.lang.String name, PolicyAttachmentArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) {
super("aws:iam/policyAttachment:PolicyAttachment", name, makeArgs(args, options), makeResourceOptions(options, Codegen.empty()), false);
}
private PolicyAttachment(java.lang.String name, Output id, @Nullable PolicyAttachmentState state, @Nullable com.pulumi.resources.CustomResourceOptions options) {
super("aws:iam/policyAttachment:PolicyAttachment", name, state, makeResourceOptions(options, id), false);
}
private static PolicyAttachmentArgs makeArgs(PolicyAttachmentArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options) {
if (options != null && options.getUrn().isPresent()) {
return null;
}
return args == null ? PolicyAttachmentArgs.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 PolicyAttachment get(java.lang.String name, Output id, @Nullable PolicyAttachmentState state, @Nullable com.pulumi.resources.CustomResourceOptions options) {
return new PolicyAttachment(name, id, state, options);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy