Skip to content
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

add opslevel_check_code_issue #523

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Feature-20241022-161548.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Feature
body: Add new resource to manage Code Issue Checks - 'opslevel_check_code_issue'
time: 2024-10-22T16:15:48.980301-05:00
1 change: 1 addition & 0 deletions examples/resources/opslevel_check_code_issue/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import opslevel_check_code_issue.example Z2lkOi8vb3BzbGV2ZWwvU2VydmljZS82MDI0
59 changes: 59 additions & 0 deletions examples/resources/opslevel_check_code_issue/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
data "opslevel_rubric_category" "security" {
filter {
field = "name"
value = "Security"
}
}

data "opslevel_rubric_level" "bronze" {
filter {
field = "name"
value = "Bronze"
}
}

data "opslevel_team" "devs" {
alias = "developers"
}

data "opslevel_filter" "tier1" {
filter {
field = "name"
value = "Tier 1"
}
}

resource "opslevel_check_code_issue" "example" {
name = "foo"
pass_pending = true
enabled = true
# To set a future enable date remove field 'enabled' and use 'enable_on'
# enable_on = "2022-05-23T14:14:18.782000Z"
category = data.opslevel_rubric_category.security.id
level = data.opslevel_rubric_level.bronze.id
owner = data.opslevel_team.devs.id
filter = data.opslevel_filter.tier1.id
notes = "Optional additional info on why this check is run or how to fix it"

constraint = "any"
issue_name = "CVE-2024-0001"
issue_type = [
"snyk:code",
"snyk:cloud",
"snyk:config",
"snyk:custom",
"snyk:license",
"snyk:package_vulnerability",
]
max_allowed = 5
resolution_time = {
unit = "day"
value = 3
}
severity = [
"snyk:critical",
"snyk:low",
"snyk:medium",
"snyk:high",
]
}
1 change: 1 addition & 0 deletions opslevel/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (p *OpslevelProvider) Resources(context.Context) []func() resource.Resource
return []func() resource.Resource{
NewAliasResource,
NewCheckAlertSourceUsageResource,
NewCheckCodeIssueResource,
NewCheckCustomEventResource,
NewCheckGitBranchProtectionResource,
NewCheckHasDocumentationResource,
Expand Down
26 changes: 26 additions & 0 deletions opslevel/resource_opslevel_check_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ type CheckCodeBaseResourceModel struct {
Owner types.String `tfsdk:"owner"`
}

func NewCheckCodeBaseResourceModel(check opslevel.Check, givenModel CheckCodeBaseResourceModel) CheckCodeBaseResourceModel {
var stateModel CheckCodeBaseResourceModel

stateModel.Category = RequiredStringValue(string(check.Category.Id))
stateModel.Description = ComputedStringValue(check.Description)
if givenModel.Enabled.IsNull() {
stateModel.Enabled = types.BoolValue(false)
} else {
stateModel.Enabled = OptionalBoolValue(&check.Enabled)
}
if givenModel.EnableOn.IsNull() {
stateModel.EnableOn = types.StringNull()
} else {
// We pass through the plan value because of time formatting issue to ensure the state gets the exact value the customer specified
stateModel.EnableOn = givenModel.EnableOn
}
stateModel.Filter = OptionalStringValue(string(check.Filter.Id))
stateModel.Id = ComputedStringValue(string(check.Id))
stateModel.Level = RequiredStringValue(string(check.Level.Id))
stateModel.Name = RequiredStringValue(check.Name)
stateModel.Notes = OptionalStringValue(check.Notes)
stateModel.Owner = OptionalStringValue(string(check.Owner.Team.Id))

return stateModel
}

var checkBaseAttributes = map[string]schema.Attribute{
"category": schema.StringAttribute{
Description: "The id of the category the check belongs to.",
Expand Down
Loading
Loading