|
| 1 | +package sysdig |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "time" |
| 6 | + |
| 7 | + v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 10 | +) |
| 11 | + |
| 12 | +func dataSourceSysdigSecureOktaMLPolicy() *schema.Resource { |
| 13 | + timeout := 5 * time.Minute |
| 14 | + |
| 15 | + return &schema.Resource{ |
| 16 | + ReadContext: dataSourceSysdigSecureOktaMLPolicyRead, |
| 17 | + |
| 18 | + Timeouts: &schema.ResourceTimeout{ |
| 19 | + Read: schema.DefaultTimeout(timeout), |
| 20 | + }, |
| 21 | + |
| 22 | + Schema: createOktaMLPolicyDataSourceSchema(), |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func dataSourceSysdigSecureOktaMLPolicyRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { |
| 27 | + return oktaMLPolicyDataSourceRead(ctx, d, meta, "custom Okta ML policy", isCustomCompositePolicy) |
| 28 | +} |
| 29 | + |
| 30 | +func createOktaMLPolicyDataSourceSchema() map[string]*schema.Schema { |
| 31 | + return map[string]*schema.Schema{ |
| 32 | + // IMPORTANT: Type is implicit: It's automatically added upon conversion to JSON |
| 33 | + "type": { |
| 34 | + Type: schema.TypeString, |
| 35 | + Computed: true, |
| 36 | + }, |
| 37 | + "name": NameSchema(), |
| 38 | + "description": DescriptionComputedSchema(), |
| 39 | + "enabled": EnabledComputedSchema(), |
| 40 | + "severity": SeverityComputedSchema(), |
| 41 | + "scope": ScopeComputedSchema(), |
| 42 | + "version": VersionSchema(), |
| 43 | + "notification_channels": NotificationChannelsComputedSchema(), |
| 44 | + "runbook": RunbookComputedSchema(), |
| 45 | + "rule": { |
| 46 | + Type: schema.TypeList, |
| 47 | + Computed: true, |
| 48 | + Elem: &schema.Resource{ |
| 49 | + Schema: map[string]*schema.Schema{ |
| 50 | + "id": ReadOnlyIntSchema(), |
| 51 | + "name": ReadOnlyStringSchema(), |
| 52 | + "description": DescriptionComputedSchema(), |
| 53 | + "tags": TagsSchema(), |
| 54 | + "version": VersionSchema(), |
| 55 | + "anomalous_console_login": MLRuleThresholdAndSeverityComputedSchema(), |
| 56 | + }, |
| 57 | + }, |
| 58 | + }, |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +func oktaMLPolicyDataSourceRead(ctx context.Context, d *schema.ResourceData, meta any, resourceName string, validationFunc func(v2.PolicyRulesComposite) bool) diag.Diagnostics { |
| 63 | + policy, err := compositePolicyDataSourceRead(ctx, d, meta, resourceName, policyTypeOktaML, validationFunc) |
| 64 | + if err != nil { |
| 65 | + return diag.FromErr(err) |
| 66 | + } |
| 67 | + |
| 68 | + err = oktaMLPolicyToResourceData(policy, d) |
| 69 | + if err != nil { |
| 70 | + return diag.FromErr(err) |
| 71 | + } |
| 72 | + |
| 73 | + return nil |
| 74 | +} |
0 commit comments