/
remediation.go
402 lines (342 loc) · 16.3 KB
/
remediation.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
// *** 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 policy
import (
"context"
"reflect"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
// Manages an Azure Policy Remediation at the specified Scope.
//
// ## Example Usage
//
// ```go
// package main
//
// import (
// "fmt"
//
// "github.com/pulumi/pulumi-azure/sdk/v3/go/azure/core"
// "github.com/pulumi/pulumi-azure/sdk/v3/go/azure/policy"
// "github.com/pulumi/pulumi/sdk/v2/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
// }
// exampleDefinition, err := policy.NewDefinition(ctx, "exampleDefinition", &policy.DefinitionArgs{
// PolicyType: pulumi.String("Custom"),
// Mode: pulumi.String("All"),
// DisplayName: pulumi.String("my-policy-definition"),
// PolicyRule: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v", " {\n", " \"if\": {\n", " \"not\": {\n", " \"field\": \"location\",\n", " \"in\": \"[parameters('allowedLocations')]\"\n", " }\n", " },\n", " \"then\": {\n", " \"effect\": \"audit\"\n", " }\n", " }\n")),
// Parameters: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v", " {\n", " \"allowedLocations\": {\n", " \"type\": \"Array\",\n", " \"metadata\": {\n", " \"description\": \"The list of allowed locations for resources.\",\n", " \"displayName\": \"Allowed locations\",\n", " \"strongType\": \"location\"\n", " }\n", " }\n", " }\n")),
// })
// if err != nil {
// return err
// }
// exampleAssignment, err := policy.NewAssignment(ctx, "exampleAssignment", &policy.AssignmentArgs{
// Scope: exampleResourceGroup.ID(),
// PolicyDefinitionId: exampleDefinition.ID(),
// Description: pulumi.String("Policy Assignment created via an Acceptance Test"),
// DisplayName: pulumi.String("My Example Policy Assignment"),
// Parameters: pulumi.String(fmt.Sprintf("%v%v%v%v%v", "{\n", " \"allowedLocations\": {\n", " \"value\": [ \"West Europe\" ]\n", " }\n", "}\n")),
// })
// if err != nil {
// return err
// }
// _, err = policy.NewRemediation(ctx, "exampleRemediation", &policy.RemediationArgs{
// Scope: exampleAssignment.Scope,
// PolicyAssignmentId: exampleAssignment.ID(),
// LocationFilters: pulumi.StringArray{
// pulumi.String("West Europe"),
// },
// })
// if err != nil {
// return err
// }
// return nil
// })
// }
// ```
//
// ## Import
//
// Policy Remediations can be imported using the `resource id`, e.g.
//
// ```sh
// $ pulumi import azure:policy/remediation:Remediation example /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.PolicyInsights/remediations/remediation1
// ```
//
// or
//
// ```sh
// $ pulumi import azure:policy/remediation:Remediation example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.PolicyInsights/remediations/remediation1
// ```
//
// or
//
// ```sh
// $ pulumi import azure:policy/remediation:Remediation example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Compute/virtualMachines/vm1/providers/Microsoft.PolicyInsights/remediations/remediation1
// ```
//
// or
//
// ```sh
// $ pulumi import azure:policy/remediation:Remediation example /providers/Microsoft.Management/managementGroups/my-mgmt-group-id/providers/Microsoft.PolicyInsights/remediations/remediation1
// ```
type Remediation struct {
pulumi.CustomResourceState
// A list of the resource locations that will be remediated.
LocationFilters pulumi.StringArrayOutput `pulumi:"locationFilters"`
// The name of the Policy Remediation. Changing this forces a new resource to be created.
Name pulumi.StringOutput `pulumi:"name"`
// The ID of the Policy Assignment that should be remediated.
PolicyAssignmentId pulumi.StringOutput `pulumi:"policyAssignmentId"`
// The unique ID for the policy definition within the policy set definition that should be remediated. Required when the policy assignment being remediated assigns a policy set definition.
PolicyDefinitionReferenceId pulumi.StringPtrOutput `pulumi:"policyDefinitionReferenceId"`
// The way that resources to remediate are discovered. Possible values are `ExistingNonCompliant`, `ReEvaluateCompliance`. Defaults to `ExistingNonCompliant`.
ResourceDiscoveryMode pulumi.StringPtrOutput `pulumi:"resourceDiscoveryMode"`
// The Scope at which the Policy Remediation should be applied. Changing this forces a new resource to be created. A scope must be a Resource ID out of one of the following list:
Scope pulumi.StringOutput `pulumi:"scope"`
}
// NewRemediation registers a new resource with the given unique name, arguments, and options.
func NewRemediation(ctx *pulumi.Context,
name string, args *RemediationArgs, opts ...pulumi.ResourceOption) (*Remediation, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.PolicyAssignmentId == nil {
return nil, errors.New("invalid value for required argument 'PolicyAssignmentId'")
}
if args.Scope == nil {
return nil, errors.New("invalid value for required argument 'Scope'")
}
var resource Remediation
err := ctx.RegisterResource("azure:policy/remediation:Remediation", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetRemediation gets an existing Remediation 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 GetRemediation(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *RemediationState, opts ...pulumi.ResourceOption) (*Remediation, error) {
var resource Remediation
err := ctx.ReadResource("azure:policy/remediation:Remediation", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Remediation resources.
type remediationState struct {
// A list of the resource locations that will be remediated.
LocationFilters []string `pulumi:"locationFilters"`
// The name of the Policy Remediation. Changing this forces a new resource to be created.
Name *string `pulumi:"name"`
// The ID of the Policy Assignment that should be remediated.
PolicyAssignmentId *string `pulumi:"policyAssignmentId"`
// The unique ID for the policy definition within the policy set definition that should be remediated. Required when the policy assignment being remediated assigns a policy set definition.
PolicyDefinitionReferenceId *string `pulumi:"policyDefinitionReferenceId"`
// The way that resources to remediate are discovered. Possible values are `ExistingNonCompliant`, `ReEvaluateCompliance`. Defaults to `ExistingNonCompliant`.
ResourceDiscoveryMode *string `pulumi:"resourceDiscoveryMode"`
// The Scope at which the Policy Remediation should be applied. Changing this forces a new resource to be created. A scope must be a Resource ID out of one of the following list:
Scope *string `pulumi:"scope"`
}
type RemediationState struct {
// A list of the resource locations that will be remediated.
LocationFilters pulumi.StringArrayInput
// The name of the Policy Remediation. Changing this forces a new resource to be created.
Name pulumi.StringPtrInput
// The ID of the Policy Assignment that should be remediated.
PolicyAssignmentId pulumi.StringPtrInput
// The unique ID for the policy definition within the policy set definition that should be remediated. Required when the policy assignment being remediated assigns a policy set definition.
PolicyDefinitionReferenceId pulumi.StringPtrInput
// The way that resources to remediate are discovered. Possible values are `ExistingNonCompliant`, `ReEvaluateCompliance`. Defaults to `ExistingNonCompliant`.
ResourceDiscoveryMode pulumi.StringPtrInput
// The Scope at which the Policy Remediation should be applied. Changing this forces a new resource to be created. A scope must be a Resource ID out of one of the following list:
Scope pulumi.StringPtrInput
}
func (RemediationState) ElementType() reflect.Type {
return reflect.TypeOf((*remediationState)(nil)).Elem()
}
type remediationArgs struct {
// A list of the resource locations that will be remediated.
LocationFilters []string `pulumi:"locationFilters"`
// The name of the Policy Remediation. Changing this forces a new resource to be created.
Name *string `pulumi:"name"`
// The ID of the Policy Assignment that should be remediated.
PolicyAssignmentId string `pulumi:"policyAssignmentId"`
// The unique ID for the policy definition within the policy set definition that should be remediated. Required when the policy assignment being remediated assigns a policy set definition.
PolicyDefinitionReferenceId *string `pulumi:"policyDefinitionReferenceId"`
// The way that resources to remediate are discovered. Possible values are `ExistingNonCompliant`, `ReEvaluateCompliance`. Defaults to `ExistingNonCompliant`.
ResourceDiscoveryMode *string `pulumi:"resourceDiscoveryMode"`
// The Scope at which the Policy Remediation should be applied. Changing this forces a new resource to be created. A scope must be a Resource ID out of one of the following list:
Scope string `pulumi:"scope"`
}
// The set of arguments for constructing a Remediation resource.
type RemediationArgs struct {
// A list of the resource locations that will be remediated.
LocationFilters pulumi.StringArrayInput
// The name of the Policy Remediation. Changing this forces a new resource to be created.
Name pulumi.StringPtrInput
// The ID of the Policy Assignment that should be remediated.
PolicyAssignmentId pulumi.StringInput
// The unique ID for the policy definition within the policy set definition that should be remediated. Required when the policy assignment being remediated assigns a policy set definition.
PolicyDefinitionReferenceId pulumi.StringPtrInput
// The way that resources to remediate are discovered. Possible values are `ExistingNonCompliant`, `ReEvaluateCompliance`. Defaults to `ExistingNonCompliant`.
ResourceDiscoveryMode pulumi.StringPtrInput
// The Scope at which the Policy Remediation should be applied. Changing this forces a new resource to be created. A scope must be a Resource ID out of one of the following list:
Scope pulumi.StringInput
}
func (RemediationArgs) ElementType() reflect.Type {
return reflect.TypeOf((*remediationArgs)(nil)).Elem()
}
type RemediationInput interface {
pulumi.Input
ToRemediationOutput() RemediationOutput
ToRemediationOutputWithContext(ctx context.Context) RemediationOutput
}
func (*Remediation) ElementType() reflect.Type {
return reflect.TypeOf((*Remediation)(nil))
}
func (i *Remediation) ToRemediationOutput() RemediationOutput {
return i.ToRemediationOutputWithContext(context.Background())
}
func (i *Remediation) ToRemediationOutputWithContext(ctx context.Context) RemediationOutput {
return pulumi.ToOutputWithContext(ctx, i).(RemediationOutput)
}
func (i *Remediation) ToRemediationPtrOutput() RemediationPtrOutput {
return i.ToRemediationPtrOutputWithContext(context.Background())
}
func (i *Remediation) ToRemediationPtrOutputWithContext(ctx context.Context) RemediationPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(RemediationPtrOutput)
}
type RemediationPtrInput interface {
pulumi.Input
ToRemediationPtrOutput() RemediationPtrOutput
ToRemediationPtrOutputWithContext(ctx context.Context) RemediationPtrOutput
}
type remediationPtrType RemediationArgs
func (*remediationPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Remediation)(nil))
}
func (i *remediationPtrType) ToRemediationPtrOutput() RemediationPtrOutput {
return i.ToRemediationPtrOutputWithContext(context.Background())
}
func (i *remediationPtrType) ToRemediationPtrOutputWithContext(ctx context.Context) RemediationPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(RemediationPtrOutput)
}
// RemediationArrayInput is an input type that accepts RemediationArray and RemediationArrayOutput values.
// You can construct a concrete instance of `RemediationArrayInput` via:
//
// RemediationArray{ RemediationArgs{...} }
type RemediationArrayInput interface {
pulumi.Input
ToRemediationArrayOutput() RemediationArrayOutput
ToRemediationArrayOutputWithContext(context.Context) RemediationArrayOutput
}
type RemediationArray []RemediationInput
func (RemediationArray) ElementType() reflect.Type {
return reflect.TypeOf(([]*Remediation)(nil))
}
func (i RemediationArray) ToRemediationArrayOutput() RemediationArrayOutput {
return i.ToRemediationArrayOutputWithContext(context.Background())
}
func (i RemediationArray) ToRemediationArrayOutputWithContext(ctx context.Context) RemediationArrayOutput {
return pulumi.ToOutputWithContext(ctx, i).(RemediationArrayOutput)
}
// RemediationMapInput is an input type that accepts RemediationMap and RemediationMapOutput values.
// You can construct a concrete instance of `RemediationMapInput` via:
//
// RemediationMap{ "key": RemediationArgs{...} }
type RemediationMapInput interface {
pulumi.Input
ToRemediationMapOutput() RemediationMapOutput
ToRemediationMapOutputWithContext(context.Context) RemediationMapOutput
}
type RemediationMap map[string]RemediationInput
func (RemediationMap) ElementType() reflect.Type {
return reflect.TypeOf((map[string]*Remediation)(nil))
}
func (i RemediationMap) ToRemediationMapOutput() RemediationMapOutput {
return i.ToRemediationMapOutputWithContext(context.Background())
}
func (i RemediationMap) ToRemediationMapOutputWithContext(ctx context.Context) RemediationMapOutput {
return pulumi.ToOutputWithContext(ctx, i).(RemediationMapOutput)
}
type RemediationOutput struct {
*pulumi.OutputState
}
func (RemediationOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Remediation)(nil))
}
func (o RemediationOutput) ToRemediationOutput() RemediationOutput {
return o
}
func (o RemediationOutput) ToRemediationOutputWithContext(ctx context.Context) RemediationOutput {
return o
}
func (o RemediationOutput) ToRemediationPtrOutput() RemediationPtrOutput {
return o.ToRemediationPtrOutputWithContext(context.Background())
}
func (o RemediationOutput) ToRemediationPtrOutputWithContext(ctx context.Context) RemediationPtrOutput {
return o.ApplyT(func(v Remediation) *Remediation {
return &v
}).(RemediationPtrOutput)
}
type RemediationPtrOutput struct {
*pulumi.OutputState
}
func (RemediationPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Remediation)(nil))
}
func (o RemediationPtrOutput) ToRemediationPtrOutput() RemediationPtrOutput {
return o
}
func (o RemediationPtrOutput) ToRemediationPtrOutputWithContext(ctx context.Context) RemediationPtrOutput {
return o
}
type RemediationArrayOutput struct{ *pulumi.OutputState }
func (RemediationArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]Remediation)(nil))
}
func (o RemediationArrayOutput) ToRemediationArrayOutput() RemediationArrayOutput {
return o
}
func (o RemediationArrayOutput) ToRemediationArrayOutputWithContext(ctx context.Context) RemediationArrayOutput {
return o
}
func (o RemediationArrayOutput) Index(i pulumi.IntInput) RemediationOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) Remediation {
return vs[0].([]Remediation)[vs[1].(int)]
}).(RemediationOutput)
}
type RemediationMapOutput struct{ *pulumi.OutputState }
func (RemediationMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]Remediation)(nil))
}
func (o RemediationMapOutput) ToRemediationMapOutput() RemediationMapOutput {
return o
}
func (o RemediationMapOutput) ToRemediationMapOutputWithContext(ctx context.Context) RemediationMapOutput {
return o
}
func (o RemediationMapOutput) MapIndex(k pulumi.StringInput) RemediationOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) Remediation {
return vs[0].(map[string]Remediation)[vs[1].(string)]
}).(RemediationOutput)
}
func init() {
pulumi.RegisterOutputType(RemediationOutput{})
pulumi.RegisterOutputType(RemediationPtrOutput{})
pulumi.RegisterOutputType(RemediationArrayOutput{})
pulumi.RegisterOutputType(RemediationMapOutput{})
}