-
Notifications
You must be signed in to change notification settings - Fork 54
Add terraform support to Okta ML Policy #675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
harshampatel-sysdig
wants to merge
7
commits into
sysdiglabs:master
Choose a base branch
from
harshampatel-sysdig:feature-oktaml-terraform
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df22c77
Add terraform support to Okta ML Policy
harshampatel-sysdig 7d69eab
Merge branch 'master' into feature-oktaml-terraform
harshampatel-sysdig 9fd8297
Handle error and git ignore vscode
harshampatel-sysdig 9c2b3c8
Merge branch 'feature-oktaml-terraform' of https://github.com/harsham…
harshampatel-sysdig c509dba
Remove pointer and pass &policy
harshampatel-sysdig 62d7809
Updated documentations
harshampatel-sysdig 8443bcd
docs: update threshold descriptions to Default/High/Higher
harshampatel-sysdig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "type": "chrome", | ||
| "request": "launch", | ||
| "name": "Launch Chrome against localhost", | ||
| "url": "http://localhost:8080", | ||
| "webRoot": "${workspaceFolder}" | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package sysdig | ||
|
|
||
| import ( | ||
| "context" | ||
| "time" | ||
|
|
||
| v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| ) | ||
|
|
||
| func dataSourceSysdigSecureOktaMLPolicy() *schema.Resource { | ||
| timeout := 5 * time.Minute | ||
|
|
||
| return &schema.Resource{ | ||
| ReadContext: dataSourceSysdigSecureOktaMLPolicyRead, | ||
|
|
||
| Timeouts: &schema.ResourceTimeout{ | ||
| Read: schema.DefaultTimeout(timeout), | ||
| }, | ||
|
|
||
| Schema: createOktaMLPolicyDataSourceSchema(), | ||
| } | ||
| } | ||
|
|
||
| func dataSourceSysdigSecureOktaMLPolicyRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { | ||
| return oktaMLPolicyDataSourceRead(ctx, d, meta, "custom Okta ML policy", isCustomCompositePolicy) | ||
| } | ||
|
|
||
| func createOktaMLPolicyDataSourceSchema() map[string]*schema.Schema { | ||
| return map[string]*schema.Schema{ | ||
| // IMPORTANT: Type is implicit: It's automatically added upon conversion to JSON | ||
| "type": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "name": NameSchema(), | ||
| "description": DescriptionComputedSchema(), | ||
| "enabled": EnabledComputedSchema(), | ||
| "severity": SeverityComputedSchema(), | ||
| "scope": ScopeComputedSchema(), | ||
| "version": VersionSchema(), | ||
| "notification_channels": NotificationChannelsComputedSchema(), | ||
| "runbook": RunbookComputedSchema(), | ||
| "rule": { | ||
| Type: schema.TypeList, | ||
| Computed: true, | ||
| Elem: &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "id": ReadOnlyIntSchema(), | ||
| "name": ReadOnlyStringSchema(), | ||
| "description": DescriptionComputedSchema(), | ||
| "tags": TagsSchema(), | ||
| "version": VersionSchema(), | ||
| "anomalous_console_login": MLRuleThresholdAndSeverityComputedSchema(), | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func oktaMLPolicyDataSourceRead(ctx context.Context, d *schema.ResourceData, meta any, resourceName string, validationFunc func(v2.PolicyRulesComposite) bool) diag.Diagnostics { | ||
| policy, err := compositePolicyDataSourceRead(ctx, d, meta, resourceName, policyTypeOktaML, validationFunc) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| err = oktaMLPolicyToResourceData(policy, d) | ||
| if err != nil { | ||
| return diag.FromErr(err) | ||
| } | ||
|
|
||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| //go:build tf_acc_sysdig_secure || tf_acc_policies || tf_acc_policies_okta | ||
|
|
||
| package sysdig_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
|
||
| "github.com/draios/terraform-provider-sysdig/sysdig" | ||
| ) | ||
|
|
||
| func TestAccOktaMLPolicyDataSource(t *testing.T) { | ||
| rText := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
|
||
| resource.ParallelTest(t, resource.TestCase{ | ||
| PreCheck: func() { | ||
| if v := os.Getenv("SYSDIG_SECURE_API_TOKEN"); v == "" { | ||
| t.Fatal("SYSDIG_SECURE_API_TOKEN must be set for acceptance tests") | ||
| } | ||
| }, | ||
| ProviderFactories: map[string]func() (*schema.Provider, error){ | ||
| "sysdig": func() (*schema.Provider, error) { | ||
| return sysdig.Provider(), nil | ||
| }, | ||
| }, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: oktaOktaMLPolicyDataSource(rText), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func oktaOktaMLPolicyDataSource(name string) string { | ||
| return fmt.Sprintf(` | ||
| resource "sysdig_secure_okta_ml_policy" "policy_1" { | ||
| name = "Test Okta ML Policy %s" | ||
| description = "Test Okta ML Policy Description %s" | ||
| enabled = true | ||
| severity = 4 | ||
|
|
||
| rule { | ||
| description = "Test Okta ML Rule Description" | ||
|
|
||
| anomalous_console_login { | ||
| enabled = true | ||
| threshold = 2 | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| data "sysdig_secure_okta_ml_policy" "policy_2" { | ||
| name = sysdig_secure_okta_ml_policy.policy_1.name | ||
| depends_on = [sysdig_secure_okta_ml_policy.policy_1] | ||
| } | ||
| `, name, name) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to push this. If you can, please add it to gitignore so this isn't tracked in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need to delete it from your local machine and push once to remove it from here