/
extension.go
486 lines (440 loc) · 19.4 KB
/
extension.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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
// *** 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 compute
import (
"context"
"reflect"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Manages a Virtual Machine Extension to provide post deployment configuration
// and run automated tasks.
//
// > **NOTE:** Custom Script Extensions for Linux & Windows require that the `commandToExecute` returns a `0` exit code to be classified as successfully deployed. You can achieve this by appending `exit 0` to the end of your `commandToExecute`.
//
// > **NOTE:** Custom Script Extensions require that the Azure Virtual Machine Guest Agent is running on the Virtual Machine.
//
// ## Example Usage
//
// ```go
// package main
//
// import (
// "fmt"
//
// "github.com/pulumi/pulumi-azure/sdk/v4/go/azure/compute"
// "github.com/pulumi/pulumi-azure/sdk/v4/go/azure/core"
// "github.com/pulumi/pulumi-azure/sdk/v4/go/azure/network"
// "github.com/pulumi/pulumi-azure/sdk/v4/go/azure/storage"
// "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
// )
//
// func main() {
// pulumi.Run(func(ctx *pulumi.Context) error {
// exampleResourceGroup, err := core.NewResourceGroup(ctx, "exampleResourceGroup", &core.ResourceGroupArgs{
// Location: pulumi.String("West Europe"),
// })
// if err != nil {
// return err
// }
// exampleVirtualNetwork, err := network.NewVirtualNetwork(ctx, "exampleVirtualNetwork", &network.VirtualNetworkArgs{
// AddressSpaces: pulumi.StringArray{
// pulumi.String("10.0.0.0/16"),
// },
// Location: exampleResourceGroup.Location,
// ResourceGroupName: exampleResourceGroup.Name,
// })
// if err != nil {
// return err
// }
// exampleSubnet, err := network.NewSubnet(ctx, "exampleSubnet", &network.SubnetArgs{
// ResourceGroupName: exampleResourceGroup.Name,
// VirtualNetworkName: exampleVirtualNetwork.Name,
// AddressPrefixes: pulumi.StringArray{
// pulumi.String("10.0.2.0/24"),
// },
// })
// if err != nil {
// return err
// }
// exampleNetworkInterface, err := network.NewNetworkInterface(ctx, "exampleNetworkInterface", &network.NetworkInterfaceArgs{
// Location: exampleResourceGroup.Location,
// ResourceGroupName: exampleResourceGroup.Name,
// IpConfigurations: network.NetworkInterfaceIpConfigurationArray{
// &network.NetworkInterfaceIpConfigurationArgs{
// Name: pulumi.String("testconfiguration1"),
// SubnetId: exampleSubnet.ID(),
// PrivateIpAddressAllocation: pulumi.String("Dynamic"),
// },
// },
// })
// if err != nil {
// return err
// }
// exampleAccount, err := storage.NewAccount(ctx, "exampleAccount", &storage.AccountArgs{
// ResourceGroupName: exampleResourceGroup.Name,
// Location: exampleResourceGroup.Location,
// AccountTier: pulumi.String("Standard"),
// AccountReplicationType: pulumi.String("LRS"),
// Tags: pulumi.StringMap{
// "environment": pulumi.String("staging"),
// },
// })
// if err != nil {
// return err
// }
// exampleContainer, err := storage.NewContainer(ctx, "exampleContainer", &storage.ContainerArgs{
// StorageAccountName: exampleAccount.Name,
// ContainerAccessType: pulumi.String("private"),
// })
// if err != nil {
// return err
// }
// exampleVirtualMachine, err := compute.NewVirtualMachine(ctx, "exampleVirtualMachine", &compute.VirtualMachineArgs{
// Location: exampleResourceGroup.Location,
// ResourceGroupName: exampleResourceGroup.Name,
// NetworkInterfaceIds: pulumi.StringArray{
// exampleNetworkInterface.ID(),
// },
// VmSize: pulumi.String("Standard_F2"),
// StorageImageReference: &compute.VirtualMachineStorageImageReferenceArgs{
// Publisher: pulumi.String("Canonical"),
// Offer: pulumi.String("UbuntuServer"),
// Sku: pulumi.String("16.04-LTS"),
// Version: pulumi.String("latest"),
// },
// StorageOsDisk: &compute.VirtualMachineStorageOsDiskArgs{
// Name: pulumi.String("myosdisk1"),
// VhdUri: pulumi.All(exampleAccount.PrimaryBlobEndpoint, exampleContainer.Name).ApplyT(func(_args []interface{}) (string, error) {
// primaryBlobEndpoint := _args[0].(string)
// name := _args[1].(string)
// return fmt.Sprintf("%v%v%v", primaryBlobEndpoint, name, "/myosdisk1.vhd"), nil
// }).(pulumi.StringOutput),
// Caching: pulumi.String("ReadWrite"),
// CreateOption: pulumi.String("FromImage"),
// },
// OsProfile: &compute.VirtualMachineOsProfileArgs{
// ComputerName: pulumi.String("hostname"),
// AdminUsername: pulumi.String("testadmin"),
// AdminPassword: pulumi.String("Password1234!"),
// },
// OsProfileLinuxConfig: &compute.VirtualMachineOsProfileLinuxConfigArgs{
// DisablePasswordAuthentication: pulumi.Bool(false),
// },
// Tags: pulumi.StringMap{
// "environment": pulumi.String("staging"),
// },
// })
// if err != nil {
// return err
// }
// _, err = compute.NewExtension(ctx, "exampleExtension", &compute.ExtensionArgs{
// VirtualMachineId: exampleVirtualMachine.ID(),
// Publisher: pulumi.String("Microsoft.Azure.Extensions"),
// Type: pulumi.String("CustomScript"),
// TypeHandlerVersion: pulumi.String("2.0"),
// Settings: pulumi.String(fmt.Sprintf("%v%v%v", " {\n", " \"commandToExecute\": \"hostname && uptime\"\n", " }\n")),
// Tags: pulumi.StringMap{
// "environment": pulumi.String("Production"),
// },
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
//
// ## Import
//
// Virtual Machine Extensions can be imported using the `resource id`, e.g.
//
// ```sh
// $ pulumi import azure:compute/extension:Extension example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Compute/virtualMachines/myVM/extensions/extensionName
// ```
type Extension struct {
pulumi.CustomResourceState
// Specifies if the platform deploys
// the latest minor version update to the `typeHandlerVersion` specified.
AutoUpgradeMinorVersion pulumi.BoolPtrOutput `pulumi:"autoUpgradeMinorVersion"`
// Should the Extension be automatically updated whenever the Publisher releases a new version of this VM Extension? Defaults to `false`.
AutomaticUpgradeEnabled pulumi.BoolPtrOutput `pulumi:"automaticUpgradeEnabled"`
// The name of the virtual machine extension peering. Changing
// this forces a new resource to be created.
Name pulumi.StringOutput `pulumi:"name"`
// The protectedSettings passed to the
// extension, like settings, these are specified as a JSON object in a string.
ProtectedSettings pulumi.StringPtrOutput `pulumi:"protectedSettings"`
// The publisher of the extension, available publishers can be found by using the Azure CLI. Changing this forces a new resource to be created.
Publisher pulumi.StringOutput `pulumi:"publisher"`
// The settings passed to the extension, these are
// specified as a JSON object in a string.
Settings pulumi.StringPtrOutput `pulumi:"settings"`
// A mapping of tags to assign to the resource.
Tags pulumi.StringMapOutput `pulumi:"tags"`
// The type of extension, available types for a publisher can
// be found using the Azure CLI.
Type pulumi.StringOutput `pulumi:"type"`
// Specifies the version of the extension to
// use, available versions can be found using the Azure CLI.
TypeHandlerVersion pulumi.StringOutput `pulumi:"typeHandlerVersion"`
// The ID of the Virtual Machine. Changing this forces a new resource to be created
VirtualMachineId pulumi.StringOutput `pulumi:"virtualMachineId"`
}
// NewExtension registers a new resource with the given unique name, arguments, and options.
func NewExtension(ctx *pulumi.Context,
name string, args *ExtensionArgs, opts ...pulumi.ResourceOption) (*Extension, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.Publisher == nil {
return nil, errors.New("invalid value for required argument 'Publisher'")
}
if args.Type == nil {
return nil, errors.New("invalid value for required argument 'Type'")
}
if args.TypeHandlerVersion == nil {
return nil, errors.New("invalid value for required argument 'TypeHandlerVersion'")
}
if args.VirtualMachineId == nil {
return nil, errors.New("invalid value for required argument 'VirtualMachineId'")
}
var resource Extension
err := ctx.RegisterResource("azure:compute/extension:Extension", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetExtension gets an existing Extension 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 GetExtension(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *ExtensionState, opts ...pulumi.ResourceOption) (*Extension, error) {
var resource Extension
err := ctx.ReadResource("azure:compute/extension:Extension", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Extension resources.
type extensionState struct {
// Specifies if the platform deploys
// the latest minor version update to the `typeHandlerVersion` specified.
AutoUpgradeMinorVersion *bool `pulumi:"autoUpgradeMinorVersion"`
// Should the Extension be automatically updated whenever the Publisher releases a new version of this VM Extension? Defaults to `false`.
AutomaticUpgradeEnabled *bool `pulumi:"automaticUpgradeEnabled"`
// The name of the virtual machine extension peering. Changing
// this forces a new resource to be created.
Name *string `pulumi:"name"`
// The protectedSettings passed to the
// extension, like settings, these are specified as a JSON object in a string.
ProtectedSettings *string `pulumi:"protectedSettings"`
// The publisher of the extension, available publishers can be found by using the Azure CLI. Changing this forces a new resource to be created.
Publisher *string `pulumi:"publisher"`
// The settings passed to the extension, these are
// specified as a JSON object in a string.
Settings *string `pulumi:"settings"`
// A mapping of tags to assign to the resource.
Tags map[string]string `pulumi:"tags"`
// The type of extension, available types for a publisher can
// be found using the Azure CLI.
Type *string `pulumi:"type"`
// Specifies the version of the extension to
// use, available versions can be found using the Azure CLI.
TypeHandlerVersion *string `pulumi:"typeHandlerVersion"`
// The ID of the Virtual Machine. Changing this forces a new resource to be created
VirtualMachineId *string `pulumi:"virtualMachineId"`
}
type ExtensionState struct {
// Specifies if the platform deploys
// the latest minor version update to the `typeHandlerVersion` specified.
AutoUpgradeMinorVersion pulumi.BoolPtrInput
// Should the Extension be automatically updated whenever the Publisher releases a new version of this VM Extension? Defaults to `false`.
AutomaticUpgradeEnabled pulumi.BoolPtrInput
// The name of the virtual machine extension peering. Changing
// this forces a new resource to be created.
Name pulumi.StringPtrInput
// The protectedSettings passed to the
// extension, like settings, these are specified as a JSON object in a string.
ProtectedSettings pulumi.StringPtrInput
// The publisher of the extension, available publishers can be found by using the Azure CLI. Changing this forces a new resource to be created.
Publisher pulumi.StringPtrInput
// The settings passed to the extension, these are
// specified as a JSON object in a string.
Settings pulumi.StringPtrInput
// A mapping of tags to assign to the resource.
Tags pulumi.StringMapInput
// The type of extension, available types for a publisher can
// be found using the Azure CLI.
Type pulumi.StringPtrInput
// Specifies the version of the extension to
// use, available versions can be found using the Azure CLI.
TypeHandlerVersion pulumi.StringPtrInput
// The ID of the Virtual Machine. Changing this forces a new resource to be created
VirtualMachineId pulumi.StringPtrInput
}
func (ExtensionState) ElementType() reflect.Type {
return reflect.TypeOf((*extensionState)(nil)).Elem()
}
type extensionArgs struct {
// Specifies if the platform deploys
// the latest minor version update to the `typeHandlerVersion` specified.
AutoUpgradeMinorVersion *bool `pulumi:"autoUpgradeMinorVersion"`
// Should the Extension be automatically updated whenever the Publisher releases a new version of this VM Extension? Defaults to `false`.
AutomaticUpgradeEnabled *bool `pulumi:"automaticUpgradeEnabled"`
// The name of the virtual machine extension peering. Changing
// this forces a new resource to be created.
Name *string `pulumi:"name"`
// The protectedSettings passed to the
// extension, like settings, these are specified as a JSON object in a string.
ProtectedSettings *string `pulumi:"protectedSettings"`
// The publisher of the extension, available publishers can be found by using the Azure CLI. Changing this forces a new resource to be created.
Publisher string `pulumi:"publisher"`
// The settings passed to the extension, these are
// specified as a JSON object in a string.
Settings *string `pulumi:"settings"`
// A mapping of tags to assign to the resource.
Tags map[string]string `pulumi:"tags"`
// The type of extension, available types for a publisher can
// be found using the Azure CLI.
Type string `pulumi:"type"`
// Specifies the version of the extension to
// use, available versions can be found using the Azure CLI.
TypeHandlerVersion string `pulumi:"typeHandlerVersion"`
// The ID of the Virtual Machine. Changing this forces a new resource to be created
VirtualMachineId string `pulumi:"virtualMachineId"`
}
// The set of arguments for constructing a Extension resource.
type ExtensionArgs struct {
// Specifies if the platform deploys
// the latest minor version update to the `typeHandlerVersion` specified.
AutoUpgradeMinorVersion pulumi.BoolPtrInput
// Should the Extension be automatically updated whenever the Publisher releases a new version of this VM Extension? Defaults to `false`.
AutomaticUpgradeEnabled pulumi.BoolPtrInput
// The name of the virtual machine extension peering. Changing
// this forces a new resource to be created.
Name pulumi.StringPtrInput
// The protectedSettings passed to the
// extension, like settings, these are specified as a JSON object in a string.
ProtectedSettings pulumi.StringPtrInput
// The publisher of the extension, available publishers can be found by using the Azure CLI. Changing this forces a new resource to be created.
Publisher pulumi.StringInput
// The settings passed to the extension, these are
// specified as a JSON object in a string.
Settings pulumi.StringPtrInput
// A mapping of tags to assign to the resource.
Tags pulumi.StringMapInput
// The type of extension, available types for a publisher can
// be found using the Azure CLI.
Type pulumi.StringInput
// Specifies the version of the extension to
// use, available versions can be found using the Azure CLI.
TypeHandlerVersion pulumi.StringInput
// The ID of the Virtual Machine. Changing this forces a new resource to be created
VirtualMachineId pulumi.StringInput
}
func (ExtensionArgs) ElementType() reflect.Type {
return reflect.TypeOf((*extensionArgs)(nil)).Elem()
}
type ExtensionInput interface {
pulumi.Input
ToExtensionOutput() ExtensionOutput
ToExtensionOutputWithContext(ctx context.Context) ExtensionOutput
}
func (*Extension) ElementType() reflect.Type {
return reflect.TypeOf((**Extension)(nil)).Elem()
}
func (i *Extension) ToExtensionOutput() ExtensionOutput {
return i.ToExtensionOutputWithContext(context.Background())
}
func (i *Extension) ToExtensionOutputWithContext(ctx context.Context) ExtensionOutput {
return pulumi.ToOutputWithContext(ctx, i).(ExtensionOutput)
}
// ExtensionArrayInput is an input type that accepts ExtensionArray and ExtensionArrayOutput values.
// You can construct a concrete instance of `ExtensionArrayInput` via:
//
// ExtensionArray{ ExtensionArgs{...} }
type ExtensionArrayInput interface {
pulumi.Input
ToExtensionArrayOutput() ExtensionArrayOutput
ToExtensionArrayOutputWithContext(context.Context) ExtensionArrayOutput
}
type ExtensionArray []ExtensionInput
func (ExtensionArray) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Extension)(nil)).Elem()
}
func (i ExtensionArray) ToExtensionArrayOutput() ExtensionArrayOutput {
return i.ToExtensionArrayOutputWithContext(context.Background())
}
func (i ExtensionArray) ToExtensionArrayOutputWithContext(ctx context.Context) ExtensionArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(ExtensionArrayOutput)
}
// ExtensionMapInput is an input type that accepts ExtensionMap and ExtensionMapOutput values.
// You can construct a concrete instance of `ExtensionMapInput` via:
//
// ExtensionMap{ "key": ExtensionArgs{...} }
type ExtensionMapInput interface {
pulumi.Input
ToExtensionMapOutput() ExtensionMapOutput
ToExtensionMapOutputWithContext(context.Context) ExtensionMapOutput
}
type ExtensionMap map[string]ExtensionInput
func (ExtensionMap) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Extension)(nil)).Elem()
}
func (i ExtensionMap) ToExtensionMapOutput() ExtensionMapOutput {
return i.ToExtensionMapOutputWithContext(context.Background())
}
func (i ExtensionMap) ToExtensionMapOutputWithContext(ctx context.Context) ExtensionMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(ExtensionMapOutput)
}
type ExtensionOutput struct{ *pulumi.OutputState }
func (ExtensionOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Extension)(nil)).Elem()
}
func (o ExtensionOutput) ToExtensionOutput() ExtensionOutput {
return o
}
func (o ExtensionOutput) ToExtensionOutputWithContext(ctx context.Context) ExtensionOutput {
return o
}
type ExtensionArrayOutput struct{ *pulumi.OutputState }
func (ExtensionArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]*Extension)(nil)).Elem()
}
func (o ExtensionArrayOutput) ToExtensionArrayOutput() ExtensionArrayOutput {
return o
}
func (o ExtensionArrayOutput) ToExtensionArrayOutputWithContext(ctx context.Context) ExtensionArrayOutput {
return o
}
func (o ExtensionArrayOutput) Index(i pulumi.IntInput) ExtensionOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Extension {
return vs[0].([]*Extension)[vs[1].(int)]
}).(ExtensionOutput)
}
type ExtensionMapOutput struct{ *pulumi.OutputState }
func (ExtensionMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]*Extension)(nil)).Elem()
}
func (o ExtensionMapOutput) ToExtensionMapOutput() ExtensionMapOutput {
return o
}
func (o ExtensionMapOutput) ToExtensionMapOutputWithContext(ctx context.Context) ExtensionMapOutput {
return o
}
func (o ExtensionMapOutput) MapIndex(k pulumi.StringInput) ExtensionOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Extension {
return vs[0].(map[string]*Extension)[vs[1].(string)]
}).(ExtensionOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*ExtensionInput)(nil)).Elem(), &Extension{})
pulumi.RegisterInputType(reflect.TypeOf((*ExtensionArrayInput)(nil)).Elem(), ExtensionArray{})
pulumi.RegisterInputType(reflect.TypeOf((*ExtensionMapInput)(nil)).Elem(), ExtensionMap{})
pulumi.RegisterOutputType(ExtensionOutput{})
pulumi.RegisterOutputType(ExtensionArrayOutput{})
pulumi.RegisterOutputType(ExtensionMapOutput{})
}