github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/s3/bucketPolicy.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 s3
     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  // Attaches a policy to an S3 bucket resource.
    16  //
    17  // > Policies can be attached to both S3 general purpose buckets and S3 directory buckets.
    18  //
    19  // ## Example Usage
    20  //
    21  // ### Basic Usage
    22  //
    23  // <!--Start PulumiCodeChooser -->
    24  // ```go
    25  // package main
    26  //
    27  // import (
    28  //
    29  //	"fmt"
    30  //
    31  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    32  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/s3"
    33  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    34  //
    35  // )
    36  //
    37  //	func main() {
    38  //		pulumi.Run(func(ctx *pulumi.Context) error {
    39  //			example, err := s3.NewBucketV2(ctx, "example", &s3.BucketV2Args{
    40  //				Bucket: pulumi.String("my-tf-test-bucket"),
    41  //			})
    42  //			if err != nil {
    43  //				return err
    44  //			}
    45  //			allowAccessFromAnotherAccount := iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
    46  //				Statements: iam.GetPolicyDocumentStatementArray{
    47  //					&iam.GetPolicyDocumentStatementArgs{
    48  //						Principals: iam.GetPolicyDocumentStatementPrincipalArray{
    49  //							&iam.GetPolicyDocumentStatementPrincipalArgs{
    50  //								Type: pulumi.String("AWS"),
    51  //								Identifiers: pulumi.StringArray{
    52  //									pulumi.String("123456789012"),
    53  //								},
    54  //							},
    55  //						},
    56  //						Actions: pulumi.StringArray{
    57  //							pulumi.String("s3:GetObject"),
    58  //							pulumi.String("s3:ListBucket"),
    59  //						},
    60  //						Resources: pulumi.StringArray{
    61  //							example.Arn,
    62  //							example.Arn.ApplyT(func(arn string) (string, error) {
    63  //								return fmt.Sprintf("%v/*", arn), nil
    64  //							}).(pulumi.StringOutput),
    65  //						},
    66  //					},
    67  //				},
    68  //			}, nil)
    69  //			_, err = s3.NewBucketPolicy(ctx, "allow_access_from_another_account", &s3.BucketPolicyArgs{
    70  //				Bucket: example.ID(),
    71  //				Policy: allowAccessFromAnotherAccount.ApplyT(func(allowAccessFromAnotherAccount iam.GetPolicyDocumentResult) (*string, error) {
    72  //					return &allowAccessFromAnotherAccount.Json, nil
    73  //				}).(pulumi.StringPtrOutput),
    74  //			})
    75  //			if err != nil {
    76  //				return err
    77  //			}
    78  //			return nil
    79  //		})
    80  //	}
    81  //
    82  // ```
    83  // <!--End PulumiCodeChooser -->
    84  //
    85  // ## Import
    86  //
    87  // Using `pulumi import`, import S3 bucket policies using the bucket name. For example:
    88  //
    89  // ```sh
    90  // $ pulumi import aws:s3/bucketPolicy:BucketPolicy allow_access_from_another_account my-tf-test-bucket
    91  // ```
    92  type BucketPolicy struct {
    93  	pulumi.CustomResourceState
    94  
    95  	// Name of the bucket to which to apply the policy.
    96  	Bucket pulumi.StringOutput `pulumi:"bucket"`
    97  	// Text of the policy. Although this is a bucket policy rather than an IAM policy, the `iam.getPolicyDocument` data source may be used, so long as it specifies a principal. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide. Note: Bucket policies are limited to 20 KB in size.
    98  	Policy pulumi.StringOutput `pulumi:"policy"`
    99  }
   100  
   101  // NewBucketPolicy registers a new resource with the given unique name, arguments, and options.
   102  func NewBucketPolicy(ctx *pulumi.Context,
   103  	name string, args *BucketPolicyArgs, opts ...pulumi.ResourceOption) (*BucketPolicy, error) {
   104  	if args == nil {
   105  		return nil, errors.New("missing one or more required arguments")
   106  	}
   107  
   108  	if args.Bucket == nil {
   109  		return nil, errors.New("invalid value for required argument 'Bucket'")
   110  	}
   111  	if args.Policy == nil {
   112  		return nil, errors.New("invalid value for required argument 'Policy'")
   113  	}
   114  	opts = internal.PkgResourceDefaultOpts(opts)
   115  	var resource BucketPolicy
   116  	err := ctx.RegisterResource("aws:s3/bucketPolicy:BucketPolicy", name, args, &resource, opts...)
   117  	if err != nil {
   118  		return nil, err
   119  	}
   120  	return &resource, nil
   121  }
   122  
   123  // GetBucketPolicy gets an existing BucketPolicy resource's state with the given name, ID, and optional
   124  // state properties that are used to uniquely qualify the lookup (nil if not required).
   125  func GetBucketPolicy(ctx *pulumi.Context,
   126  	name string, id pulumi.IDInput, state *BucketPolicyState, opts ...pulumi.ResourceOption) (*BucketPolicy, error) {
   127  	var resource BucketPolicy
   128  	err := ctx.ReadResource("aws:s3/bucketPolicy:BucketPolicy", name, id, state, &resource, opts...)
   129  	if err != nil {
   130  		return nil, err
   131  	}
   132  	return &resource, nil
   133  }
   134  
   135  // Input properties used for looking up and filtering BucketPolicy resources.
   136  type bucketPolicyState struct {
   137  	// Name of the bucket to which to apply the policy.
   138  	Bucket *string `pulumi:"bucket"`
   139  	// Text of the policy. Although this is a bucket policy rather than an IAM policy, the `iam.getPolicyDocument` data source may be used, so long as it specifies a principal. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide. Note: Bucket policies are limited to 20 KB in size.
   140  	Policy interface{} `pulumi:"policy"`
   141  }
   142  
   143  type BucketPolicyState struct {
   144  	// Name of the bucket to which to apply the policy.
   145  	Bucket pulumi.StringPtrInput
   146  	// Text of the policy. Although this is a bucket policy rather than an IAM policy, the `iam.getPolicyDocument` data source may be used, so long as it specifies a principal. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide. Note: Bucket policies are limited to 20 KB in size.
   147  	Policy pulumi.Input
   148  }
   149  
   150  func (BucketPolicyState) ElementType() reflect.Type {
   151  	return reflect.TypeOf((*bucketPolicyState)(nil)).Elem()
   152  }
   153  
   154  type bucketPolicyArgs struct {
   155  	// Name of the bucket to which to apply the policy.
   156  	Bucket string `pulumi:"bucket"`
   157  	// Text of the policy. Although this is a bucket policy rather than an IAM policy, the `iam.getPolicyDocument` data source may be used, so long as it specifies a principal. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide. Note: Bucket policies are limited to 20 KB in size.
   158  	Policy interface{} `pulumi:"policy"`
   159  }
   160  
   161  // The set of arguments for constructing a BucketPolicy resource.
   162  type BucketPolicyArgs struct {
   163  	// Name of the bucket to which to apply the policy.
   164  	Bucket pulumi.StringInput
   165  	// Text of the policy. Although this is a bucket policy rather than an IAM policy, the `iam.getPolicyDocument` data source may be used, so long as it specifies a principal. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide. Note: Bucket policies are limited to 20 KB in size.
   166  	Policy pulumi.Input
   167  }
   168  
   169  func (BucketPolicyArgs) ElementType() reflect.Type {
   170  	return reflect.TypeOf((*bucketPolicyArgs)(nil)).Elem()
   171  }
   172  
   173  type BucketPolicyInput interface {
   174  	pulumi.Input
   175  
   176  	ToBucketPolicyOutput() BucketPolicyOutput
   177  	ToBucketPolicyOutputWithContext(ctx context.Context) BucketPolicyOutput
   178  }
   179  
   180  func (*BucketPolicy) ElementType() reflect.Type {
   181  	return reflect.TypeOf((**BucketPolicy)(nil)).Elem()
   182  }
   183  
   184  func (i *BucketPolicy) ToBucketPolicyOutput() BucketPolicyOutput {
   185  	return i.ToBucketPolicyOutputWithContext(context.Background())
   186  }
   187  
   188  func (i *BucketPolicy) ToBucketPolicyOutputWithContext(ctx context.Context) BucketPolicyOutput {
   189  	return pulumi.ToOutputWithContext(ctx, i).(BucketPolicyOutput)
   190  }
   191  
   192  // BucketPolicyArrayInput is an input type that accepts BucketPolicyArray and BucketPolicyArrayOutput values.
   193  // You can construct a concrete instance of `BucketPolicyArrayInput` via:
   194  //
   195  //	BucketPolicyArray{ BucketPolicyArgs{...} }
   196  type BucketPolicyArrayInput interface {
   197  	pulumi.Input
   198  
   199  	ToBucketPolicyArrayOutput() BucketPolicyArrayOutput
   200  	ToBucketPolicyArrayOutputWithContext(context.Context) BucketPolicyArrayOutput
   201  }
   202  
   203  type BucketPolicyArray []BucketPolicyInput
   204  
   205  func (BucketPolicyArray) ElementType() reflect.Type {
   206  	return reflect.TypeOf((*[]*BucketPolicy)(nil)).Elem()
   207  }
   208  
   209  func (i BucketPolicyArray) ToBucketPolicyArrayOutput() BucketPolicyArrayOutput {
   210  	return i.ToBucketPolicyArrayOutputWithContext(context.Background())
   211  }
   212  
   213  func (i BucketPolicyArray) ToBucketPolicyArrayOutputWithContext(ctx context.Context) BucketPolicyArrayOutput {
   214  	return pulumi.ToOutputWithContext(ctx, i).(BucketPolicyArrayOutput)
   215  }
   216  
   217  // BucketPolicyMapInput is an input type that accepts BucketPolicyMap and BucketPolicyMapOutput values.
   218  // You can construct a concrete instance of `BucketPolicyMapInput` via:
   219  //
   220  //	BucketPolicyMap{ "key": BucketPolicyArgs{...} }
   221  type BucketPolicyMapInput interface {
   222  	pulumi.Input
   223  
   224  	ToBucketPolicyMapOutput() BucketPolicyMapOutput
   225  	ToBucketPolicyMapOutputWithContext(context.Context) BucketPolicyMapOutput
   226  }
   227  
   228  type BucketPolicyMap map[string]BucketPolicyInput
   229  
   230  func (BucketPolicyMap) ElementType() reflect.Type {
   231  	return reflect.TypeOf((*map[string]*BucketPolicy)(nil)).Elem()
   232  }
   233  
   234  func (i BucketPolicyMap) ToBucketPolicyMapOutput() BucketPolicyMapOutput {
   235  	return i.ToBucketPolicyMapOutputWithContext(context.Background())
   236  }
   237  
   238  func (i BucketPolicyMap) ToBucketPolicyMapOutputWithContext(ctx context.Context) BucketPolicyMapOutput {
   239  	return pulumi.ToOutputWithContext(ctx, i).(BucketPolicyMapOutput)
   240  }
   241  
   242  type BucketPolicyOutput struct{ *pulumi.OutputState }
   243  
   244  func (BucketPolicyOutput) ElementType() reflect.Type {
   245  	return reflect.TypeOf((**BucketPolicy)(nil)).Elem()
   246  }
   247  
   248  func (o BucketPolicyOutput) ToBucketPolicyOutput() BucketPolicyOutput {
   249  	return o
   250  }
   251  
   252  func (o BucketPolicyOutput) ToBucketPolicyOutputWithContext(ctx context.Context) BucketPolicyOutput {
   253  	return o
   254  }
   255  
   256  // Name of the bucket to which to apply the policy.
   257  func (o BucketPolicyOutput) Bucket() pulumi.StringOutput {
   258  	return o.ApplyT(func(v *BucketPolicy) pulumi.StringOutput { return v.Bucket }).(pulumi.StringOutput)
   259  }
   260  
   261  // Text of the policy. Although this is a bucket policy rather than an IAM policy, the `iam.getPolicyDocument` data source may be used, so long as it specifies a principal. For more information about building AWS IAM policy documents, see the AWS IAM Policy Document Guide. Note: Bucket policies are limited to 20 KB in size.
   262  func (o BucketPolicyOutput) Policy() pulumi.StringOutput {
   263  	return o.ApplyT(func(v *BucketPolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput)
   264  }
   265  
   266  type BucketPolicyArrayOutput struct{ *pulumi.OutputState }
   267  
   268  func (BucketPolicyArrayOutput) ElementType() reflect.Type {
   269  	return reflect.TypeOf((*[]*BucketPolicy)(nil)).Elem()
   270  }
   271  
   272  func (o BucketPolicyArrayOutput) ToBucketPolicyArrayOutput() BucketPolicyArrayOutput {
   273  	return o
   274  }
   275  
   276  func (o BucketPolicyArrayOutput) ToBucketPolicyArrayOutputWithContext(ctx context.Context) BucketPolicyArrayOutput {
   277  	return o
   278  }
   279  
   280  func (o BucketPolicyArrayOutput) Index(i pulumi.IntInput) BucketPolicyOutput {
   281  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *BucketPolicy {
   282  		return vs[0].([]*BucketPolicy)[vs[1].(int)]
   283  	}).(BucketPolicyOutput)
   284  }
   285  
   286  type BucketPolicyMapOutput struct{ *pulumi.OutputState }
   287  
   288  func (BucketPolicyMapOutput) ElementType() reflect.Type {
   289  	return reflect.TypeOf((*map[string]*BucketPolicy)(nil)).Elem()
   290  }
   291  
   292  func (o BucketPolicyMapOutput) ToBucketPolicyMapOutput() BucketPolicyMapOutput {
   293  	return o
   294  }
   295  
   296  func (o BucketPolicyMapOutput) ToBucketPolicyMapOutputWithContext(ctx context.Context) BucketPolicyMapOutput {
   297  	return o
   298  }
   299  
   300  func (o BucketPolicyMapOutput) MapIndex(k pulumi.StringInput) BucketPolicyOutput {
   301  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *BucketPolicy {
   302  		return vs[0].(map[string]*BucketPolicy)[vs[1].(string)]
   303  	}).(BucketPolicyOutput)
   304  }
   305  
   306  func init() {
   307  	pulumi.RegisterInputType(reflect.TypeOf((*BucketPolicyInput)(nil)).Elem(), &BucketPolicy{})
   308  	pulumi.RegisterInputType(reflect.TypeOf((*BucketPolicyArrayInput)(nil)).Elem(), BucketPolicyArray{})
   309  	pulumi.RegisterInputType(reflect.TypeOf((*BucketPolicyMapInput)(nil)).Elem(), BucketPolicyMap{})
   310  	pulumi.RegisterOutputType(BucketPolicyOutput{})
   311  	pulumi.RegisterOutputType(BucketPolicyArrayOutput{})
   312  	pulumi.RegisterOutputType(BucketPolicyMapOutput{})
   313  }