Skip to content

Commit

Permalink
check base refactor, part 1 (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss authored Oct 22, 2024
1 parent 025912b commit f1c5e24
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 59 deletions.
11 changes: 1 addition & 10 deletions opslevel/resource_opslevel_check_alert_source_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,7 @@ type CheckAlertSourceUsageResource struct {
}

type CheckAlertSourceUsageResourceModel struct {
Category types.String `tfsdk:"category"`
Description types.String `tfsdk:"description"`
Enabled types.Bool `tfsdk:"enabled"`
EnableOn types.String `tfsdk:"enable_on"`
Filter types.String `tfsdk:"filter"`
Id types.String `tfsdk:"id"`
Level types.String `tfsdk:"level"`
Name types.String `tfsdk:"name"`
Notes types.String `tfsdk:"notes"`
Owner types.String `tfsdk:"owner"`
CheckCodeBaseResourceModel

AlertType types.String `tfsdk:"alert_type"`
AlertNamePredicate types.Object `tfsdk:"alert_name_predicate"`
Expand Down
13 changes: 13 additions & 0 deletions opslevel/resource_opslevel_check_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ import (
"github.com/opslevel/opslevel-go/v2024"
)

type CheckCodeBaseResourceModel struct {
Category types.String `tfsdk:"category"`
Description types.String `tfsdk:"description"`
Enabled types.Bool `tfsdk:"enabled"`
EnableOn types.String `tfsdk:"enable_on"`
Filter types.String `tfsdk:"filter"`
Id types.String `tfsdk:"id"`
Level types.String `tfsdk:"level"`
Name types.String `tfsdk:"name"`
Notes types.String `tfsdk:"notes"`
Owner types.String `tfsdk:"owner"`
}

var checkBaseAttributes = map[string]schema.Attribute{
"category": schema.StringAttribute{
Description: "The id of the category the check belongs to.",
Expand Down
25 changes: 6 additions & 19 deletions opslevel/resource_opslevel_check_git_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,8 @@ type CheckGitBranchProtectionResource struct {
CommonResourceClient
}

type CheckGitBranchProtectionResourceModel struct {
Category types.String `tfsdk:"category"`
Description types.String `tfsdk:"description"`
Enabled types.Bool `tfsdk:"enabled"`
EnableOn types.String `tfsdk:"enable_on"`
Filter types.String `tfsdk:"filter"`
Id types.String `tfsdk:"id"`
Level types.String `tfsdk:"level"`
Name types.String `tfsdk:"name"`
Notes types.String `tfsdk:"notes"`
Owner types.String `tfsdk:"owner"`
}

func NewCheckGitBranchProtectionResourceModel(ctx context.Context, check opslevel.Check, planModel CheckGitBranchProtectionResourceModel) CheckGitBranchProtectionResourceModel {
var stateModel CheckGitBranchProtectionResourceModel
func NewCheckGitBranchProtectionResourceModel(ctx context.Context, check opslevel.Check, planModel CheckCodeBaseResourceModel) CheckCodeBaseResourceModel {
var stateModel CheckCodeBaseResourceModel

stateModel.Category = RequiredStringValue(string(check.Category.Id))
stateModel.Description = ComputedStringValue(check.Description)
Expand Down Expand Up @@ -82,7 +69,7 @@ func (r *CheckGitBranchProtectionResource) Schema(ctx context.Context, req resou
}

func (r *CheckGitBranchProtectionResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var planModel CheckGitBranchProtectionResourceModel
var planModel CheckCodeBaseResourceModel

// Read Terraform plan data into the planModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)
Expand Down Expand Up @@ -121,7 +108,7 @@ func (r *CheckGitBranchProtectionResource) Create(ctx context.Context, req resou
}

func (r *CheckGitBranchProtectionResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var planModel CheckGitBranchProtectionResourceModel
var planModel CheckCodeBaseResourceModel

// Read Terraform prior state data into the planModel
resp.Diagnostics.Append(req.State.Get(ctx, &planModel)...)
Expand All @@ -146,7 +133,7 @@ func (r *CheckGitBranchProtectionResource) Read(ctx context.Context, req resourc
}

func (r *CheckGitBranchProtectionResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var planModel CheckGitBranchProtectionResourceModel
var planModel CheckCodeBaseResourceModel

// Read Terraform plan data into the planModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &planModel)...)
Expand Down Expand Up @@ -186,7 +173,7 @@ func (r *CheckGitBranchProtectionResource) Update(ctx context.Context, req resou
}

func (r *CheckGitBranchProtectionResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
var planModel CheckGitBranchProtectionResourceModel
var planModel CheckCodeBaseResourceModel

// Read Terraform prior state data into the planModel
resp.Diagnostics.Append(req.State.Get(ctx, &planModel)...)
Expand Down
11 changes: 1 addition & 10 deletions opslevel/resource_opslevel_check_has_documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,7 @@ type CheckHasDocumentationResource struct {
}

type CheckHasDocumentationResourceModel struct {
Category types.String `tfsdk:"category"`
Description types.String `tfsdk:"description"`
Enabled types.Bool `tfsdk:"enabled"`
EnableOn types.String `tfsdk:"enable_on"`
Filter types.String `tfsdk:"filter"`
Id types.String `tfsdk:"id"`
Level types.String `tfsdk:"level"`
Name types.String `tfsdk:"name"`
Notes types.String `tfsdk:"notes"`
Owner types.String `tfsdk:"owner"`
CheckCodeBaseResourceModel

DocumentType types.String `tfsdk:"document_type"`
DocumentSubtype types.String `tfsdk:"document_subtype"`
Expand Down
11 changes: 1 addition & 10 deletions opslevel/resource_opslevel_check_has_recent_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,7 @@ type CheckHasRecentDeployResource struct {
}

type CheckHasRecentDeployResourceModel struct {
Category types.String `tfsdk:"category"`
Description types.String `tfsdk:"description"`
Enabled types.Bool `tfsdk:"enabled"`
EnableOn types.String `tfsdk:"enable_on"`
Filter types.String `tfsdk:"filter"`
Id types.String `tfsdk:"id"`
Level types.String `tfsdk:"level"`
Name types.String `tfsdk:"name"`
Notes types.String `tfsdk:"notes"`
Owner types.String `tfsdk:"owner"`
CheckCodeBaseResourceModel

Days types.Int64 `tfsdk:"days"`
}
Expand Down
11 changes: 1 addition & 10 deletions opslevel/resource_opslevel_check_manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,7 @@ var updateFrequencyTypeV0 = map[string]attr.Type{
}

type CheckManualResourceModel struct {
Category types.String `tfsdk:"category"`
Description types.String `tfsdk:"description"`
Enabled types.Bool `tfsdk:"enabled"`
EnableOn types.String `tfsdk:"enable_on"`
Filter types.String `tfsdk:"filter"`
Id types.String `tfsdk:"id"`
Level types.String `tfsdk:"level"`
Name types.String `tfsdk:"name"`
Notes types.String `tfsdk:"notes"`
Owner types.String `tfsdk:"owner"`
CheckCodeBaseResourceModel

UpdateFrequency *CheckUpdateFrequency `tfsdk:"update_frequency"`
UpdateRequiresComment types.Bool `tfsdk:"update_requires_comment"`
Expand Down

0 comments on commit f1c5e24

Please sign in to comment.