/
subscription.go
416 lines (356 loc) · 16.3 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
// *** 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 core
import (
"context"
"reflect"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
// Manages an Alias for a Subscription - which adds an Alias to an existing Subscription, allowing it to be managed in the provider - or create a new Subscription with a new Alias.
//
// > **NOTE:** Destroying a Subscription controlled by this resource will place the Subscription into a cancelled state. It is possible to re-activate a subscription within 90-days of cancellation, after which time the Subscription is irrevocably deleted, and the Subscription ID cannot be re-used. For further information see [here](https://docs.microsoft.com/en-us/azure/cost-management-billing/manage/cancel-azure-subscription#what-happens-after-subscription-cancellation). Users can optionally delete a Subscription once 72 hours have passed, however, this functionality is not suitable for this provider. A `Deleted` subscription cannot be reactivated.
//
// > **NOTE:** It is not possible to destroy (cancel) a subscription if it contains resources. If resources are present that are not managed by the provider then these will need to be removed before the Subscription can be destroyed.
//
// > **NOTE:** Azure supports Multiple Aliases per Subscription, however, to reliably manage this resource in this provider only a single Alias is supported.
//
// ## Example Usage
// ### Creating A New Alias And Subscription For An Enrollment Account
//
// ```go
// package main
//
// import (
// "github.com/pulumi/pulumi-azure/sdk/v3/go/azure/billing"
// "github.com/pulumi/pulumi-azure/sdk/v3/go/azure/core"
// "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// exampleEnrollmentAccountScope, err := billing.GetEnrollmentAccountScope(ctx, &billing.GetEnrollmentAccountScopeArgs{
// BillingAccountName: "1234567890",
// EnrollmentAccountName: "0123456",
// }, nil)
// if err != nil {
// return err
// }
// _, err = core.NewSubscription(ctx, "exampleSubscription", &core.SubscriptionArgs{
// SubscriptionName: pulumi.String("My Example EA Subscription"),
// BillingScopeId: pulumi.String(exampleEnrollmentAccountScope.Id),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
// ### Creating A New Alias And Subscription For A Microsoft Customer Account
//
// ```go
// package main
//
// import (
// "github.com/pulumi/pulumi-azure/sdk/v3/go/azure/billing"
// "github.com/pulumi/pulumi-azure/sdk/v3/go/azure/core"
// "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// exampleMcaAccountScope, err := billing.GetMcaAccountScope(ctx, &billing.GetMcaAccountScopeArgs{
// BillingAccountName: "e879cf0f-2b4d-5431-109a-f72fc9868693:024cabf4-7321-4cf9-be59-df0c77ca51de_2019-05-31",
// BillingProfileName: "PE2Q-NOIT-BG7-TGB",
// InvoiceSectionName: "MTT4-OBS7-PJA-TGB",
// }, nil)
// if err != nil {
// return err
// }
// _, err = core.NewSubscription(ctx, "exampleSubscription", &core.SubscriptionArgs{
// SubscriptionName: pulumi.String("My Example MCA Subscription"),
// BillingScopeId: pulumi.String(exampleMcaAccountScope.Id),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
// ### Adding An Alias To An Existing Subscription
//
// ```go
// package main
//
// import (
// "github.com/pulumi/pulumi-azure/sdk/v3/go/azure/core"
// "github.com/pulumi/pulumi/sdk/v2/go/pulumi"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// _, err := core.NewSubscription(ctx, "example", &core.SubscriptionArgs{
// Alias: pulumi.String("examplesub"),
// SubscriptionId: pulumi.String("12345678-12234-5678-9012-123456789012"),
// SubscriptionName: pulumi.String("My Example Subscription"),
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
//
// ## Import
//
// Subscriptions can be imported using the `resource id`, e.g.
//
// ```sh
// $ pulumi import azure:core/subscription:Subscription example "/providers/Microsoft.Subscription/aliases/subscription1"
// ```
//
// In this scenario, the `subscription_id` property can be completed and the provider will assume control of the existing subscription by creating an Alias. e.g.
type Subscription struct {
pulumi.CustomResourceState
// The Alias name for the subscription. This provider will generate a new GUID if this is not supplied. Changing this forces a new Subscription to be created.
Alias pulumi.StringOutput `pulumi:"alias"`
BillingScopeId pulumi.StringPtrOutput `pulumi:"billingScopeId"`
// The ID of the Subscription. Cannot be specified with `billingAccount`, `billingProfile`, `enrollmentAccount`, or `invoiceSection` Changing this forces a new Subscription to be created.
SubscriptionId pulumi.StringOutput `pulumi:"subscriptionId"`
// The Name of the Subscription. This is the Display Name in the portal.
SubscriptionName pulumi.StringOutput `pulumi:"subscriptionName"`
Tags pulumi.StringMapOutput `pulumi:"tags"`
// The ID of the Tenant to which the subscription belongs.
TenantId pulumi.StringOutput `pulumi:"tenantId"`
// The workload type of the Subscription. Possible values are `Production` (default) and `DevTest`. Changing this forces a new Subscription to be created.
Workload pulumi.StringPtrOutput `pulumi:"workload"`
}
// 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.SubscriptionName == nil {
return nil, errors.New("invalid value for required argument 'SubscriptionName'")
}
var resource Subscription
err := ctx.RegisterResource("azure:core/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:core/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 {
// The Alias name for the subscription. This provider will generate a new GUID if this is not supplied. Changing this forces a new Subscription to be created.
Alias *string `pulumi:"alias"`
BillingScopeId *string `pulumi:"billingScopeId"`
// The ID of the Subscription. Cannot be specified with `billingAccount`, `billingProfile`, `enrollmentAccount`, or `invoiceSection` Changing this forces a new Subscription to be created.
SubscriptionId *string `pulumi:"subscriptionId"`
// The Name of the Subscription. This is the Display Name in the portal.
SubscriptionName *string `pulumi:"subscriptionName"`
Tags map[string]string `pulumi:"tags"`
// The ID of the Tenant to which the subscription belongs.
TenantId *string `pulumi:"tenantId"`
// The workload type of the Subscription. Possible values are `Production` (default) and `DevTest`. Changing this forces a new Subscription to be created.
Workload *string `pulumi:"workload"`
}
type SubscriptionState struct {
// The Alias name for the subscription. This provider will generate a new GUID if this is not supplied. Changing this forces a new Subscription to be created.
Alias pulumi.StringPtrInput
BillingScopeId pulumi.StringPtrInput
// The ID of the Subscription. Cannot be specified with `billingAccount`, `billingProfile`, `enrollmentAccount`, or `invoiceSection` Changing this forces a new Subscription to be created.
SubscriptionId pulumi.StringPtrInput
// The Name of the Subscription. This is the Display Name in the portal.
SubscriptionName pulumi.StringPtrInput
Tags pulumi.StringMapInput
// The ID of the Tenant to which the subscription belongs.
TenantId pulumi.StringPtrInput
// The workload type of the Subscription. Possible values are `Production` (default) and `DevTest`. Changing this forces a new Subscription to be created.
Workload pulumi.StringPtrInput
}
func (SubscriptionState) ElementType() reflect.Type {
return reflect.TypeOf((*subscriptionState)(nil)).Elem()
}
type subscriptionArgs struct {
// The Alias name for the subscription. This provider will generate a new GUID if this is not supplied. Changing this forces a new Subscription to be created.
Alias *string `pulumi:"alias"`
BillingScopeId *string `pulumi:"billingScopeId"`
// The ID of the Subscription. Cannot be specified with `billingAccount`, `billingProfile`, `enrollmentAccount`, or `invoiceSection` Changing this forces a new Subscription to be created.
SubscriptionId *string `pulumi:"subscriptionId"`
// The Name of the Subscription. This is the Display Name in the portal.
SubscriptionName string `pulumi:"subscriptionName"`
// The workload type of the Subscription. Possible values are `Production` (default) and `DevTest`. Changing this forces a new Subscription to be created.
Workload *string `pulumi:"workload"`
}
// The set of arguments for constructing a Subscription resource.
type SubscriptionArgs struct {
// The Alias name for the subscription. This provider will generate a new GUID if this is not supplied. Changing this forces a new Subscription to be created.
Alias pulumi.StringPtrInput
BillingScopeId pulumi.StringPtrInput
// The ID of the Subscription. Cannot be specified with `billingAccount`, `billingProfile`, `enrollmentAccount`, or `invoiceSection` Changing this forces a new Subscription to be created.
SubscriptionId pulumi.StringPtrInput
// The Name of the Subscription. This is the Display Name in the portal.
SubscriptionName pulumi.StringInput
// The workload type of the Subscription. Possible values are `Production` (default) and `DevTest`. Changing this forces a new Subscription to be created.
Workload 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))
}
func (i *Subscription) ToSubscriptionOutput() SubscriptionOutput {
return i.ToSubscriptionOutputWithContext(context.Background())
}
func (i *Subscription) ToSubscriptionOutputWithContext(ctx context.Context) SubscriptionOutput {
return pulumi.ToOutputWithContext(ctx, i).(SubscriptionOutput)
}
func (i *Subscription) ToSubscriptionPtrOutput() SubscriptionPtrOutput {
return i.ToSubscriptionPtrOutputWithContext(context.Background())
}
func (i *Subscription) ToSubscriptionPtrOutputWithContext(ctx context.Context) SubscriptionPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(SubscriptionPtrOutput)
}
type SubscriptionPtrInput interface {
pulumi.Input
ToSubscriptionPtrOutput() SubscriptionPtrOutput
ToSubscriptionPtrOutputWithContext(ctx context.Context) SubscriptionPtrOutput
}
type subscriptionPtrType SubscriptionArgs
func (*subscriptionPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Subscription)(nil))
}
func (i *subscriptionPtrType) ToSubscriptionPtrOutput() SubscriptionPtrOutput {
return i.ToSubscriptionPtrOutputWithContext(context.Background())
}
func (i *subscriptionPtrType) ToSubscriptionPtrOutputWithContext(ctx context.Context) SubscriptionPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(SubscriptionPtrOutput)
}
// 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))
}
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))
}
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))
}
func (o SubscriptionOutput) ToSubscriptionOutput() SubscriptionOutput {
return o
}
func (o SubscriptionOutput) ToSubscriptionOutputWithContext(ctx context.Context) SubscriptionOutput {
return o
}
func (o SubscriptionOutput) ToSubscriptionPtrOutput() SubscriptionPtrOutput {
return o.ToSubscriptionPtrOutputWithContext(context.Background())
}
func (o SubscriptionOutput) ToSubscriptionPtrOutputWithContext(ctx context.Context) SubscriptionPtrOutput {
return o.ApplyT(func(v Subscription) *Subscription {
return &v
}).(SubscriptionPtrOutput)
}
type SubscriptionPtrOutput struct {
*pulumi.OutputState
}
func (SubscriptionPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Subscription)(nil))
}
func (o SubscriptionPtrOutput) ToSubscriptionPtrOutput() SubscriptionPtrOutput {
return o
}
func (o SubscriptionPtrOutput) ToSubscriptionPtrOutputWithContext(ctx context.Context) SubscriptionPtrOutput {
return o
}
type SubscriptionArrayOutput struct{ *pulumi.OutputState }
func (SubscriptionArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]Subscription)(nil))
}
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))
}
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.RegisterOutputType(SubscriptionOutput{})
pulumi.RegisterOutputType(SubscriptionPtrOutput{})
pulumi.RegisterOutputType(SubscriptionArrayOutput{})
pulumi.RegisterOutputType(SubscriptionMapOutput{})
}