github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/sqs/queuePolicy.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 sqs
     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  // Allows you to set a policy of an SQS Queue
    16  // while referencing ARN of the queue within the policy.
    17  //
    18  // ## Example Usage
    19  //
    20  // <!--Start PulumiCodeChooser -->
    21  // ```go
    22  // package main
    23  //
    24  // import (
    25  //
    26  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    27  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sqs"
    28  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    29  //
    30  // )
    31  // func main() {
    32  // pulumi.Run(func(ctx *pulumi.Context) error {
    33  // q, err := sqs.NewQueue(ctx, "q", &sqs.QueueArgs{
    34  // Name: pulumi.String("examplequeue"),
    35  // })
    36  // if err != nil {
    37  // return err
    38  // }
    39  // test := q.Arn.ApplyT(func(arn string) (iam.GetPolicyDocumentResult, error) {
    40  // return iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
    41  // Statements: []iam.GetPolicyDocumentStatement{
    42  // {
    43  // Sid: "First",
    44  // Effect: "Allow",
    45  // Principals: []iam.GetPolicyDocumentStatementPrincipal{
    46  // {
    47  // Type: "*",
    48  // Identifiers: []string{
    49  // "*",
    50  // },
    51  // },
    52  // },
    53  // Actions: []string{
    54  // "sqs:SendMessage",
    55  // },
    56  // Resources: []string{
    57  // arn,
    58  // },
    59  // Conditions: []iam.GetPolicyDocumentStatementCondition{
    60  // {
    61  // Test: "ArnEquals",
    62  // Variable: "aws:SourceArn",
    63  // Values: interface{}{
    64  // example.Arn,
    65  // },
    66  // },
    67  // },
    68  // },
    69  // },
    70  // }, nil), nil
    71  // }).(iam.GetPolicyDocumentResultOutput)
    72  // _, err = sqs.NewQueuePolicy(ctx, "test", &sqs.QueuePolicyArgs{
    73  // QueueUrl: q.ID(),
    74  // Policy: test.ApplyT(func(test iam.GetPolicyDocumentResult) (*string, error) {
    75  // return &test.Json, nil
    76  // }).(pulumi.StringPtrOutput),
    77  // })
    78  // if err != nil {
    79  // return err
    80  // }
    81  // return nil
    82  // })
    83  // }
    84  // ```
    85  // <!--End PulumiCodeChooser -->
    86  //
    87  // ## Import
    88  //
    89  // Using `pulumi import`, import SQS Queue Policies using the queue URL. For example:
    90  //
    91  // ```sh
    92  // $ pulumi import aws:sqs/queuePolicy:QueuePolicy test https://queue.amazonaws.com/0123456789012/myqueue
    93  // ```
    94  type QueuePolicy struct {
    95  	pulumi.CustomResourceState
    96  
    97  	// The JSON policy for the SQS queue.
    98  	Policy pulumi.StringOutput `pulumi:"policy"`
    99  	// The URL of the SQS Queue to which to attach the policy
   100  	QueueUrl pulumi.StringOutput `pulumi:"queueUrl"`
   101  }
   102  
   103  // NewQueuePolicy registers a new resource with the given unique name, arguments, and options.
   104  func NewQueuePolicy(ctx *pulumi.Context,
   105  	name string, args *QueuePolicyArgs, opts ...pulumi.ResourceOption) (*QueuePolicy, error) {
   106  	if args == nil {
   107  		return nil, errors.New("missing one or more required arguments")
   108  	}
   109  
   110  	if args.Policy == nil {
   111  		return nil, errors.New("invalid value for required argument 'Policy'")
   112  	}
   113  	if args.QueueUrl == nil {
   114  		return nil, errors.New("invalid value for required argument 'QueueUrl'")
   115  	}
   116  	opts = internal.PkgResourceDefaultOpts(opts)
   117  	var resource QueuePolicy
   118  	err := ctx.RegisterResource("aws:sqs/queuePolicy:QueuePolicy", name, args, &resource, opts...)
   119  	if err != nil {
   120  		return nil, err
   121  	}
   122  	return &resource, nil
   123  }
   124  
   125  // GetQueuePolicy gets an existing QueuePolicy resource's state with the given name, ID, and optional
   126  // state properties that are used to uniquely qualify the lookup (nil if not required).
   127  func GetQueuePolicy(ctx *pulumi.Context,
   128  	name string, id pulumi.IDInput, state *QueuePolicyState, opts ...pulumi.ResourceOption) (*QueuePolicy, error) {
   129  	var resource QueuePolicy
   130  	err := ctx.ReadResource("aws:sqs/queuePolicy:QueuePolicy", name, id, state, &resource, opts...)
   131  	if err != nil {
   132  		return nil, err
   133  	}
   134  	return &resource, nil
   135  }
   136  
   137  // Input properties used for looking up and filtering QueuePolicy resources.
   138  type queuePolicyState struct {
   139  	// The JSON policy for the SQS queue.
   140  	Policy interface{} `pulumi:"policy"`
   141  	// The URL of the SQS Queue to which to attach the policy
   142  	QueueUrl *string `pulumi:"queueUrl"`
   143  }
   144  
   145  type QueuePolicyState struct {
   146  	// The JSON policy for the SQS queue.
   147  	Policy pulumi.Input
   148  	// The URL of the SQS Queue to which to attach the policy
   149  	QueueUrl pulumi.StringPtrInput
   150  }
   151  
   152  func (QueuePolicyState) ElementType() reflect.Type {
   153  	return reflect.TypeOf((*queuePolicyState)(nil)).Elem()
   154  }
   155  
   156  type queuePolicyArgs struct {
   157  	// The JSON policy for the SQS queue.
   158  	Policy interface{} `pulumi:"policy"`
   159  	// The URL of the SQS Queue to which to attach the policy
   160  	QueueUrl string `pulumi:"queueUrl"`
   161  }
   162  
   163  // The set of arguments for constructing a QueuePolicy resource.
   164  type QueuePolicyArgs struct {
   165  	// The JSON policy for the SQS queue.
   166  	Policy pulumi.Input
   167  	// The URL of the SQS Queue to which to attach the policy
   168  	QueueUrl pulumi.StringInput
   169  }
   170  
   171  func (QueuePolicyArgs) ElementType() reflect.Type {
   172  	return reflect.TypeOf((*queuePolicyArgs)(nil)).Elem()
   173  }
   174  
   175  type QueuePolicyInput interface {
   176  	pulumi.Input
   177  
   178  	ToQueuePolicyOutput() QueuePolicyOutput
   179  	ToQueuePolicyOutputWithContext(ctx context.Context) QueuePolicyOutput
   180  }
   181  
   182  func (*QueuePolicy) ElementType() reflect.Type {
   183  	return reflect.TypeOf((**QueuePolicy)(nil)).Elem()
   184  }
   185  
   186  func (i *QueuePolicy) ToQueuePolicyOutput() QueuePolicyOutput {
   187  	return i.ToQueuePolicyOutputWithContext(context.Background())
   188  }
   189  
   190  func (i *QueuePolicy) ToQueuePolicyOutputWithContext(ctx context.Context) QueuePolicyOutput {
   191  	return pulumi.ToOutputWithContext(ctx, i).(QueuePolicyOutput)
   192  }
   193  
   194  // QueuePolicyArrayInput is an input type that accepts QueuePolicyArray and QueuePolicyArrayOutput values.
   195  // You can construct a concrete instance of `QueuePolicyArrayInput` via:
   196  //
   197  //	QueuePolicyArray{ QueuePolicyArgs{...} }
   198  type QueuePolicyArrayInput interface {
   199  	pulumi.Input
   200  
   201  	ToQueuePolicyArrayOutput() QueuePolicyArrayOutput
   202  	ToQueuePolicyArrayOutputWithContext(context.Context) QueuePolicyArrayOutput
   203  }
   204  
   205  type QueuePolicyArray []QueuePolicyInput
   206  
   207  func (QueuePolicyArray) ElementType() reflect.Type {
   208  	return reflect.TypeOf((*[]*QueuePolicy)(nil)).Elem()
   209  }
   210  
   211  func (i QueuePolicyArray) ToQueuePolicyArrayOutput() QueuePolicyArrayOutput {
   212  	return i.ToQueuePolicyArrayOutputWithContext(context.Background())
   213  }
   214  
   215  func (i QueuePolicyArray) ToQueuePolicyArrayOutputWithContext(ctx context.Context) QueuePolicyArrayOutput {
   216  	return pulumi.ToOutputWithContext(ctx, i).(QueuePolicyArrayOutput)
   217  }
   218  
   219  // QueuePolicyMapInput is an input type that accepts QueuePolicyMap and QueuePolicyMapOutput values.
   220  // You can construct a concrete instance of `QueuePolicyMapInput` via:
   221  //
   222  //	QueuePolicyMap{ "key": QueuePolicyArgs{...} }
   223  type QueuePolicyMapInput interface {
   224  	pulumi.Input
   225  
   226  	ToQueuePolicyMapOutput() QueuePolicyMapOutput
   227  	ToQueuePolicyMapOutputWithContext(context.Context) QueuePolicyMapOutput
   228  }
   229  
   230  type QueuePolicyMap map[string]QueuePolicyInput
   231  
   232  func (QueuePolicyMap) ElementType() reflect.Type {
   233  	return reflect.TypeOf((*map[string]*QueuePolicy)(nil)).Elem()
   234  }
   235  
   236  func (i QueuePolicyMap) ToQueuePolicyMapOutput() QueuePolicyMapOutput {
   237  	return i.ToQueuePolicyMapOutputWithContext(context.Background())
   238  }
   239  
   240  func (i QueuePolicyMap) ToQueuePolicyMapOutputWithContext(ctx context.Context) QueuePolicyMapOutput {
   241  	return pulumi.ToOutputWithContext(ctx, i).(QueuePolicyMapOutput)
   242  }
   243  
   244  type QueuePolicyOutput struct{ *pulumi.OutputState }
   245  
   246  func (QueuePolicyOutput) ElementType() reflect.Type {
   247  	return reflect.TypeOf((**QueuePolicy)(nil)).Elem()
   248  }
   249  
   250  func (o QueuePolicyOutput) ToQueuePolicyOutput() QueuePolicyOutput {
   251  	return o
   252  }
   253  
   254  func (o QueuePolicyOutput) ToQueuePolicyOutputWithContext(ctx context.Context) QueuePolicyOutput {
   255  	return o
   256  }
   257  
   258  // The JSON policy for the SQS queue.
   259  func (o QueuePolicyOutput) Policy() pulumi.StringOutput {
   260  	return o.ApplyT(func(v *QueuePolicy) pulumi.StringOutput { return v.Policy }).(pulumi.StringOutput)
   261  }
   262  
   263  // The URL of the SQS Queue to which to attach the policy
   264  func (o QueuePolicyOutput) QueueUrl() pulumi.StringOutput {
   265  	return o.ApplyT(func(v *QueuePolicy) pulumi.StringOutput { return v.QueueUrl }).(pulumi.StringOutput)
   266  }
   267  
   268  type QueuePolicyArrayOutput struct{ *pulumi.OutputState }
   269  
   270  func (QueuePolicyArrayOutput) ElementType() reflect.Type {
   271  	return reflect.TypeOf((*[]*QueuePolicy)(nil)).Elem()
   272  }
   273  
   274  func (o QueuePolicyArrayOutput) ToQueuePolicyArrayOutput() QueuePolicyArrayOutput {
   275  	return o
   276  }
   277  
   278  func (o QueuePolicyArrayOutput) ToQueuePolicyArrayOutputWithContext(ctx context.Context) QueuePolicyArrayOutput {
   279  	return o
   280  }
   281  
   282  func (o QueuePolicyArrayOutput) Index(i pulumi.IntInput) QueuePolicyOutput {
   283  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *QueuePolicy {
   284  		return vs[0].([]*QueuePolicy)[vs[1].(int)]
   285  	}).(QueuePolicyOutput)
   286  }
   287  
   288  type QueuePolicyMapOutput struct{ *pulumi.OutputState }
   289  
   290  func (QueuePolicyMapOutput) ElementType() reflect.Type {
   291  	return reflect.TypeOf((*map[string]*QueuePolicy)(nil)).Elem()
   292  }
   293  
   294  func (o QueuePolicyMapOutput) ToQueuePolicyMapOutput() QueuePolicyMapOutput {
   295  	return o
   296  }
   297  
   298  func (o QueuePolicyMapOutput) ToQueuePolicyMapOutputWithContext(ctx context.Context) QueuePolicyMapOutput {
   299  	return o
   300  }
   301  
   302  func (o QueuePolicyMapOutput) MapIndex(k pulumi.StringInput) QueuePolicyOutput {
   303  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *QueuePolicy {
   304  		return vs[0].(map[string]*QueuePolicy)[vs[1].(string)]
   305  	}).(QueuePolicyOutput)
   306  }
   307  
   308  func init() {
   309  	pulumi.RegisterInputType(reflect.TypeOf((*QueuePolicyInput)(nil)).Elem(), &QueuePolicy{})
   310  	pulumi.RegisterInputType(reflect.TypeOf((*QueuePolicyArrayInput)(nil)).Elem(), QueuePolicyArray{})
   311  	pulumi.RegisterInputType(reflect.TypeOf((*QueuePolicyMapInput)(nil)).Elem(), QueuePolicyMap{})
   312  	pulumi.RegisterOutputType(QueuePolicyOutput{})
   313  	pulumi.RegisterOutputType(QueuePolicyArrayOutput{})
   314  	pulumi.RegisterOutputType(QueuePolicyMapOutput{})
   315  }