/
subscription.go
471 lines (414 loc) · 21.9 KB
/
subscription.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
// Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
// *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
package apimanagement
import (
"context"
"reflect"
"errors"
"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/internal"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Manages a Subscription within a API Management Service.
//
// ## Example Usage
//
// ```go
// package main
//
// import (
//
// "github.com/pulumi/pulumi-azure/sdk/v5/go/azure/apimanagement"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
//
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// example, err := apimanagement.LookupService(ctx, &apimanagement.LookupServiceArgs{
// Name: "example-apim",
// ResourceGroupName: "example-resources",
// }, nil)
// if err != nil {
// return err
// }
// exampleGetProduct, err := apimanagement.LookupProduct(ctx, &apimanagement.LookupProductArgs{
// ProductId: "00000000-0000-0000-0000-000000000000",
// ApiManagementName: example.Name,
// ResourceGroupName: example.ResourceGroupName,
// }, nil)
// if err != nil {
// return err
// }
// exampleGetUser, err := apimanagement.LookupUser(ctx, &apimanagement.LookupUserArgs{
// UserId: "11111111-1111-1111-1111-111111111111",
// ApiManagementName: example.Name,
// ResourceGroupName: example.ResourceGroupName,
// }, nil)
// if err != nil {
// return err
// }
// _, err = apimanagement.NewSubscription(ctx, "example", &apimanagement.SubscriptionArgs{
// ApiManagementName: pulumi.String(example.Name),
// ResourceGroupName: pulumi.String(example.ResourceGroupName),
// UserId: pulumi.String(exampleGetUser.Id),
// ProductId: pulumi.String(exampleGetProduct.Id),
// DisplayName: pulumi.String("Parser API"),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
//
// ```
//
// ## Import
//
// API Management Subscriptions can be imported using the `resource id`, e.g.
//
// ```sh
// $ pulumi import azure:apimanagement/subscription:Subscription example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resources/providers/Microsoft.ApiManagement/service/example-apim/subscriptions/subscription-name
// ```
type Subscription struct {
pulumi.CustomResourceState
// Determines whether tracing can be enabled. Defaults to `true`.
AllowTracing pulumi.BoolPtrOutput `pulumi:"allowTracing"`
// The ID of the API which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `/apis` scope is used for the subscription and all apis are accessible.
ApiId pulumi.StringPtrOutput `pulumi:"apiId"`
// The name of the API Management Service where this Subscription should be created. Changing this forces a new resource to be created.
ApiManagementName pulumi.StringOutput `pulumi:"apiManagementName"`
// The display name of this Subscription.
DisplayName pulumi.StringOutput `pulumi:"displayName"`
// The primary subscription key to use for the subscription.
PrimaryKey pulumi.StringOutput `pulumi:"primaryKey"`
// The ID of the Product which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `allApis` scope is used for the subscription.
ProductId pulumi.StringPtrOutput `pulumi:"productId"`
// The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.
ResourceGroupName pulumi.StringOutput `pulumi:"resourceGroupName"`
// The secondary subscription key to use for the subscription.
SecondaryKey pulumi.StringOutput `pulumi:"secondaryKey"`
// The state of this Subscription. Possible values are `active`, `cancelled`, `expired`, `rejected`, `submitted` and `suspended`. Defaults to `submitted`.
State pulumi.StringPtrOutput `pulumi:"state"`
// An Identifier which should used as the ID of this Subscription. If not specified a new Subscription ID will be generated. Changing this forces a new resource to be created.
SubscriptionId pulumi.StringOutput `pulumi:"subscriptionId"`
// The ID of the User which should be assigned to this Subscription. Changing this forces a new resource to be created.
UserId pulumi.StringPtrOutput `pulumi:"userId"`
}
// NewSubscription registers a new resource with the given unique name, arguments, and options.
func NewSubscription(ctx *pulumi.Context,
name string, args *SubscriptionArgs, opts ...pulumi.ResourceOption) (*Subscription, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.ApiManagementName == nil {
return nil, errors.New("invalid value for required argument 'ApiManagementName'")
}
if args.DisplayName == nil {
return nil, errors.New("invalid value for required argument 'DisplayName'")
}
if args.ResourceGroupName == nil {
return nil, errors.New("invalid value for required argument 'ResourceGroupName'")
}
if args.PrimaryKey != nil {
args.PrimaryKey = pulumi.ToSecret(args.PrimaryKey).(pulumi.StringPtrInput)
}
if args.SecondaryKey != nil {
args.SecondaryKey = pulumi.ToSecret(args.SecondaryKey).(pulumi.StringPtrInput)
}
secrets := pulumi.AdditionalSecretOutputs([]string{
"primaryKey",
"secondaryKey",
})
opts = append(opts, secrets)
opts = internal.PkgResourceDefaultOpts(opts)
var resource Subscription
err := ctx.RegisterResource("azure:apimanagement/subscription:Subscription", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetSubscription gets an existing Subscription 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 GetSubscription(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *SubscriptionState, opts ...pulumi.ResourceOption) (*Subscription, error) {
var resource Subscription
err := ctx.ReadResource("azure:apimanagement/subscription:Subscription", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Subscription resources.
type subscriptionState struct {
// Determines whether tracing can be enabled. Defaults to `true`.
AllowTracing *bool `pulumi:"allowTracing"`
// The ID of the API which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `/apis` scope is used for the subscription and all apis are accessible.
ApiId *string `pulumi:"apiId"`
// The name of the API Management Service where this Subscription should be created. Changing this forces a new resource to be created.
ApiManagementName *string `pulumi:"apiManagementName"`
// The display name of this Subscription.
DisplayName *string `pulumi:"displayName"`
// The primary subscription key to use for the subscription.
PrimaryKey *string `pulumi:"primaryKey"`
// The ID of the Product which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `allApis` scope is used for the subscription.
ProductId *string `pulumi:"productId"`
// The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.
ResourceGroupName *string `pulumi:"resourceGroupName"`
// The secondary subscription key to use for the subscription.
SecondaryKey *string `pulumi:"secondaryKey"`
// The state of this Subscription. Possible values are `active`, `cancelled`, `expired`, `rejected`, `submitted` and `suspended`. Defaults to `submitted`.
State *string `pulumi:"state"`
// An Identifier which should used as the ID of this Subscription. If not specified a new Subscription ID will be generated. Changing this forces a new resource to be created.
SubscriptionId *string `pulumi:"subscriptionId"`
// The ID of the User which should be assigned to this Subscription. Changing this forces a new resource to be created.
UserId *string `pulumi:"userId"`
}
type SubscriptionState struct {
// Determines whether tracing can be enabled. Defaults to `true`.
AllowTracing pulumi.BoolPtrInput
// The ID of the API which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `/apis` scope is used for the subscription and all apis are accessible.
ApiId pulumi.StringPtrInput
// The name of the API Management Service where this Subscription should be created. Changing this forces a new resource to be created.
ApiManagementName pulumi.StringPtrInput
// The display name of this Subscription.
DisplayName pulumi.StringPtrInput
// The primary subscription key to use for the subscription.
PrimaryKey pulumi.StringPtrInput
// The ID of the Product which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `allApis` scope is used for the subscription.
ProductId pulumi.StringPtrInput
// The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.
ResourceGroupName pulumi.StringPtrInput
// The secondary subscription key to use for the subscription.
SecondaryKey pulumi.StringPtrInput
// The state of this Subscription. Possible values are `active`, `cancelled`, `expired`, `rejected`, `submitted` and `suspended`. Defaults to `submitted`.
State pulumi.StringPtrInput
// An Identifier which should used as the ID of this Subscription. If not specified a new Subscription ID will be generated. Changing this forces a new resource to be created.
SubscriptionId pulumi.StringPtrInput
// The ID of the User which should be assigned to this Subscription. Changing this forces a new resource to be created.
UserId pulumi.StringPtrInput
}
func (SubscriptionState) ElementType() reflect.Type {
return reflect.TypeOf((*subscriptionState)(nil)).Elem()
}
type subscriptionArgs struct {
// Determines whether tracing can be enabled. Defaults to `true`.
AllowTracing *bool `pulumi:"allowTracing"`
// The ID of the API which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `/apis` scope is used for the subscription and all apis are accessible.
ApiId *string `pulumi:"apiId"`
// The name of the API Management Service where this Subscription should be created. Changing this forces a new resource to be created.
ApiManagementName string `pulumi:"apiManagementName"`
// The display name of this Subscription.
DisplayName string `pulumi:"displayName"`
// The primary subscription key to use for the subscription.
PrimaryKey *string `pulumi:"primaryKey"`
// The ID of the Product which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `allApis` scope is used for the subscription.
ProductId *string `pulumi:"productId"`
// The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.
ResourceGroupName string `pulumi:"resourceGroupName"`
// The secondary subscription key to use for the subscription.
SecondaryKey *string `pulumi:"secondaryKey"`
// The state of this Subscription. Possible values are `active`, `cancelled`, `expired`, `rejected`, `submitted` and `suspended`. Defaults to `submitted`.
State *string `pulumi:"state"`
// An Identifier which should used as the ID of this Subscription. If not specified a new Subscription ID will be generated. Changing this forces a new resource to be created.
SubscriptionId *string `pulumi:"subscriptionId"`
// The ID of the User which should be assigned to this Subscription. Changing this forces a new resource to be created.
UserId *string `pulumi:"userId"`
}
// The set of arguments for constructing a Subscription resource.
type SubscriptionArgs struct {
// Determines whether tracing can be enabled. Defaults to `true`.
AllowTracing pulumi.BoolPtrInput
// The ID of the API which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `/apis` scope is used for the subscription and all apis are accessible.
ApiId pulumi.StringPtrInput
// The name of the API Management Service where this Subscription should be created. Changing this forces a new resource to be created.
ApiManagementName pulumi.StringInput
// The display name of this Subscription.
DisplayName pulumi.StringInput
// The primary subscription key to use for the subscription.
PrimaryKey pulumi.StringPtrInput
// The ID of the Product which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `allApis` scope is used for the subscription.
ProductId pulumi.StringPtrInput
// The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.
ResourceGroupName pulumi.StringInput
// The secondary subscription key to use for the subscription.
SecondaryKey pulumi.StringPtrInput
// The state of this Subscription. Possible values are `active`, `cancelled`, `expired`, `rejected`, `submitted` and `suspended`. Defaults to `submitted`.
State pulumi.StringPtrInput
// An Identifier which should used as the ID of this Subscription. If not specified a new Subscription ID will be generated. Changing this forces a new resource to be created.
SubscriptionId pulumi.StringPtrInput
// The ID of the User which should be assigned to this Subscription. Changing this forces a new resource to be created.
UserId pulumi.StringPtrInput
}
func (SubscriptionArgs) ElementType() reflect.Type {
return reflect.TypeOf((*subscriptionArgs)(nil)).Elem()
}
type SubscriptionInput interface {
pulumi.Input
ToSubscriptionOutput() SubscriptionOutput
ToSubscriptionOutputWithContext(ctx context.Context) SubscriptionOutput
}
func (*Subscription) ElementType() reflect.Type {
return reflect.TypeOf((**Subscription)(nil)).Elem()
}
func (i *Subscription) ToSubscriptionOutput() SubscriptionOutput {
return i.ToSubscriptionOutputWithContext(context.Background())
}
func (i *Subscription) ToSubscriptionOutputWithContext(ctx context.Context) SubscriptionOutput {
return pulumi.ToOutputWithContext(ctx, i).(SubscriptionOutput)
}
// SubscriptionArrayInput is an input type that accepts SubscriptionArray and SubscriptionArrayOutput values.
// You can construct a concrete instance of `SubscriptionArrayInput` via:
//
// SubscriptionArray{ SubscriptionArgs{...} }
type SubscriptionArrayInput interface {
pulumi.Input
ToSubscriptionArrayOutput() SubscriptionArrayOutput
ToSubscriptionArrayOutputWithContext(context.Context) SubscriptionArrayOutput
}
type SubscriptionArray []SubscriptionInput
func (SubscriptionArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Subscription)(nil)).Elem()
}
func (i SubscriptionArray) ToSubscriptionArrayOutput() SubscriptionArrayOutput {
return i.ToSubscriptionArrayOutputWithContext(context.Background())
}
func (i SubscriptionArray) ToSubscriptionArrayOutputWithContext(ctx context.Context) SubscriptionArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(SubscriptionArrayOutput)
}
// SubscriptionMapInput is an input type that accepts SubscriptionMap and SubscriptionMapOutput values.
// You can construct a concrete instance of `SubscriptionMapInput` via:
//
// SubscriptionMap{ "key": SubscriptionArgs{...} }
type SubscriptionMapInput interface {
pulumi.Input
ToSubscriptionMapOutput() SubscriptionMapOutput
ToSubscriptionMapOutputWithContext(context.Context) SubscriptionMapOutput
}
type SubscriptionMap map[string]SubscriptionInput
func (SubscriptionMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Subscription)(nil)).Elem()
}
func (i SubscriptionMap) ToSubscriptionMapOutput() SubscriptionMapOutput {
return i.ToSubscriptionMapOutputWithContext(context.Background())
}
func (i SubscriptionMap) ToSubscriptionMapOutputWithContext(ctx context.Context) SubscriptionMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(SubscriptionMapOutput)
}
type SubscriptionOutput struct{ *pulumi.OutputState }
func (SubscriptionOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Subscription)(nil)).Elem()
}
func (o SubscriptionOutput) ToSubscriptionOutput() SubscriptionOutput {
return o
}
func (o SubscriptionOutput) ToSubscriptionOutputWithContext(ctx context.Context) SubscriptionOutput {
return o
}
// Determines whether tracing can be enabled. Defaults to `true`.
func (o SubscriptionOutput) AllowTracing() pulumi.BoolPtrOutput {
return o.ApplyT(func(v *Subscription) pulumi.BoolPtrOutput { return v.AllowTracing }).(pulumi.BoolPtrOutput)
}
// The ID of the API which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `/apis` scope is used for the subscription and all apis are accessible.
func (o SubscriptionOutput) ApiId() pulumi.StringPtrOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringPtrOutput { return v.ApiId }).(pulumi.StringPtrOutput)
}
// The name of the API Management Service where this Subscription should be created. Changing this forces a new resource to be created.
func (o SubscriptionOutput) ApiManagementName() pulumi.StringOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringOutput { return v.ApiManagementName }).(pulumi.StringOutput)
}
// The display name of this Subscription.
func (o SubscriptionOutput) DisplayName() pulumi.StringOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringOutput { return v.DisplayName }).(pulumi.StringOutput)
}
// The primary subscription key to use for the subscription.
func (o SubscriptionOutput) PrimaryKey() pulumi.StringOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringOutput { return v.PrimaryKey }).(pulumi.StringOutput)
}
// The ID of the Product which should be assigned to this Subscription. Changing this forces a new resource to be created.
//
// > **Info:** Only one of `productId` and `apiId` can be set. If both are missing `allApis` scope is used for the subscription.
func (o SubscriptionOutput) ProductId() pulumi.StringPtrOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringPtrOutput { return v.ProductId }).(pulumi.StringPtrOutput)
}
// The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.
func (o SubscriptionOutput) ResourceGroupName() pulumi.StringOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringOutput { return v.ResourceGroupName }).(pulumi.StringOutput)
}
// The secondary subscription key to use for the subscription.
func (o SubscriptionOutput) SecondaryKey() pulumi.StringOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringOutput { return v.SecondaryKey }).(pulumi.StringOutput)
}
// The state of this Subscription. Possible values are `active`, `cancelled`, `expired`, `rejected`, `submitted` and `suspended`. Defaults to `submitted`.
func (o SubscriptionOutput) State() pulumi.StringPtrOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringPtrOutput { return v.State }).(pulumi.StringPtrOutput)
}
// An Identifier which should used as the ID of this Subscription. If not specified a new Subscription ID will be generated. Changing this forces a new resource to be created.
func (o SubscriptionOutput) SubscriptionId() pulumi.StringOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringOutput { return v.SubscriptionId }).(pulumi.StringOutput)
}
// The ID of the User which should be assigned to this Subscription. Changing this forces a new resource to be created.
func (o SubscriptionOutput) UserId() pulumi.StringPtrOutput {
return o.ApplyT(func(v *Subscription) pulumi.StringPtrOutput { return v.UserId }).(pulumi.StringPtrOutput)
}
type SubscriptionArrayOutput struct{ *pulumi.OutputState }
func (SubscriptionArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Subscription)(nil)).Elem()
}
func (o SubscriptionArrayOutput) ToSubscriptionArrayOutput() SubscriptionArrayOutput {
return o
}
func (o SubscriptionArrayOutput) ToSubscriptionArrayOutputWithContext(ctx context.Context) SubscriptionArrayOutput {
return o
}
func (o SubscriptionArrayOutput) Index(i pulumi.IntInput) SubscriptionOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Subscription {
return vs[0].([]*Subscription)[vs[1].(int)]
}).(SubscriptionOutput)
}
type SubscriptionMapOutput struct{ *pulumi.OutputState }
func (SubscriptionMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Subscription)(nil)).Elem()
}
func (o SubscriptionMapOutput) ToSubscriptionMapOutput() SubscriptionMapOutput {
return o
}
func (o SubscriptionMapOutput) ToSubscriptionMapOutputWithContext(ctx context.Context) SubscriptionMapOutput {
return o
}
func (o SubscriptionMapOutput) MapIndex(k pulumi.StringInput) SubscriptionOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Subscription {
return vs[0].(map[string]*Subscription)[vs[1].(string)]
}).(SubscriptionOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*SubscriptionInput)(nil)).Elem(), &Subscription{})
pulumi.RegisterInputType(reflect.TypeOf((*SubscriptionArrayInput)(nil)).Elem(), SubscriptionArray{})
pulumi.RegisterInputType(reflect.TypeOf((*SubscriptionMapInput)(nil)).Elem(), SubscriptionMap{})
pulumi.RegisterOutputType(SubscriptionOutput{})
pulumi.RegisterOutputType(SubscriptionArrayOutput{})
pulumi.RegisterOutputType(SubscriptionMapOutput{})
}