forked from integrations/terraform-provider-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource_github_organization_ruleset.go
More file actions
715 lines (682 loc) · 25.7 KB
/
resource_github_organization_ruleset.go
File metadata and controls
715 lines (682 loc) · 25.7 KB
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
package github
import (
"context"
"errors"
"fmt"
"log"
"net/http"
"strconv"
"github.com/google/go-github/v67/github"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func resourceGithubOrganizationRuleset() *schema.Resource {
return &schema.Resource{
Create: resourceGithubOrganizationRulesetCreate,
Read: resourceGithubOrganizationRulesetRead,
Update: resourceGithubOrganizationRulesetUpdate,
Delete: resourceGithubOrganizationRulesetDelete,
Importer: &schema.ResourceImporter{
State: resourceGithubOrganizationRulesetImport,
},
SchemaVersion: 1,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
Description: "The name of the ruleset.",
},
"target": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"branch", "tag", "push"}, false),
Description: "Possible values are `branch`, `tag` and `push`. Note: The `push` target is in beta and is subject to change.",
},
"enforcement": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"disabled", "active", "evaluate"}, false),
Description: "Possible values for Enforcement are `disabled`, `active`, `evaluate`. Note: `evaluate` is currently only supported for owners of type `organization`.",
},
"bypass_actors": {
Type: schema.TypeList,
Optional: true,
DiffSuppressFunc: bypassActorsDiffSuppressFunc,
Description: "The actors that can bypass the rules in this ruleset.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"actor_id": {
Type: schema.TypeInt,
Optional: true,
Default: nil,
Description: "The ID of the actor that can bypass a ruleset. When `actor_type` is `OrganizationAdmin`, this should be set to `1`. Some resources such as DeployKey do not have an ID and this should be omitted.",
},
"actor_type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"Integration", "OrganizationAdmin", "RepositoryRole", "Team", "DeployKey"}, false),
Description: "The type of actor that can bypass a ruleset. See https://docs.github.com/en/rest/orgs/rules for more information",
},
"bypass_mode": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"always", "pull_request", "exempt"}, false),
Description: "When the specified actor can bypass the ruleset. pull_request means that an actor can only bypass rules on pull requests. Can be one of: `always`, `pull_request`, `exempt`.",
},
},
},
},
"node_id": {
Type: schema.TypeString,
Computed: true,
Description: "GraphQL global node id for use with v4 API.",
},
"ruleset_id": {
Type: schema.TypeInt,
Computed: true,
Description: "GitHub ID for the ruleset.",
},
"conditions": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Parameters for an organization ruleset condition. `ref_name` is required alongside one of `repository_name` or `repository_id`.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ref_name": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"include": {
Type: schema.TypeList,
Required: true,
Description: "Array of ref names or patterns to include. One of these patterns must match for the condition to pass. Also accepts `~DEFAULT_BRANCH` to include the default branch or `~ALL` to include all branches.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"exclude": {
Type: schema.TypeList,
Required: true,
Description: "Array of ref names or patterns to exclude. The condition will not pass if any of these patterns match.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"repository_name": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ExactlyOneOf: []string{"conditions.0.repository_id"},
AtLeastOneOf: []string{"conditions.0.repository_id"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"include": {
Type: schema.TypeList,
Required: true,
Description: "Array of repository names or patterns to include. One of these patterns must match for the condition to pass. Also accepts `~ALL` to include all repositories.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"exclude": {
Type: schema.TypeList,
Required: true,
Description: "Array of repository names or patterns to exclude. The condition will not pass if any of these patterns match.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"protected": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether renaming of target repositories is prevented.",
},
},
},
},
"repository_id": {
Type: schema.TypeList,
Optional: true,
Description: "The repository IDs that the ruleset applies to. One of these IDs must match for the condition to pass.",
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
},
},
"rules": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Description: "Rules within the ruleset.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"creation": {
Type: schema.TypeBool,
Optional: true,
Description: "Only allow users with bypass permission to create matching refs.",
},
"update": {
Type: schema.TypeBool,
Optional: true,
Description: "Only allow users with bypass permission to update matching refs.",
},
"deletion": {
Type: schema.TypeBool,
Optional: true,
Description: "Only allow users with bypass permissions to delete matching refs.",
},
"required_linear_history": {
Type: schema.TypeBool,
Optional: true,
Description: "Prevent merge commits from being pushed to matching branches.",
},
"required_signatures": {
Type: schema.TypeBool,
Optional: true,
Description: "Commits pushed to matching branches must have verified signatures.",
},
"pull_request": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Require all commits be made to a non-target branch and submitted via a pull request before they can be merged.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dismiss_stale_reviews_on_push": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "New, reviewable commits pushed will dismiss previous pull request review approvals. Defaults to `false`.",
},
"require_code_owner_review": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Require an approving review in pull requests that modify files that have a designated code owner. Defaults to `false`.",
},
"require_last_push_approval": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Whether the most recent reviewable push must be approved by someone other than the person who pushed it. Defaults to `false`.",
},
"required_approving_review_count": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The number of approving reviews that are required before a pull request can be merged. Defaults to `0`.",
},
"required_review_thread_resolution": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "All conversations on code must be resolved before a pull request can be merged. Defaults to `false`.",
},
},
},
},
"required_status_checks": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Choose which status checks must pass before branches can be merged into a branch that matches this rule. When enabled, commits must first be pushed to another branch, then merged or pushed directly to a branch that matches this rule after status checks have passed.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"required_check": {
Type: schema.TypeSet,
MinItems: 1,
Required: true,
Description: "Status checks that are required. Several can be defined.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"context": {
Type: schema.TypeString,
Required: true,
Description: "The status check context name that must be present on the commit.",
},
"integration_id": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The optional integration ID that this status check must originate from.",
},
},
},
},
"strict_required_status_checks_policy": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether pull requests targeting a matching branch must be tested with the latest code. This setting will not take effect unless at least one status check is enabled. Defaults to `false`.",
},
"do_not_enforce_on_create": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow repositories and branches to be created if a check would otherwise prohibit it.",
Default: false,
},
},
},
},
"non_fast_forward": {
Type: schema.TypeBool,
Optional: true,
Description: "Prevent users with push access from force pushing to branches.",
},
"commit_message_pattern": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Parameters to be used for the commit_message_pattern rule.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "How this rule will appear to users.",
},
"negate": {
Type: schema.TypeBool,
Optional: true,
Description: "If true, the rule will fail if the pattern matches.",
},
"operator": {
Type: schema.TypeString,
Required: true,
Description: "The operator to use for matching. Can be one of: `starts_with`, `ends_with`, `contains`, `regex`.",
},
"pattern": {
Type: schema.TypeString,
Required: true,
Description: "The pattern to match with.",
},
},
},
},
"commit_author_email_pattern": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Parameters to be used for the commit_author_email_pattern rule.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "How this rule will appear to users.",
},
"negate": {
Type: schema.TypeBool,
Optional: true,
Description: "If true, the rule will fail if the pattern matches.",
},
"operator": {
Type: schema.TypeString,
Required: true,
Description: "The operator to use for matching. Can be one of: `starts_with`, `ends_with`, `contains`, `regex`.",
},
"pattern": {
Type: schema.TypeString,
Required: true,
Description: "The pattern to match with.",
},
},
},
},
"committer_email_pattern": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Parameters to be used for the committer_email_pattern rule.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "How this rule will appear to users.",
},
"negate": {
Type: schema.TypeBool,
Optional: true,
Description: "If true, the rule will fail if the pattern matches.",
},
"operator": {
Type: schema.TypeString,
Required: true,
Description: "The operator to use for matching. Can be one of: `starts_with`, `ends_with`, `contains`, `regex`.",
},
"pattern": {
Type: schema.TypeString,
Required: true,
Description: "The pattern to match with.",
},
},
},
},
"branch_name_pattern": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ConflictsWith: []string{"rules.0.tag_name_pattern"},
Description: "Parameters to be used for the branch_name_pattern rule. This rule only applies to repositories within an enterprise, it cannot be applied to repositories owned by individuals or regular organizations. Conflicts with `tag_name_pattern` as it only applies to rulesets with target `branch`.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "How this rule will appear to users.",
},
"negate": {
Type: schema.TypeBool,
Optional: true,
Description: "If true, the rule will fail if the pattern matches.",
},
"operator": {
Type: schema.TypeString,
Required: true,
Description: "The operator to use for matching. Can be one of: `starts_with`, `ends_with`, `contains`, `regex`.",
},
"pattern": {
Type: schema.TypeString,
Required: true,
Description: "The pattern to match with.",
},
},
},
},
"tag_name_pattern": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ConflictsWith: []string{"rules.0.branch_name_pattern"},
Description: "Parameters to be used for the tag_name_pattern rule. This rule only applies to repositories within an enterprise, it cannot be applied to repositories owned by individuals or regular organizations. Conflicts with `branch_name_pattern` as it only applies to rulesets with target `tag`.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Optional: true,
Description: "How this rule will appear to users.",
},
"negate": {
Type: schema.TypeBool,
Optional: true,
Description: "If true, the rule will fail if the pattern matches.",
},
"operator": {
Type: schema.TypeString,
Required: true,
Description: "The operator to use for matching. Can be one of: `starts_with`, `ends_with`, `contains`, `regex`.",
},
"pattern": {
Type: schema.TypeString,
Required: true,
Description: "The pattern to match with.",
},
},
},
},
"required_workflows": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Choose which Actions workflows must pass before branches can be merged into a branch that matches this rule.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"do_not_enforce_on_create": {
Type: schema.TypeBool,
Optional: true,
Description: "Allow repositories and branches to be created if a check would otherwise prohibit it.",
},
"required_workflow": {
Type: schema.TypeSet,
MinItems: 1,
Required: true,
Description: "Actions workflows that are required. Several can be defined.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"repository_id": {
Type: schema.TypeInt,
Required: true,
Description: "The repository in which the workflow is defined.",
},
"path": {
Type: schema.TypeString,
Required: true,
Description: "The path to the workflow YAML definition file.",
},
"ref": {
Type: schema.TypeString,
Optional: true,
Default: "master",
Description: "The ref (branch or tag) of the workflow file to use.",
},
},
},
},
},
},
},
"required_code_scanning": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Choose which tools must provide code scanning results before the reference is updated. When configured, code scanning must be enabled and have results for both the commit and the reference being updated.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"required_code_scanning_tool": {
Type: schema.TypeSet,
MinItems: 1,
Required: true,
Description: "Tools that must provide code scanning results for this rule to pass.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"alerts_threshold": {
Type: schema.TypeString,
Required: true,
Description: "The severity level at which code scanning results that raise alerts block a reference update. Can be one of: `none`, `errors`, `errors_and_warnings`, `all`.",
},
"security_alerts_threshold": {
Type: schema.TypeString,
Required: true,
Description: "The severity level at which code scanning results that raise security alerts block a reference update. Can be one of: `none`, `critical`, `high_or_higher`, `medium_or_higher`, `all`.",
},
"tool": {
Type: schema.TypeString,
Required: true,
Description: "The name of a code scanning tool.",
},
},
},
},
},
},
},
"file_path_restriction": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Prevent commits that include changes in specified file paths from being pushed to the commit graph.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"restricted_file_paths": {
Type: schema.TypeList,
MinItems: 1,
Required: true,
Description: "The file paths that are restricted from being pushed to the commit graph.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"max_file_size": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Prevent pushes based on file size.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max_file_size": {
Type: schema.TypeInt,
Required: true,
Description: "The maximum allowed size of a file in megabytes (MB). Valid range is 1-100 MB.",
ValidateDiagFunc: toDiagFunc(validation.IntBetween(1, 100), "max_file_size"),
},
},
},
},
"max_file_path_length": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Prevent pushes based on file path length.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"max_file_path_length": {
Type: schema.TypeInt,
Required: true,
Description: "The maximum allowed length of a file path.",
},
},
},
},
"file_extension_restriction": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Prevent pushes based on file extensions.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"restricted_file_extensions": {
Type: schema.TypeSet,
MinItems: 1,
Required: true,
Description: "The file extensions that are restricted from being pushed to the commit graph.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
"etag": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func resourceGithubOrganizationRulesetCreate(d *schema.ResourceData, meta any) error {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
rulesetReq := resourceGithubRulesetObject(d, owner)
ctx := context.Background()
var ruleset *github.Ruleset
var err error
ruleset, _, err = client.Organizations.CreateOrganizationRuleset(ctx, owner, rulesetReq)
if err != nil {
return err
}
d.SetId(strconv.FormatInt(*ruleset.ID, 10))
return resourceGithubOrganizationRulesetRead(d, meta)
}
func resourceGithubOrganizationRulesetRead(d *schema.ResourceData, meta any) error {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
rulesetID, err := strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
return unconvertibleIdErr(d.Id(), err)
}
ctx := context.WithValue(context.Background(), ctxId, d.Id())
if !d.IsNewResource() {
ctx = context.WithValue(ctx, ctxEtag, d.Get("etag").(string))
}
var ruleset *github.Ruleset
var resp *github.Response
ruleset, resp, err = client.Organizations.GetOrganizationRuleset(ctx, owner, rulesetID)
if err != nil {
var ghErr *github.ErrorResponse
if errors.As(err, &ghErr) {
if ghErr.Response.StatusCode == http.StatusNotModified {
return nil
}
if ghErr.Response.StatusCode == http.StatusNotFound {
log.Printf("[INFO] Removing ruleset %s: %d from state because it no longer exists in GitHub",
owner, rulesetID)
d.SetId("")
return nil
}
}
return err
}
_ = d.Set("etag", resp.Header.Get("ETag"))
_ = d.Set("name", ruleset.Name)
_ = d.Set("target", ruleset.GetTarget())
_ = d.Set("enforcement", ruleset.Enforcement)
_ = d.Set("bypass_actors", flattenBypassActors(ruleset.BypassActors))
_ = d.Set("conditions", flattenConditions(ruleset.GetConditions(), true))
_ = d.Set("rules", flattenRules(ruleset.Rules, true))
_ = d.Set("node_id", ruleset.GetNodeID())
_ = d.Set("ruleset_id", ruleset.ID)
return nil
}
func resourceGithubOrganizationRulesetUpdate(d *schema.ResourceData, meta any) error {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
rulesetReq := resourceGithubRulesetObject(d, owner)
rulesetID, err := strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
return unconvertibleIdErr(d.Id(), err)
}
ctx := context.WithValue(context.Background(), ctxId, d.Id())
ruleset, _, err := client.Organizations.UpdateOrganizationRuleset(ctx, owner, rulesetID, rulesetReq)
if err != nil {
return err
}
d.SetId(strconv.FormatInt(*ruleset.ID, 10))
return resourceGithubOrganizationRulesetRead(d, meta)
}
func resourceGithubOrganizationRulesetDelete(d *schema.ResourceData, meta any) error {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
rulesetID, err := strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
return unconvertibleIdErr(d.Id(), err)
}
ctx := context.WithValue(context.Background(), ctxId, d.Id())
log.Printf("[DEBUG] Deleting organization ruleset: %s: %d", owner, rulesetID)
_, err = client.Organizations.DeleteOrganizationRuleset(ctx, owner, rulesetID)
return err
}
func resourceGithubOrganizationRulesetImport(d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) {
rulesetID, err := strconv.ParseInt(d.Id(), 10, 64)
if err != nil {
return []*schema.ResourceData{d}, unconvertibleIdErr(d.Id(), err)
}
if rulesetID == 0 {
return []*schema.ResourceData{d}, fmt.Errorf("`ruleset_id` must be present")
}
log.Printf("[DEBUG] Importing organization ruleset with ID: %d", rulesetID)
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
ctx := context.Background()
ruleset, _, err := client.Organizations.GetOrganizationRuleset(ctx, owner, rulesetID)
if ruleset == nil || err != nil {
return []*schema.ResourceData{d}, err
}
d.SetId(strconv.FormatInt(ruleset.GetID(), 10))
return []*schema.ResourceData{d}, nil
}