github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iam/userPolicy.go (about)

     1  // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package iam
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"errors"
    11  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    12  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    13  )
    14  
    15  // Provides an IAM policy attached to a user.
    16  //
    17  // > **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.
    18  //
    19  // ## Example Usage
    20  //
    21  // <!--Start PulumiCodeChooser -->
    22  // ```go
    23  // package main
    24  //
    25  // import (
    26  //
    27  //	"encoding/json"
    28  //
    29  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    30  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    31  //
    32  // )
    33  //
    34  //	func main() {
    35  //		pulumi.Run(func(ctx *pulumi.Context) error {
    36  //			lb, err := iam.NewUser(ctx, "lb", &iam.UserArgs{
    37  //				Name: pulumi.String("loadbalancer"),
    38  //				Path: pulumi.String("/system/"),
    39  //			})
    40  //			if err != nil {
    41  //				return err
    42  //			}
    43  //			tmpJSON0, err := json.Marshal(map[string]interface{}{
    44  //				"Version": "2012-10-17",
    45  //				"Statement": []map[string]interface{}{
    46  //					map[string]interface{}{
    47  //						"Action": []string{
    48  //							"ec2:Describe*",
    49  //						},
    50  //						"Effect":   "Allow",
    51  //						"Resource": "*",
    52  //					},
    53  //				},
    54  //			})
    55  //			if err != nil {
    56  //				return err
    57  //			}
    58  //			json0 := string(tmpJSON0)
    59  //			_, err = iam.NewUserPolicy(ctx, "lb_ro", &iam.UserPolicyArgs{
    60  //				Name:   pulumi.String("test"),
    61  //				User:   lb.Name,
    62  //				Policy: pulumi.String(json0),
    63  //			})
    64  //			if err != nil {
    65  //				return err
    66  //			}
    67  //			_, err = iam.NewAccessKey(ctx, "lb", &iam.AccessKeyArgs{
    68  //				User: lb.Name,
    69  //			})
    70  //			if err != nil {
    71  //				return err
    72  //			}
    73  //			return nil
    74  //		})
    75  //	}
    76  //
    77  // ```
    78  // <!--End PulumiCodeChooser -->
    79  //
    80  // ## Import
    81  //
    82  // Using `pulumi import`, import IAM User Policies using the `user_name:user_policy_name`. For example:
    83  //
    84  // ```sh
    85  // $ pulumi import aws:iam/userPolicy:UserPolicy mypolicy user_of_mypolicy_name:mypolicy_name
    86  // ```
    87  type UserPolicy struct {
    88  	pulumi.CustomResourceState
    89  
    90  	// The name of the policy. If omitted, the provider will assign a random, unique name.
    91  	Name pulumi.StringOutput `pulumi:"name"`
    92  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
    93  	NamePrefix pulumi.StringOutput `pulumi:"namePrefix"`
    94  	// The policy document. This is a JSON formatted string.
    95  	Policy pulumi.StringOutput `pulumi:"policy"`
    96  	// IAM user to which to attach this policy.
    97  	User pulumi.StringOutput `pulumi:"user"`
    98  }
    99  
   100  // NewUserPolicy registers a new resource with the given unique name, arguments, and options.
   101  func NewUserPolicy(ctx *pulumi.Context,
   102  	name string, args *UserPolicyArgs, opts ...pulumi.ResourceOption) (*UserPolicy, error) {
   103  	if args == nil {
   104  		return nil, errors.New("missing one or more required arguments")
   105  	}
   106  
   107  	if args.Policy == nil {
   108  		return nil, errors.New("invalid value for required argument 'Policy'")
   109  	}
   110  	if args.User == nil {
   111  		return nil, errors.New("invalid value for required argument 'User'")
   112  	}
   113  	opts = internal.PkgResourceDefaultOpts(opts)
   114  	var resource UserPolicy
   115  	err := ctx.RegisterResource("aws:iam/userPolicy:UserPolicy", name, args, &resource, opts...)
   116  	if err != nil {
   117  		return nil, err
   118  	}
   119  	return &resource, nil
   120  }
   121  
   122  // GetUserPolicy gets an existing UserPolicy resource's state with the given name, ID, and optional
   123  // state properties that are used to uniquely qualify the lookup (nil if not required).
   124  func GetUserPolicy(ctx *pulumi.Context,
   125  	name string, id pulumi.IDInput, state *UserPolicyState, opts ...pulumi.ResourceOption) (*UserPolicy, error) {
   126  	var resource UserPolicy
   127  	err := ctx.ReadResource("aws:iam/userPolicy:UserPolicy", name, id, state, &resource, opts...)
   128  	if err != nil {
   129  		return nil, err
   130  	}
   131  	return &resource, nil
   132  }
   133  
   134  // Input properties used for looking up and filtering UserPolicy resources.
   135  type userPolicyState struct {
   136  	// The name of the policy. If omitted, the provider will assign a random, unique name.
   137  	Name *string `pulumi:"name"`
   138  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   139  	NamePrefix *string `pulumi:"namePrefix"`
   140  	// The policy document. This is a JSON formatted string.
   141  	Policy interface{} `pulumi:"policy"`
   142  	// IAM user to which to attach this policy.
   143  	User *string `pulumi:"user"`
   144  }
   145  
   146  type UserPolicyState struct {
   147  	// The name of the policy. If omitted, the provider will assign a random, unique name.
   148  	Name pulumi.StringPtrInput
   149  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   150  	NamePrefix pulumi.StringPtrInput
   151  	// The policy document. This is a JSON formatted string.
   152  	Policy pulumi.Input
   153  	// IAM user to which to attach this policy.
   154  	User pulumi.StringPtrInput
   155  }
   156  
   157  func (UserPolicyState) ElementType() reflect.Type {
   158  	return reflect.TypeOf((*userPolicyState)(nil)).Elem()
   159  }
   160  
   161  type userPolicyArgs struct {
   162  	// The name of the policy. If omitted, the provider will assign a random, unique name.
   163  	Name *string `pulumi:"name"`
   164  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   165  	NamePrefix *string `pulumi:"namePrefix"`
   166  	// The policy document. This is a JSON formatted string.
   167  	Policy interface{} `pulumi:"policy"`
   168  	// IAM user to which to attach this policy.
   169  	User string `pulumi:"user"`
   170  }
   171  
   172  // The set of arguments for constructing a UserPolicy resource.
   173  type UserPolicyArgs struct {
   174  	// The name of the policy. If omitted, the provider will assign a random, unique name.
   175  	Name pulumi.StringPtrInput
   176  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   177  	NamePrefix pulumi.StringPtrInput
   178  	// The policy document. This is a JSON formatted string.
   179  	Policy pulumi.Input
   180  	// IAM user to which to attach this policy.
   181  	User pulumi.StringInput
   182  }
   183  
   184  func (UserPolicyArgs) ElementType() reflect.Type {
   185  	return reflect.TypeOf((*userPolicyArgs)(nil)).Elem()
   186  }
   187  
   188  type UserPolicyInput interface {
   189  	pulumi.Input
   190  
   191  	ToUserPolicyOutput() UserPolicyOutput
   192  	ToUserPolicyOutputWithContext(ctx context.Context) UserPolicyOutput
   193  }
   194  
   195  func (*UserPolicy) ElementType() reflect.Type {
   196  	return reflect.TypeOf((**UserPolicy)(nil)).Elem()
   197  }
   198  
   199  func (i *UserPolicy) ToUserPolicyOutput() UserPolicyOutput {
   200  	return i.ToUserPolicyOutputWithContext(context.Background())
   201  }
   202  
   203  func (i *UserPolicy) ToUserPolicyOutputWithContext(ctx context.Context) UserPolicyOutput {
   204  	return pulumi.ToOutputWithContext(ctx, i).(UserPolicyOutput)
   205  }
   206  
   207  // UserPolicyArrayInput is an input type that accepts UserPolicyArray and UserPolicyArrayOutput values.
   208  // You can construct a concrete instance of `UserPolicyArrayInput` via:
   209  //
   210  //	UserPolicyArray{ UserPolicyArgs{...} }
   211  type UserPolicyArrayInput interface {
   212  	pulumi.Input
   213  
   214  	ToUserPolicyArrayOutput() UserPolicyArrayOutput
   215  	ToUserPolicyArrayOutputWithContext(context.Context) UserPolicyArrayOutput
   216  }
   217  
   218  type UserPolicyArray []UserPolicyInput
   219  
   220  func (UserPolicyArray) ElementType() reflect.Type {
   221  	return reflect.TypeOf((*[]*UserPolicy)(nil)).Elem()
   222  }
   223  
   224  func (i UserPolicyArray) ToUserPolicyArrayOutput() UserPolicyArrayOutput {
   225  	return i.ToUserPolicyArrayOutputWithContext(context.Background())
   226  }
   227  
   228  func (i UserPolicyArray) ToUserPolicyArrayOutputWithContext(ctx context.Context) UserPolicyArrayOutput {
   229  	return pulumi.ToOutputWithContext(ctx, i).(UserPolicyArrayOutput)
   230  }
   231  
   232  // UserPolicyMapInput is an input type that accepts UserPolicyMap and UserPolicyMapOutput values.
   233  // You can construct a concrete instance of `UserPolicyMapInput` via:
   234  //
   235  //	UserPolicyMap{ "key": UserPolicyArgs{...} }
   236  type UserPolicyMapInput interface {
   237  	pulumi.Input
   238  
   239  	ToUserPolicyMapOutput() UserPolicyMapOutput
   240  	ToUserPolicyMapOutputWithContext(context.Context) UserPolicyMapOutput
   241  }
   242  
   243  type UserPolicyMap map[string]UserPolicyInput
   244  
   245  func (UserPolicyMap) ElementType() reflect.Type {
   246  	return reflect.TypeOf((*map[string]*UserPolicy)(nil)).Elem()
   247  }
   248  
   249  func (i UserPolicyMap) ToUserPolicyMapOutput() UserPolicyMapOutput {
   250  	return i.ToUserPolicyMapOutputWithContext(context.Background())
   251  }
   252  
   253  func (i UserPolicyMap) ToUserPolicyMapOutputWithContext(ctx context.Context) UserPolicyMapOutput {
   254  	return pulumi.ToOutputWithContext(ctx, i).(UserPolicyMapOutput)
   255  }
   256  
   257  type UserPolicyOutput struct{ *pulumi.OutputState }
   258  
   259  func (UserPolicyOutput) ElementType() reflect.Type {
   260  	return reflect.TypeOf((**UserPolicy)(nil)).Elem()
   261  }
   262  
   263  func (o UserPolicyOutput) ToUserPolicyOutput() UserPolicyOutput {
   264  	return o
   265  }
   266  
   267  func (o UserPolicyOutput) ToUserPolicyOutputWithContext(ctx context.Context) UserPolicyOutput {
   268  	return o
   269  }
   270  
   271  // The name of the policy. If omitted, the provider will assign a random, unique name.
   272  func (o UserPolicyOutput) Name() pulumi.StringOutput {
   273  	return o.ApplyT(func(v *UserPolicy) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
   274  }
   275  
   276  // Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   277  func (o UserPolicyOutput) NamePrefix() pulumi.StringOutput {
   278  	return o.ApplyT(func(v *UserPolicy) pulumi.StringOutput { return v.NamePrefix }).(pulumi.StringOutput)
   279  }
   280  
   281  // The policy document. This is a JSON formatted string.
   282  func (o UserPolicyOutput) Policy() pulumi.StringOutput {
   283  	return o.ApplyT(func(v *UserPolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput)
   284  }
   285  
   286  // IAM user to which to attach this policy.
   287  func (o UserPolicyOutput) User() pulumi.StringOutput {
   288  	return o.ApplyT(func(v *UserPolicy) pulumi.StringOutput { return v.User }).(pulumi.StringOutput)
   289  }
   290  
   291  type UserPolicyArrayOutput struct{ *pulumi.OutputState }
   292  
   293  func (UserPolicyArrayOutput) ElementType() reflect.Type {
   294  	return reflect.TypeOf((*[]*UserPolicy)(nil)).Elem()
   295  }
   296  
   297  func (o UserPolicyArrayOutput) ToUserPolicyArrayOutput() UserPolicyArrayOutput {
   298  	return o
   299  }
   300  
   301  func (o UserPolicyArrayOutput) ToUserPolicyArrayOutputWithContext(ctx context.Context) UserPolicyArrayOutput {
   302  	return o
   303  }
   304  
   305  func (o UserPolicyArrayOutput) Index(i pulumi.IntInput) UserPolicyOutput {
   306  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *UserPolicy {
   307  		return vs[0].([]*UserPolicy)[vs[1].(int)]
   308  	}).(UserPolicyOutput)
   309  }
   310  
   311  type UserPolicyMapOutput struct{ *pulumi.OutputState }
   312  
   313  func (UserPolicyMapOutput) ElementType() reflect.Type {
   314  	return reflect.TypeOf((*map[string]*UserPolicy)(nil)).Elem()
   315  }
   316  
   317  func (o UserPolicyMapOutput) ToUserPolicyMapOutput() UserPolicyMapOutput {
   318  	return o
   319  }
   320  
   321  func (o UserPolicyMapOutput) ToUserPolicyMapOutputWithContext(ctx context.Context) UserPolicyMapOutput {
   322  	return o
   323  }
   324  
   325  func (o UserPolicyMapOutput) MapIndex(k pulumi.StringInput) UserPolicyOutput {
   326  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *UserPolicy {
   327  		return vs[0].(map[string]*UserPolicy)[vs[1].(string)]
   328  	}).(UserPolicyOutput)
   329  }
   330  
   331  func init() {
   332  	pulumi.RegisterInputType(reflect.TypeOf((*UserPolicyInput)(nil)).Elem(), &UserPolicy{})
   333  	pulumi.RegisterInputType(reflect.TypeOf((*UserPolicyArrayInput)(nil)).Elem(), UserPolicyArray{})
   334  	pulumi.RegisterInputType(reflect.TypeOf((*UserPolicyMapInput)(nil)).Elem(), UserPolicyMap{})
   335  	pulumi.RegisterOutputType(UserPolicyOutput{})
   336  	pulumi.RegisterOutputType(UserPolicyArrayOutput{})
   337  	pulumi.RegisterOutputType(UserPolicyMapOutput{})
   338  }