/
queuePolicy.go
267 lines (221 loc) · 8.67 KB
/
queuePolicy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package sqs
import (
"context"
"reflect"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Allows you to set a policy of an SQS Queue
// while referencing ARN of the queue within the policy.
//
// ## Example Usage
//
// ```go
// package main
//
// import (
// "fmt"
//
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/iam"
// "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/sqs"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// queue, err := sqs.NewQueue(ctx, "queue", nil)
// if err != nil {
// return err
// }
// _, err = sqs.NewQueuePolicy(ctx, "test", &sqs.QueuePolicyArgs{
// QueueUrl: queue.ID(),
// Policy: queue.Arn.ApplyT(func(arn string) (string, error) {
// return fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", " \"Version\": \"2012-10-17\",\n", " \"Id\": \"sqspolicy\",\n", " \"Statement\": [\n", " {\n", " \"Sid\": \"First\",\n", " \"Effect\": \"Allow\",\n", " \"Principal\": \"*\",\n", " \"Action\": \"sqs:SendMessage\",\n", " \"Resource\": \"", arn, "\",\n", " \"Condition\": {\n", " \"ArnEquals\": {\n", " \"aws:SourceArn\": \"", aws_sns_topic.Example.Arn, "\"\n", " }\n", " }\n", " }\n", " ]\n", "}\n"), nil
// }).(pulumi.StringOutput),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
//
// ## Import
//
// SQS Queue Policies can be imported using the queue URL, e.g.,
//
// ```sh
// $ pulumi import aws:sqs/queuePolicy:QueuePolicy test https://queue.amazonaws.com/0123456789012/myqueue
// ```
type QueuePolicy struct {
pulumi.CustomResourceState
// The JSON policy for the SQS queue.
Policy pulumi.StringOutput `pulumi:"policy"`
// The URL of the SQS Queue to which to attach the policy
QueueUrl pulumi.StringOutput `pulumi:"queueUrl"`
}
// NewQueuePolicy registers a new resource with the given unique name, arguments, and options.
func NewQueuePolicy(ctx *pulumi.Context,
name string, args *QueuePolicyArgs, opts ...pulumi.ResourceOption) (*QueuePolicy, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.Policy == nil {
return nil, errors.New("invalid value for required argument 'Policy'")
}
if args.QueueUrl == nil {
return nil, errors.New("invalid value for required argument 'QueueUrl'")
}
var resource QueuePolicy
err := ctx.RegisterResource("aws:sqs/queuePolicy:QueuePolicy", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetQueuePolicy gets an existing QueuePolicy resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetQueuePolicy(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *QueuePolicyState, opts ...pulumi.ResourceOption) (*QueuePolicy, error) {
var resource QueuePolicy
err := ctx.ReadResource("aws:sqs/queuePolicy:QueuePolicy", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering QueuePolicy resources.
type queuePolicyState struct {
// The JSON policy for the SQS queue.
Policy interface{} `pulumi:"policy"`
// The URL of the SQS Queue to which to attach the policy
QueueUrl *string `pulumi:"queueUrl"`
}
type QueuePolicyState struct {
// The JSON policy for the SQS queue.
Policy pulumi.Input
// The URL of the SQS Queue to which to attach the policy
QueueUrl pulumi.StringPtrInput
}
func (QueuePolicyState) ElementType() reflect.Type {
return reflect.TypeOf((*queuePolicyState)(nil)).Elem()
}
type queuePolicyArgs struct {
// The JSON policy for the SQS queue.
Policy interface{} `pulumi:"policy"`
// The URL of the SQS Queue to which to attach the policy
QueueUrl string `pulumi:"queueUrl"`
}
// The set of arguments for constructing a QueuePolicy resource.
type QueuePolicyArgs struct {
// The JSON policy for the SQS queue.
Policy pulumi.Input
// The URL of the SQS Queue to which to attach the policy
QueueUrl pulumi.StringInput
}
func (QueuePolicyArgs) ElementType() reflect.Type {
return reflect.TypeOf((*queuePolicyArgs)(nil)).Elem()
}
type QueuePolicyInput interface {
pulumi.Input
ToQueuePolicyOutput() QueuePolicyOutput
ToQueuePolicyOutputWithContext(ctx context.Context) QueuePolicyOutput
}
func (*QueuePolicy) ElementType() reflect.Type {
return reflect.TypeOf((**QueuePolicy)(nil)).Elem()
}
func (i *QueuePolicy) ToQueuePolicyOutput() QueuePolicyOutput {
return i.ToQueuePolicyOutputWithContext(context.Background())
}
func (i *QueuePolicy) ToQueuePolicyOutputWithContext(ctx context.Context) QueuePolicyOutput {
return pulumi.ToOutputWithContext(ctx, i).(QueuePolicyOutput)
}
// QueuePolicyArrayInput is an input type that accepts QueuePolicyArray and QueuePolicyArrayOutput values.
// You can construct a concrete instance of `QueuePolicyArrayInput` via:
//
// QueuePolicyArray{ QueuePolicyArgs{...} }
type QueuePolicyArrayInput interface {
pulumi.Input
ToQueuePolicyArrayOutput() QueuePolicyArrayOutput
ToQueuePolicyArrayOutputWithContext(context.Context) QueuePolicyArrayOutput
}
type QueuePolicyArray []QueuePolicyInput
func (QueuePolicyArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*QueuePolicy)(nil)).Elem()
}
func (i QueuePolicyArray) ToQueuePolicyArrayOutput() QueuePolicyArrayOutput {
return i.ToQueuePolicyArrayOutputWithContext(context.Background())
}
func (i QueuePolicyArray) ToQueuePolicyArrayOutputWithContext(ctx context.Context) QueuePolicyArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(QueuePolicyArrayOutput)
}
// QueuePolicyMapInput is an input type that accepts QueuePolicyMap and QueuePolicyMapOutput values.
// You can construct a concrete instance of `QueuePolicyMapInput` via:
//
// QueuePolicyMap{ "key": QueuePolicyArgs{...} }
type QueuePolicyMapInput interface {
pulumi.Input
ToQueuePolicyMapOutput() QueuePolicyMapOutput
ToQueuePolicyMapOutputWithContext(context.Context) QueuePolicyMapOutput
}
type QueuePolicyMap map[string]QueuePolicyInput
func (QueuePolicyMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*QueuePolicy)(nil)).Elem()
}
func (i QueuePolicyMap) ToQueuePolicyMapOutput() QueuePolicyMapOutput {
return i.ToQueuePolicyMapOutputWithContext(context.Background())
}
func (i QueuePolicyMap) ToQueuePolicyMapOutputWithContext(ctx context.Context) QueuePolicyMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(QueuePolicyMapOutput)
}
type QueuePolicyOutput struct{ *pulumi.OutputState }
func (QueuePolicyOutput) ElementType() reflect.Type {
return reflect.TypeOf((**QueuePolicy)(nil)).Elem()
}
func (o QueuePolicyOutput) ToQueuePolicyOutput() QueuePolicyOutput {
return o
}
func (o QueuePolicyOutput) ToQueuePolicyOutputWithContext(ctx context.Context) QueuePolicyOutput {
return o
}
type QueuePolicyArrayOutput struct{ *pulumi.OutputState }
func (QueuePolicyArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*QueuePolicy)(nil)).Elem()
}
func (o QueuePolicyArrayOutput) ToQueuePolicyArrayOutput() QueuePolicyArrayOutput {
return o
}
func (o QueuePolicyArrayOutput) ToQueuePolicyArrayOutputWithContext(ctx context.Context) QueuePolicyArrayOutput {
return o
}
func (o QueuePolicyArrayOutput) Index(i pulumi.IntInput) QueuePolicyOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *QueuePolicy {
return vs[0].([]*QueuePolicy)[vs[1].(int)]
}).(QueuePolicyOutput)
}
type QueuePolicyMapOutput struct{ *pulumi.OutputState }
func (QueuePolicyMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*QueuePolicy)(nil)).Elem()
}
func (o QueuePolicyMapOutput) ToQueuePolicyMapOutput() QueuePolicyMapOutput {
return o
}
func (o QueuePolicyMapOutput) ToQueuePolicyMapOutputWithContext(ctx context.Context) QueuePolicyMapOutput {
return o
}
func (o QueuePolicyMapOutput) MapIndex(k pulumi.StringInput) QueuePolicyOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *QueuePolicy {
return vs[0].(map[string]*QueuePolicy)[vs[1].(string)]
}).(QueuePolicyOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*QueuePolicyInput)(nil)).Elem(), &QueuePolicy{})
pulumi.RegisterInputType(reflect.TypeOf((*QueuePolicyArrayInput)(nil)).Elem(), QueuePolicyArray{})
pulumi.RegisterInputType(reflect.TypeOf((*QueuePolicyMapInput)(nil)).Elem(), QueuePolicyMap{})
pulumi.RegisterOutputType(QueuePolicyOutput{})
pulumi.RegisterOutputType(QueuePolicyArrayOutput{})
pulumi.RegisterOutputType(QueuePolicyMapOutput{})
}