Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR feedback
Browse files Browse the repository at this point in the history
davidbloss committed Oct 24, 2024
1 parent 244ad40 commit 5eed1ac
Showing 3 changed files with 21 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .changes/unreleased/Feature-20241022-161548.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kind: Feature
body: add opslevel_check_code_issue
body: Add new resource to manage Code Issue Checks - 'opslevel_check_code_issue'
time: 2024-10-22T16:15:48.980301-05:00
8 changes: 4 additions & 4 deletions opslevel/resource_opslevel_check_base.go
Original file line number Diff line number Diff line change
@@ -30,21 +30,21 @@ type CheckCodeBaseResourceModel struct {
Owner types.String `tfsdk:"owner"`
}

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

Check warning on line 34 in opslevel/resource_opslevel_check_base.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_base.go#L33-L34

Added lines #L33 - L34 were not covered by tests

stateModel.Category = RequiredStringValue(string(check.Category.Id))
stateModel.Description = ComputedStringValue(check.Description)
if planModel.Enabled.IsNull() {
if givenModel.Enabled.IsNull() {
stateModel.Enabled = types.BoolValue(false)
} else {
stateModel.Enabled = OptionalBoolValue(&check.Enabled)

Check warning on line 41 in opslevel/resource_opslevel_check_base.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_base.go#L36-L41

Added lines #L36 - L41 were not covered by tests
}
if planModel.EnableOn.IsNull() {
if givenModel.EnableOn.IsNull() {
stateModel.EnableOn = types.StringNull()
} else {

Check warning on line 45 in opslevel/resource_opslevel_check_base.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_base.go#L43-L45

Added lines #L43 - L45 were not covered by tests
// We pass through the plan value because of time formatting issue to ensure the state gets the exact value the customer specified
stateModel.EnableOn = planModel.EnableOn
stateModel.EnableOn = givenModel.EnableOn

Check warning on line 47 in opslevel/resource_opslevel_check_base.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_base.go#L47

Added line #L47 was not covered by tests
}
stateModel.Filter = OptionalStringValue(string(check.Filter.Id))
stateModel.Id = ComputedStringValue(string(check.Id))
48 changes: 16 additions & 32 deletions opslevel/resource_opslevel_check_code_issue.go
Original file line number Diff line number Diff line change
@@ -48,21 +48,21 @@ type CheckCodeIssueResourceModel struct {
Severity types.List `tfsdk:"severity"`
}

func NewCheckCodeIssueResourceModel(ctx context.Context, check opslevel.Check, planModel CheckCodeIssueResourceModel) CheckCodeIssueResourceModel {
func NewCheckCodeIssueResourceModel(ctx context.Context, check opslevel.Check, givenModel CheckCodeIssueResourceModel) CheckCodeIssueResourceModel {
var stateModel CheckCodeIssueResourceModel

Check warning on line 52 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L51-L52

Added lines #L51 - L52 were not covered by tests

stateModel.Category = RequiredStringValue(string(check.Category.Id))
stateModel.Description = ComputedStringValue(check.Description)
if planModel.Enabled.IsNull() {
if givenModel.Enabled.IsNull() {
stateModel.Enabled = types.BoolValue(false)
} else {
stateModel.Enabled = OptionalBoolValue(&check.Enabled)

Check warning on line 59 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L54-L59

Added lines #L54 - L59 were not covered by tests
}
if planModel.EnableOn.IsNull() {
if givenModel.EnableOn.IsNull() {
stateModel.EnableOn = types.StringNull()
} else {

Check warning on line 63 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L61-L63

Added lines #L61 - L63 were not covered by tests
// We pass through the plan value because of time formatting issue to ensure the state gets the exact value the customer specified
stateModel.EnableOn = planModel.EnableOn
stateModel.EnableOn = givenModel.EnableOn

Check warning on line 65 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L65

Added line #L65 was not covered by tests
}
stateModel.Filter = OptionalStringValue(string(check.Filter.Id))
stateModel.Id = ComputedStringValue(string(check.Id))
@@ -149,11 +149,7 @@ func (r *CheckCodeIssueResource) Schema(ctx context.Context, req resource.Schema
}

func (r *CheckCodeIssueResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var planModel CheckCodeIssueResourceModel

// Read Terraform plan data into the planModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)

planModel := read[CheckCodeIssueResourceModel](ctx, &resp.Diagnostics, req.Plan)
if resp.Diagnostics.HasError() {
return

Check warning on line 154 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L151-L154

Added lines #L151 - L154 were not covered by tests
}
@@ -203,41 +199,33 @@ func (r *CheckCodeIssueResource) Create(ctx context.Context, req resource.Create

stateModel := NewCheckCodeIssueResourceModel(ctx, *data, planModel)

Check warning on line 200 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L200

Added line #L200 was not covered by tests

tflog.Trace(ctx, "created a check alert source usage resource")
tflog.Trace(ctx, "created a check_code_issue resource")
resp.Diagnostics.Append(resp.State.Set(ctx, &stateModel)...)

Check warning on line 203 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L202-L203

Added lines #L202 - L203 were not covered by tests
}

func (r *CheckCodeIssueResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var planModel CheckCodeIssueResourceModel

// Read Terraform prior state data into the planModel
resp.Diagnostics.Append(req.State.Get(ctx, &planModel)...)

stateModel := read[CheckCodeIssueResourceModel](ctx, &resp.Diagnostics, req.State)
if resp.Diagnostics.HasError() {
return

Check warning on line 209 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L206-L209

Added lines #L206 - L209 were not covered by tests
}

data, err := r.client.GetCheck(asID(planModel.Id))
data, err := r.client.GetCheck(asID(stateModel.Id))
if err != nil {
if (data == nil || data.Id == "") && opslevel.IsOpsLevelApiError(err) {
resp.State.RemoveResource(ctx)
return

Check warning on line 216 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L212-L216

Added lines #L212 - L216 were not covered by tests
}
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check alert source usage, got error: %s", err))
resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to read check_code_issue, got error: %s", err))
return

Check warning on line 219 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L218-L219

Added lines #L218 - L219 were not covered by tests
}
stateModel := NewCheckCodeIssueResourceModel(ctx, *data, planModel)
stateModel = NewCheckCodeIssueResourceModel(ctx, *data, stateModel)

Check warning on line 221 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L221

Added line #L221 was not covered by tests

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &stateModel)...)

Check warning on line 224 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L224

Added line #L224 was not covered by tests
}

func (r *CheckCodeIssueResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var planModel CheckCodeIssueResourceModel

// Read Terraform plan data into the planModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)

planModel := read[CheckCodeIssueResourceModel](ctx, &resp.Diagnostics, req.Plan)
if resp.Diagnostics.HasError() {
return

Check warning on line 230 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L227-L230

Added lines #L227 - L230 were not covered by tests
}
@@ -296,26 +284,22 @@ func (r *CheckCodeIssueResource) Update(ctx context.Context, req resource.Update

stateModel := NewCheckCodeIssueResourceModel(ctx, *data, planModel)

Check warning on line 285 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L285

Added line #L285 was not covered by tests

tflog.Trace(ctx, "updated a check alert source usage resource")
tflog.Trace(ctx, "updated a check_code_issue resource")
resp.Diagnostics.Append(resp.State.Set(ctx, &stateModel)...)

Check warning on line 288 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L287-L288

Added lines #L287 - L288 were not covered by tests
}

func (r *CheckCodeIssueResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var planModel CheckCodeIssueResourceModel

// Read Terraform prior state data into the planModel
resp.Diagnostics.Append(req.State.Get(ctx, &planModel)...)

stateModel := read[CheckCodeIssueResourceModel](ctx, &resp.Diagnostics, req.State)
if resp.Diagnostics.HasError() {
return

Check warning on line 294 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L291-L294

Added lines #L291 - L294 were not covered by tests
}

err := r.client.DeleteCheck(asID(planModel.Id))
err := r.client.DeleteCheck(asID(stateModel.Id))
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete check alert source usage, got error: %s", err))
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete check_code_issue, got error: %s", err))
return

Check warning on line 300 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L297-L300

Added lines #L297 - L300 were not covered by tests
}
tflog.Trace(ctx, "deleted a check alert source usage resource")
tflog.Trace(ctx, "deleted a check_code_issue resource")

Check warning on line 302 in opslevel/resource_opslevel_check_code_issue.go

Codecov / codecov/patch

opslevel/resource_opslevel_check_code_issue.go#L302

Added line #L302 was not covered by tests
}

func (r *CheckCodeIssueResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {

0 comments on commit 5eed1ac

Please sign in to comment.