github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/iam/policy.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.
    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  //			tmpJSON0, err := json.Marshal(map[string]interface{}{
    37  //				"Version": "2012-10-17",
    38  //				"Statement": []map[string]interface{}{
    39  //					map[string]interface{}{
    40  //						"Action": []string{
    41  //							"ec2:Describe*",
    42  //						},
    43  //						"Effect":   "Allow",
    44  //						"Resource": "*",
    45  //					},
    46  //				},
    47  //			})
    48  //			if err != nil {
    49  //				return err
    50  //			}
    51  //			json0 := string(tmpJSON0)
    52  //			_, err = iam.NewPolicy(ctx, "policy", &iam.PolicyArgs{
    53  //				Name:        pulumi.String("test_policy"),
    54  //				Path:        pulumi.String("/"),
    55  //				Description: pulumi.String("My test policy"),
    56  //				Policy:      pulumi.String(json0),
    57  //			})
    58  //			if err != nil {
    59  //				return err
    60  //			}
    61  //			return nil
    62  //		})
    63  //	}
    64  //
    65  // ```
    66  // <!--End PulumiCodeChooser -->
    67  //
    68  // ## Import
    69  //
    70  // Using `pulumi import`, import IAM Policies using the `arn`. For example:
    71  //
    72  // ```sh
    73  // $ pulumi import aws:iam/policy:Policy administrator arn:aws:iam::123456789012:policy/UsersManageOwnCredentials
    74  // ```
    75  type Policy struct {
    76  	pulumi.CustomResourceState
    77  
    78  	// ARN assigned by AWS to this policy.
    79  	Arn pulumi.StringOutput `pulumi:"arn"`
    80  	// Number of entities (users, groups, and roles) that the policy is attached to.
    81  	AttachmentCount pulumi.IntOutput `pulumi:"attachmentCount"`
    82  	// Description of the IAM policy.
    83  	Description pulumi.StringPtrOutput `pulumi:"description"`
    84  	// Name of the policy. If omitted, the provider will assign a random, unique name.
    85  	Name pulumi.StringOutput `pulumi:"name"`
    86  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
    87  	NamePrefix pulumi.StringOutput `pulumi:"namePrefix"`
    88  	// Path in which to create the policy. See [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html) for more information.
    89  	Path pulumi.StringPtrOutput `pulumi:"path"`
    90  	// Policy document. This is a JSON formatted string. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide
    91  	Policy pulumi.StringOutput `pulumi:"policy"`
    92  	// Policy's ID.
    93  	PolicyId pulumi.StringOutput `pulumi:"policyId"`
    94  	// Map of resource tags for the IAM Policy. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
    95  	Tags pulumi.StringMapOutput `pulumi:"tags"`
    96  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
    97  	//
    98  	// Deprecated: Please use `tags` instead.
    99  	TagsAll pulumi.StringMapOutput `pulumi:"tagsAll"`
   100  }
   101  
   102  // NewPolicy registers a new resource with the given unique name, arguments, and options.
   103  func NewPolicy(ctx *pulumi.Context,
   104  	name string, args *PolicyArgs, opts ...pulumi.ResourceOption) (*Policy, error) {
   105  	if args == nil {
   106  		return nil, errors.New("missing one or more required arguments")
   107  	}
   108  
   109  	if args.Policy == nil {
   110  		return nil, errors.New("invalid value for required argument 'Policy'")
   111  	}
   112  	opts = internal.PkgResourceDefaultOpts(opts)
   113  	var resource Policy
   114  	err := ctx.RegisterResource("aws:iam/policy:Policy", name, args, &resource, opts...)
   115  	if err != nil {
   116  		return nil, err
   117  	}
   118  	return &resource, nil
   119  }
   120  
   121  // GetPolicy gets an existing Policy resource's state with the given name, ID, and optional
   122  // state properties that are used to uniquely qualify the lookup (nil if not required).
   123  func GetPolicy(ctx *pulumi.Context,
   124  	name string, id pulumi.IDInput, state *PolicyState, opts ...pulumi.ResourceOption) (*Policy, error) {
   125  	var resource Policy
   126  	err := ctx.ReadResource("aws:iam/policy:Policy", name, id, state, &resource, opts...)
   127  	if err != nil {
   128  		return nil, err
   129  	}
   130  	return &resource, nil
   131  }
   132  
   133  // Input properties used for looking up and filtering Policy resources.
   134  type policyState struct {
   135  	// ARN assigned by AWS to this policy.
   136  	Arn *string `pulumi:"arn"`
   137  	// Number of entities (users, groups, and roles) that the policy is attached to.
   138  	AttachmentCount *int `pulumi:"attachmentCount"`
   139  	// Description of the IAM policy.
   140  	Description *string `pulumi:"description"`
   141  	// Name of the policy. If omitted, the provider will assign a random, unique name.
   142  	Name *string `pulumi:"name"`
   143  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   144  	NamePrefix *string `pulumi:"namePrefix"`
   145  	// Path in which to create the policy. See [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html) for more information.
   146  	Path *string `pulumi:"path"`
   147  	// Policy document. This is a JSON formatted string. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide
   148  	Policy interface{} `pulumi:"policy"`
   149  	// Policy's ID.
   150  	PolicyId *string `pulumi:"policyId"`
   151  	// Map of resource tags for the IAM Policy. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   152  	Tags map[string]string `pulumi:"tags"`
   153  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   154  	//
   155  	// Deprecated: Please use `tags` instead.
   156  	TagsAll map[string]string `pulumi:"tagsAll"`
   157  }
   158  
   159  type PolicyState struct {
   160  	// ARN assigned by AWS to this policy.
   161  	Arn pulumi.StringPtrInput
   162  	// Number of entities (users, groups, and roles) that the policy is attached to.
   163  	AttachmentCount pulumi.IntPtrInput
   164  	// Description of the IAM policy.
   165  	Description pulumi.StringPtrInput
   166  	// Name of the policy. If omitted, the provider will assign a random, unique name.
   167  	Name pulumi.StringPtrInput
   168  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   169  	NamePrefix pulumi.StringPtrInput
   170  	// Path in which to create the policy. See [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html) for more information.
   171  	Path pulumi.StringPtrInput
   172  	// Policy document. This is a JSON formatted string. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide
   173  	Policy pulumi.Input
   174  	// Policy's ID.
   175  	PolicyId pulumi.StringPtrInput
   176  	// Map of resource tags for the IAM Policy. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   177  	Tags pulumi.StringMapInput
   178  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   179  	//
   180  	// Deprecated: Please use `tags` instead.
   181  	TagsAll pulumi.StringMapInput
   182  }
   183  
   184  func (PolicyState) ElementType() reflect.Type {
   185  	return reflect.TypeOf((*policyState)(nil)).Elem()
   186  }
   187  
   188  type policyArgs struct {
   189  	// Description of the IAM policy.
   190  	Description *string `pulumi:"description"`
   191  	// Name of the policy. If omitted, the provider will assign a random, unique name.
   192  	Name *string `pulumi:"name"`
   193  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   194  	NamePrefix *string `pulumi:"namePrefix"`
   195  	// Path in which to create the policy. See [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html) for more information.
   196  	Path *string `pulumi:"path"`
   197  	// Policy document. This is a JSON formatted string. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide
   198  	Policy interface{} `pulumi:"policy"`
   199  	// Map of resource tags for the IAM Policy. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   200  	Tags map[string]string `pulumi:"tags"`
   201  }
   202  
   203  // The set of arguments for constructing a Policy resource.
   204  type PolicyArgs struct {
   205  	// Description of the IAM policy.
   206  	Description pulumi.StringPtrInput
   207  	// Name of the policy. If omitted, the provider will assign a random, unique name.
   208  	Name pulumi.StringPtrInput
   209  	// Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   210  	NamePrefix pulumi.StringPtrInput
   211  	// Path in which to create the policy. See [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html) for more information.
   212  	Path pulumi.StringPtrInput
   213  	// Policy document. This is a JSON formatted string. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide
   214  	Policy pulumi.Input
   215  	// Map of resource tags for the IAM Policy. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   216  	Tags pulumi.StringMapInput
   217  }
   218  
   219  func (PolicyArgs) ElementType() reflect.Type {
   220  	return reflect.TypeOf((*policyArgs)(nil)).Elem()
   221  }
   222  
   223  type PolicyInput interface {
   224  	pulumi.Input
   225  
   226  	ToPolicyOutput() PolicyOutput
   227  	ToPolicyOutputWithContext(ctx context.Context) PolicyOutput
   228  }
   229  
   230  func (*Policy) ElementType() reflect.Type {
   231  	return reflect.TypeOf((**Policy)(nil)).Elem()
   232  }
   233  
   234  func (i *Policy) ToPolicyOutput() PolicyOutput {
   235  	return i.ToPolicyOutputWithContext(context.Background())
   236  }
   237  
   238  func (i *Policy) ToPolicyOutputWithContext(ctx context.Context) PolicyOutput {
   239  	return pulumi.ToOutputWithContext(ctx, i).(PolicyOutput)
   240  }
   241  
   242  // PolicyArrayInput is an input type that accepts PolicyArray and PolicyArrayOutput values.
   243  // You can construct a concrete instance of `PolicyArrayInput` via:
   244  //
   245  //	PolicyArray{ PolicyArgs{...} }
   246  type PolicyArrayInput interface {
   247  	pulumi.Input
   248  
   249  	ToPolicyArrayOutput() PolicyArrayOutput
   250  	ToPolicyArrayOutputWithContext(context.Context) PolicyArrayOutput
   251  }
   252  
   253  type PolicyArray []PolicyInput
   254  
   255  func (PolicyArray) ElementType() reflect.Type {
   256  	return reflect.TypeOf((*[]*Policy)(nil)).Elem()
   257  }
   258  
   259  func (i PolicyArray) ToPolicyArrayOutput() PolicyArrayOutput {
   260  	return i.ToPolicyArrayOutputWithContext(context.Background())
   261  }
   262  
   263  func (i PolicyArray) ToPolicyArrayOutputWithContext(ctx context.Context) PolicyArrayOutput {
   264  	return pulumi.ToOutputWithContext(ctx, i).(PolicyArrayOutput)
   265  }
   266  
   267  // PolicyMapInput is an input type that accepts PolicyMap and PolicyMapOutput values.
   268  // You can construct a concrete instance of `PolicyMapInput` via:
   269  //
   270  //	PolicyMap{ "key": PolicyArgs{...} }
   271  type PolicyMapInput interface {
   272  	pulumi.Input
   273  
   274  	ToPolicyMapOutput() PolicyMapOutput
   275  	ToPolicyMapOutputWithContext(context.Context) PolicyMapOutput
   276  }
   277  
   278  type PolicyMap map[string]PolicyInput
   279  
   280  func (PolicyMap) ElementType() reflect.Type {
   281  	return reflect.TypeOf((*map[string]*Policy)(nil)).Elem()
   282  }
   283  
   284  func (i PolicyMap) ToPolicyMapOutput() PolicyMapOutput {
   285  	return i.ToPolicyMapOutputWithContext(context.Background())
   286  }
   287  
   288  func (i PolicyMap) ToPolicyMapOutputWithContext(ctx context.Context) PolicyMapOutput {
   289  	return pulumi.ToOutputWithContext(ctx, i).(PolicyMapOutput)
   290  }
   291  
   292  type PolicyOutput struct{ *pulumi.OutputState }
   293  
   294  func (PolicyOutput) ElementType() reflect.Type {
   295  	return reflect.TypeOf((**Policy)(nil)).Elem()
   296  }
   297  
   298  func (o PolicyOutput) ToPolicyOutput() PolicyOutput {
   299  	return o
   300  }
   301  
   302  func (o PolicyOutput) ToPolicyOutputWithContext(ctx context.Context) PolicyOutput {
   303  	return o
   304  }
   305  
   306  // ARN assigned by AWS to this policy.
   307  func (o PolicyOutput) Arn() pulumi.StringOutput {
   308  	return o.ApplyT(func(v *Policy) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput)
   309  }
   310  
   311  // Number of entities (users, groups, and roles) that the policy is attached to.
   312  func (o PolicyOutput) AttachmentCount() pulumi.IntOutput {
   313  	return o.ApplyT(func(v *Policy) pulumi.IntOutput { return v.AttachmentCount }).(pulumi.IntOutput)
   314  }
   315  
   316  // Description of the IAM policy.
   317  func (o PolicyOutput) Description() pulumi.StringPtrOutput {
   318  	return o.ApplyT(func(v *Policy) pulumi.StringPtrOutput { return v.Description }).(pulumi.StringPtrOutput)
   319  }
   320  
   321  // Name of the policy. If omitted, the provider will assign a random, unique name.
   322  func (o PolicyOutput) Name() pulumi.StringOutput {
   323  	return o.ApplyT(func(v *Policy) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
   324  }
   325  
   326  // Creates a unique name beginning with the specified prefix. Conflicts with `name`.
   327  func (o PolicyOutput) NamePrefix() pulumi.StringOutput {
   328  	return o.ApplyT(func(v *Policy) pulumi.StringOutput { return v.NamePrefix }).(pulumi.StringOutput)
   329  }
   330  
   331  // Path in which to create the policy. See [IAM Identifiers](https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html) for more information.
   332  func (o PolicyOutput) Path() pulumi.StringPtrOutput {
   333  	return o.ApplyT(func(v *Policy) pulumi.StringPtrOutput { return v.Path }).(pulumi.StringPtrOutput)
   334  }
   335  
   336  // Policy document. This is a JSON formatted string. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide
   337  func (o PolicyOutput) Policy() pulumi.StringOutput {
   338  	return o.ApplyT(func(v *Policy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput)
   339  }
   340  
   341  // Policy's ID.
   342  func (o PolicyOutput) PolicyId() pulumi.StringOutput {
   343  	return o.ApplyT(func(v *Policy) pulumi.StringOutput { return v.PolicyId }).(pulumi.StringOutput)
   344  }
   345  
   346  // Map of resource tags for the IAM Policy. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   347  func (o PolicyOutput) Tags() pulumi.StringMapOutput {
   348  	return o.ApplyT(func(v *Policy) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput)
   349  }
   350  
   351  // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   352  //
   353  // Deprecated: Please use `tags` instead.
   354  func (o PolicyOutput) TagsAll() pulumi.StringMapOutput {
   355  	return o.ApplyT(func(v *Policy) pulumi.StringMapOutput { return v.TagsAll }).(pulumi.StringMapOutput)
   356  }
   357  
   358  type PolicyArrayOutput struct{ *pulumi.OutputState }
   359  
   360  func (PolicyArrayOutput) ElementType() reflect.Type {
   361  	return reflect.TypeOf((*[]*Policy)(nil)).Elem()
   362  }
   363  
   364  func (o PolicyArrayOutput) ToPolicyArrayOutput() PolicyArrayOutput {
   365  	return o
   366  }
   367  
   368  func (o PolicyArrayOutput) ToPolicyArrayOutputWithContext(ctx context.Context) PolicyArrayOutput {
   369  	return o
   370  }
   371  
   372  func (o PolicyArrayOutput) Index(i pulumi.IntInput) PolicyOutput {
   373  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Policy {
   374  		return vs[0].([]*Policy)[vs[1].(int)]
   375  	}).(PolicyOutput)
   376  }
   377  
   378  type PolicyMapOutput struct{ *pulumi.OutputState }
   379  
   380  func (PolicyMapOutput) ElementType() reflect.Type {
   381  	return reflect.TypeOf((*map[string]*Policy)(nil)).Elem()
   382  }
   383  
   384  func (o PolicyMapOutput) ToPolicyMapOutput() PolicyMapOutput {
   385  	return o
   386  }
   387  
   388  func (o PolicyMapOutput) ToPolicyMapOutputWithContext(ctx context.Context) PolicyMapOutput {
   389  	return o
   390  }
   391  
   392  func (o PolicyMapOutput) MapIndex(k pulumi.StringInput) PolicyOutput {
   393  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Policy {
   394  		return vs[0].(map[string]*Policy)[vs[1].(string)]
   395  	}).(PolicyOutput)
   396  }
   397  
   398  func init() {
   399  	pulumi.RegisterInputType(reflect.TypeOf((*PolicyInput)(nil)).Elem(), &Policy{})
   400  	pulumi.RegisterInputType(reflect.TypeOf((*PolicyArrayInput)(nil)).Elem(), PolicyArray{})
   401  	pulumi.RegisterInputType(reflect.TypeOf((*PolicyMapInput)(nil)).Elem(), PolicyMap{})
   402  	pulumi.RegisterOutputType(PolicyOutput{})
   403  	pulumi.RegisterOutputType(PolicyArrayOutput{})
   404  	pulumi.RegisterOutputType(PolicyMapOutput{})
   405  }