github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/opensearch/serverlessAccessPolicy.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 opensearch
     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  // Resource for managing an AWS OpenSearch Serverless Access Policy. See AWS documentation for [data access policies](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-data-access.html) and [supported data access policy permissions](https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-data-access.html#serverless-data-supported-permissions).
    16  //
    17  // ## Example Usage
    18  //
    19  // ### Grant all collection and index permissions
    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"
    30  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/opensearch"
    31  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    32  //
    33  // )
    34  //
    35  //	func main() {
    36  //		pulumi.Run(func(ctx *pulumi.Context) error {
    37  //			current, err := aws.GetCallerIdentity(ctx, nil, nil)
    38  //			if err != nil {
    39  //				return err
    40  //			}
    41  //			tmpJSON0, err := json.Marshal([]map[string]interface{}{
    42  //				map[string]interface{}{
    43  //					"Rules": []map[string]interface{}{
    44  //						map[string]interface{}{
    45  //							"ResourceType": "index",
    46  //							"Resource": []string{
    47  //								"index/example-collection/*",
    48  //							},
    49  //							"Permission": []string{
    50  //								"aoss:*",
    51  //							},
    52  //						},
    53  //						map[string]interface{}{
    54  //							"ResourceType": "collection",
    55  //							"Resource": []string{
    56  //								"collection/example-collection",
    57  //							},
    58  //							"Permission": []string{
    59  //								"aoss:*",
    60  //							},
    61  //						},
    62  //					},
    63  //					"Principal": []*string{
    64  //						current.Arn,
    65  //					},
    66  //				},
    67  //			})
    68  //			if err != nil {
    69  //				return err
    70  //			}
    71  //			json0 := string(tmpJSON0)
    72  //			_, err = opensearch.NewServerlessAccessPolicy(ctx, "example", &opensearch.ServerlessAccessPolicyArgs{
    73  //				Name:        pulumi.String("example"),
    74  //				Type:        pulumi.String("data"),
    75  //				Description: pulumi.String("read and write permissions"),
    76  //				Policy:      pulumi.String(json0),
    77  //			})
    78  //			if err != nil {
    79  //				return err
    80  //			}
    81  //			return nil
    82  //		})
    83  //	}
    84  //
    85  // ```
    86  // <!--End PulumiCodeChooser -->
    87  //
    88  // ### Grant read-only collection and index permissions
    89  //
    90  // <!--Start PulumiCodeChooser -->
    91  // ```go
    92  // package main
    93  //
    94  // import (
    95  //
    96  //	"encoding/json"
    97  //
    98  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws"
    99  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/opensearch"
   100  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
   101  //
   102  // )
   103  //
   104  //	func main() {
   105  //		pulumi.Run(func(ctx *pulumi.Context) error {
   106  //			current, err := aws.GetCallerIdentity(ctx, nil, nil)
   107  //			if err != nil {
   108  //				return err
   109  //			}
   110  //			tmpJSON0, err := json.Marshal([]map[string]interface{}{
   111  //				map[string]interface{}{
   112  //					"Rules": []interface{}{
   113  //						map[string]interface{}{
   114  //							"ResourceType": "index",
   115  //							"Resource": []string{
   116  //								"index/example-collection/*",
   117  //							},
   118  //							"Permission": []string{
   119  //								"aoss:DescribeIndex",
   120  //								"aoss:ReadDocument",
   121  //							},
   122  //						},
   123  //						map[string]interface{}{
   124  //							"ResourceType": "collection",
   125  //							"Resource": []string{
   126  //								"collection/example-collection",
   127  //							},
   128  //							"Permission": []string{
   129  //								"aoss:DescribeCollectionItems",
   130  //							},
   131  //						},
   132  //					},
   133  //					"Principal": []*string{
   134  //						current.Arn,
   135  //					},
   136  //				},
   137  //			})
   138  //			if err != nil {
   139  //				return err
   140  //			}
   141  //			json0 := string(tmpJSON0)
   142  //			_, err = opensearch.NewServerlessAccessPolicy(ctx, "example", &opensearch.ServerlessAccessPolicyArgs{
   143  //				Name:        pulumi.String("example"),
   144  //				Type:        pulumi.String("data"),
   145  //				Description: pulumi.String("read-only permissions"),
   146  //				Policy:      pulumi.String(json0),
   147  //			})
   148  //			if err != nil {
   149  //				return err
   150  //			}
   151  //			return nil
   152  //		})
   153  //	}
   154  //
   155  // ```
   156  // <!--End PulumiCodeChooser -->
   157  //
   158  // ### Grant SAML identity permissions
   159  //
   160  // <!--Start PulumiCodeChooser -->
   161  // ```go
   162  // package main
   163  //
   164  // import (
   165  //
   166  //	"encoding/json"
   167  //
   168  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/opensearch"
   169  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
   170  //
   171  // )
   172  //
   173  //	func main() {
   174  //		pulumi.Run(func(ctx *pulumi.Context) error {
   175  //			tmpJSON0, err := json.Marshal([]map[string]interface{}{
   176  //				map[string]interface{}{
   177  //					"Rules": []map[string]interface{}{
   178  //						map[string]interface{}{
   179  //							"ResourceType": "index",
   180  //							"Resource": []string{
   181  //								"index/example-collection/*",
   182  //							},
   183  //							"Permission": []string{
   184  //								"aoss:*",
   185  //							},
   186  //						},
   187  //						map[string]interface{}{
   188  //							"ResourceType": "collection",
   189  //							"Resource": []string{
   190  //								"collection/example-collection",
   191  //							},
   192  //							"Permission": []string{
   193  //								"aoss:*",
   194  //							},
   195  //						},
   196  //					},
   197  //					"Principal": []string{
   198  //						"saml/123456789012/myprovider/user/Annie",
   199  //						"saml/123456789012/anotherprovider/group/Accounting",
   200  //					},
   201  //				},
   202  //			})
   203  //			if err != nil {
   204  //				return err
   205  //			}
   206  //			json0 := string(tmpJSON0)
   207  //			_, err = opensearch.NewServerlessAccessPolicy(ctx, "example", &opensearch.ServerlessAccessPolicyArgs{
   208  //				Name:        pulumi.String("example"),
   209  //				Type:        pulumi.String("data"),
   210  //				Description: pulumi.String("saml permissions"),
   211  //				Policy:      pulumi.String(json0),
   212  //			})
   213  //			if err != nil {
   214  //				return err
   215  //			}
   216  //			return nil
   217  //		})
   218  //	}
   219  //
   220  // ```
   221  // <!--End PulumiCodeChooser -->
   222  //
   223  // ## Import
   224  //
   225  // Using `pulumi import`, import OpenSearchServerless Access Policy using the `name` and `type` arguments separated by a slash (`/`). For example:
   226  //
   227  // ```sh
   228  // $ pulumi import aws:opensearch/serverlessAccessPolicy:ServerlessAccessPolicy example example/data
   229  // ```
   230  type ServerlessAccessPolicy struct {
   231  	pulumi.CustomResourceState
   232  
   233  	// Description of the policy. Typically used to store information about the permissions defined in the policy.
   234  	Description pulumi.StringPtrOutput `pulumi:"description"`
   235  	// Name of the policy.
   236  	Name pulumi.StringOutput `pulumi:"name"`
   237  	// JSON policy document to use as the content for the new policy
   238  	Policy pulumi.StringOutput `pulumi:"policy"`
   239  	// Version of the policy.
   240  	PolicyVersion pulumi.StringOutput `pulumi:"policyVersion"`
   241  	// Type of access policy. Must be `data`.
   242  	//
   243  	// The following arguments are optional:
   244  	Type pulumi.StringOutput `pulumi:"type"`
   245  }
   246  
   247  // NewServerlessAccessPolicy registers a new resource with the given unique name, arguments, and options.
   248  func NewServerlessAccessPolicy(ctx *pulumi.Context,
   249  	name string, args *ServerlessAccessPolicyArgs, opts ...pulumi.ResourceOption) (*ServerlessAccessPolicy, error) {
   250  	if args == nil {
   251  		return nil, errors.New("missing one or more required arguments")
   252  	}
   253  
   254  	if args.Policy == nil {
   255  		return nil, errors.New("invalid value for required argument 'Policy'")
   256  	}
   257  	if args.Type == nil {
   258  		return nil, errors.New("invalid value for required argument 'Type'")
   259  	}
   260  	opts = internal.PkgResourceDefaultOpts(opts)
   261  	var resource ServerlessAccessPolicy
   262  	err := ctx.RegisterResource("aws:opensearch/serverlessAccessPolicy:ServerlessAccessPolicy", name, args, &resource, opts...)
   263  	if err != nil {
   264  		return nil, err
   265  	}
   266  	return &resource, nil
   267  }
   268  
   269  // GetServerlessAccessPolicy gets an existing ServerlessAccessPolicy resource's state with the given name, ID, and optional
   270  // state properties that are used to uniquely qualify the lookup (nil if not required).
   271  func GetServerlessAccessPolicy(ctx *pulumi.Context,
   272  	name string, id pulumi.IDInput, state *ServerlessAccessPolicyState, opts ...pulumi.ResourceOption) (*ServerlessAccessPolicy, error) {
   273  	var resource ServerlessAccessPolicy
   274  	err := ctx.ReadResource("aws:opensearch/serverlessAccessPolicy:ServerlessAccessPolicy", name, id, state, &resource, opts...)
   275  	if err != nil {
   276  		return nil, err
   277  	}
   278  	return &resource, nil
   279  }
   280  
   281  // Input properties used for looking up and filtering ServerlessAccessPolicy resources.
   282  type serverlessAccessPolicyState struct {
   283  	// Description of the policy. Typically used to store information about the permissions defined in the policy.
   284  	Description *string `pulumi:"description"`
   285  	// Name of the policy.
   286  	Name *string `pulumi:"name"`
   287  	// JSON policy document to use as the content for the new policy
   288  	Policy *string `pulumi:"policy"`
   289  	// Version of the policy.
   290  	PolicyVersion *string `pulumi:"policyVersion"`
   291  	// Type of access policy. Must be `data`.
   292  	//
   293  	// The following arguments are optional:
   294  	Type *string `pulumi:"type"`
   295  }
   296  
   297  type ServerlessAccessPolicyState struct {
   298  	// Description of the policy. Typically used to store information about the permissions defined in the policy.
   299  	Description pulumi.StringPtrInput
   300  	// Name of the policy.
   301  	Name pulumi.StringPtrInput
   302  	// JSON policy document to use as the content for the new policy
   303  	Policy pulumi.StringPtrInput
   304  	// Version of the policy.
   305  	PolicyVersion pulumi.StringPtrInput
   306  	// Type of access policy. Must be `data`.
   307  	//
   308  	// The following arguments are optional:
   309  	Type pulumi.StringPtrInput
   310  }
   311  
   312  func (ServerlessAccessPolicyState) ElementType() reflect.Type {
   313  	return reflect.TypeOf((*serverlessAccessPolicyState)(nil)).Elem()
   314  }
   315  
   316  type serverlessAccessPolicyArgs struct {
   317  	// Description of the policy. Typically used to store information about the permissions defined in the policy.
   318  	Description *string `pulumi:"description"`
   319  	// Name of the policy.
   320  	Name *string `pulumi:"name"`
   321  	// JSON policy document to use as the content for the new policy
   322  	Policy string `pulumi:"policy"`
   323  	// Type of access policy. Must be `data`.
   324  	//
   325  	// The following arguments are optional:
   326  	Type string `pulumi:"type"`
   327  }
   328  
   329  // The set of arguments for constructing a ServerlessAccessPolicy resource.
   330  type ServerlessAccessPolicyArgs struct {
   331  	// Description of the policy. Typically used to store information about the permissions defined in the policy.
   332  	Description pulumi.StringPtrInput
   333  	// Name of the policy.
   334  	Name pulumi.StringPtrInput
   335  	// JSON policy document to use as the content for the new policy
   336  	Policy pulumi.StringInput
   337  	// Type of access policy. Must be `data`.
   338  	//
   339  	// The following arguments are optional:
   340  	Type pulumi.StringInput
   341  }
   342  
   343  func (ServerlessAccessPolicyArgs) ElementType() reflect.Type {
   344  	return reflect.TypeOf((*serverlessAccessPolicyArgs)(nil)).Elem()
   345  }
   346  
   347  type ServerlessAccessPolicyInput interface {
   348  	pulumi.Input
   349  
   350  	ToServerlessAccessPolicyOutput() ServerlessAccessPolicyOutput
   351  	ToServerlessAccessPolicyOutputWithContext(ctx context.Context) ServerlessAccessPolicyOutput
   352  }
   353  
   354  func (*ServerlessAccessPolicy) ElementType() reflect.Type {
   355  	return reflect.TypeOf((**ServerlessAccessPolicy)(nil)).Elem()
   356  }
   357  
   358  func (i *ServerlessAccessPolicy) ToServerlessAccessPolicyOutput() ServerlessAccessPolicyOutput {
   359  	return i.ToServerlessAccessPolicyOutputWithContext(context.Background())
   360  }
   361  
   362  func (i *ServerlessAccessPolicy) ToServerlessAccessPolicyOutputWithContext(ctx context.Context) ServerlessAccessPolicyOutput {
   363  	return pulumi.ToOutputWithContext(ctx, i).(ServerlessAccessPolicyOutput)
   364  }
   365  
   366  // ServerlessAccessPolicyArrayInput is an input type that accepts ServerlessAccessPolicyArray and ServerlessAccessPolicyArrayOutput values.
   367  // You can construct a concrete instance of `ServerlessAccessPolicyArrayInput` via:
   368  //
   369  //	ServerlessAccessPolicyArray{ ServerlessAccessPolicyArgs{...} }
   370  type ServerlessAccessPolicyArrayInput interface {
   371  	pulumi.Input
   372  
   373  	ToServerlessAccessPolicyArrayOutput() ServerlessAccessPolicyArrayOutput
   374  	ToServerlessAccessPolicyArrayOutputWithContext(context.Context) ServerlessAccessPolicyArrayOutput
   375  }
   376  
   377  type ServerlessAccessPolicyArray []ServerlessAccessPolicyInput
   378  
   379  func (ServerlessAccessPolicyArray) ElementType() reflect.Type {
   380  	return reflect.TypeOf((*[]*ServerlessAccessPolicy)(nil)).Elem()
   381  }
   382  
   383  func (i ServerlessAccessPolicyArray) ToServerlessAccessPolicyArrayOutput() ServerlessAccessPolicyArrayOutput {
   384  	return i.ToServerlessAccessPolicyArrayOutputWithContext(context.Background())
   385  }
   386  
   387  func (i ServerlessAccessPolicyArray) ToServerlessAccessPolicyArrayOutputWithContext(ctx context.Context) ServerlessAccessPolicyArrayOutput {
   388  	return pulumi.ToOutputWithContext(ctx, i).(ServerlessAccessPolicyArrayOutput)
   389  }
   390  
   391  // ServerlessAccessPolicyMapInput is an input type that accepts ServerlessAccessPolicyMap and ServerlessAccessPolicyMapOutput values.
   392  // You can construct a concrete instance of `ServerlessAccessPolicyMapInput` via:
   393  //
   394  //	ServerlessAccessPolicyMap{ "key": ServerlessAccessPolicyArgs{...} }
   395  type ServerlessAccessPolicyMapInput interface {
   396  	pulumi.Input
   397  
   398  	ToServerlessAccessPolicyMapOutput() ServerlessAccessPolicyMapOutput
   399  	ToServerlessAccessPolicyMapOutputWithContext(context.Context) ServerlessAccessPolicyMapOutput
   400  }
   401  
   402  type ServerlessAccessPolicyMap map[string]ServerlessAccessPolicyInput
   403  
   404  func (ServerlessAccessPolicyMap) ElementType() reflect.Type {
   405  	return reflect.TypeOf((*map[string]*ServerlessAccessPolicy)(nil)).Elem()
   406  }
   407  
   408  func (i ServerlessAccessPolicyMap) ToServerlessAccessPolicyMapOutput() ServerlessAccessPolicyMapOutput {
   409  	return i.ToServerlessAccessPolicyMapOutputWithContext(context.Background())
   410  }
   411  
   412  func (i ServerlessAccessPolicyMap) ToServerlessAccessPolicyMapOutputWithContext(ctx context.Context) ServerlessAccessPolicyMapOutput {
   413  	return pulumi.ToOutputWithContext(ctx, i).(ServerlessAccessPolicyMapOutput)
   414  }
   415  
   416  type ServerlessAccessPolicyOutput struct{ *pulumi.OutputState }
   417  
   418  func (ServerlessAccessPolicyOutput) ElementType() reflect.Type {
   419  	return reflect.TypeOf((**ServerlessAccessPolicy)(nil)).Elem()
   420  }
   421  
   422  func (o ServerlessAccessPolicyOutput) ToServerlessAccessPolicyOutput() ServerlessAccessPolicyOutput {
   423  	return o
   424  }
   425  
   426  func (o ServerlessAccessPolicyOutput) ToServerlessAccessPolicyOutputWithContext(ctx context.Context) ServerlessAccessPolicyOutput {
   427  	return o
   428  }
   429  
   430  // Description of the policy. Typically used to store information about the permissions defined in the policy.
   431  func (o ServerlessAccessPolicyOutput) Description() pulumi.StringPtrOutput {
   432  	return o.ApplyT(func(v *ServerlessAccessPolicy) pulumi.StringPtrOutput { return v.Description }).(pulumi.StringPtrOutput)
   433  }
   434  
   435  // Name of the policy.
   436  func (o ServerlessAccessPolicyOutput) Name() pulumi.StringOutput {
   437  	return o.ApplyT(func(v *ServerlessAccessPolicy) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
   438  }
   439  
   440  // JSON policy document to use as the content for the new policy
   441  func (o ServerlessAccessPolicyOutput) Policy() pulumi.StringOutput {
   442  	return o.ApplyT(func(v *ServerlessAccessPolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput)
   443  }
   444  
   445  // Version of the policy.
   446  func (o ServerlessAccessPolicyOutput) PolicyVersion() pulumi.StringOutput {
   447  	return o.ApplyT(func(v *ServerlessAccessPolicy) pulumi.StringOutput { return v.PolicyVersion }).(pulumi.StringOutput)
   448  }
   449  
   450  // Type of access policy. Must be `data`.
   451  //
   452  // The following arguments are optional:
   453  func (o ServerlessAccessPolicyOutput) Type() pulumi.StringOutput {
   454  	return o.ApplyT(func(v *ServerlessAccessPolicy) pulumi.StringOutput { return v.Type }).(pulumi.StringOutput)
   455  }
   456  
   457  type ServerlessAccessPolicyArrayOutput struct{ *pulumi.OutputState }
   458  
   459  func (ServerlessAccessPolicyArrayOutput) ElementType() reflect.Type {
   460  	return reflect.TypeOf((*[]*ServerlessAccessPolicy)(nil)).Elem()
   461  }
   462  
   463  func (o ServerlessAccessPolicyArrayOutput) ToServerlessAccessPolicyArrayOutput() ServerlessAccessPolicyArrayOutput {
   464  	return o
   465  }
   466  
   467  func (o ServerlessAccessPolicyArrayOutput) ToServerlessAccessPolicyArrayOutputWithContext(ctx context.Context) ServerlessAccessPolicyArrayOutput {
   468  	return o
   469  }
   470  
   471  func (o ServerlessAccessPolicyArrayOutput) Index(i pulumi.IntInput) ServerlessAccessPolicyOutput {
   472  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *ServerlessAccessPolicy {
   473  		return vs[0].([]*ServerlessAccessPolicy)[vs[1].(int)]
   474  	}).(ServerlessAccessPolicyOutput)
   475  }
   476  
   477  type ServerlessAccessPolicyMapOutput struct{ *pulumi.OutputState }
   478  
   479  func (ServerlessAccessPolicyMapOutput) ElementType() reflect.Type {
   480  	return reflect.TypeOf((*map[string]*ServerlessAccessPolicy)(nil)).Elem()
   481  }
   482  
   483  func (o ServerlessAccessPolicyMapOutput) ToServerlessAccessPolicyMapOutput() ServerlessAccessPolicyMapOutput {
   484  	return o
   485  }
   486  
   487  func (o ServerlessAccessPolicyMapOutput) ToServerlessAccessPolicyMapOutputWithContext(ctx context.Context) ServerlessAccessPolicyMapOutput {
   488  	return o
   489  }
   490  
   491  func (o ServerlessAccessPolicyMapOutput) MapIndex(k pulumi.StringInput) ServerlessAccessPolicyOutput {
   492  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *ServerlessAccessPolicy {
   493  		return vs[0].(map[string]*ServerlessAccessPolicy)[vs[1].(string)]
   494  	}).(ServerlessAccessPolicyOutput)
   495  }
   496  
   497  func init() {
   498  	pulumi.RegisterInputType(reflect.TypeOf((*ServerlessAccessPolicyInput)(nil)).Elem(), &ServerlessAccessPolicy{})
   499  	pulumi.RegisterInputType(reflect.TypeOf((*ServerlessAccessPolicyArrayInput)(nil)).Elem(), ServerlessAccessPolicyArray{})
   500  	pulumi.RegisterInputType(reflect.TypeOf((*ServerlessAccessPolicyMapInput)(nil)).Elem(), ServerlessAccessPolicyMap{})
   501  	pulumi.RegisterOutputType(ServerlessAccessPolicyOutput{})
   502  	pulumi.RegisterOutputType(ServerlessAccessPolicyArrayOutput{})
   503  	pulumi.RegisterOutputType(ServerlessAccessPolicyMapOutput{})
   504  }