diff --git a/opslevel/resource_opslevel_check_alert_source_usage.go b/opslevel/resource_opslevel_check_alert_source_usage.go index 2f1c646d..8d5d7ffb 100644 --- a/opslevel/resource_opslevel_check_alert_source_usage.go +++ b/opslevel/resource_opslevel_check_alert_source_usage.go @@ -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"` diff --git a/opslevel/resource_opslevel_check_base.go b/opslevel/resource_opslevel_check_base.go index 870af75e..de66483e 100644 --- a/opslevel/resource_opslevel_check_base.go +++ b/opslevel/resource_opslevel_check_base.go @@ -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.", diff --git a/opslevel/resource_opslevel_check_git_branch_protection.go b/opslevel/resource_opslevel_check_git_branch_protection.go index 1a798912..a4da628a 100644 --- a/opslevel/resource_opslevel_check_git_branch_protection.go +++ b/opslevel/resource_opslevel_check_git_branch_protection.go @@ -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) @@ -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)...) @@ -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)...) @@ -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)...) @@ -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)...) diff --git a/opslevel/resource_opslevel_check_has_documentation.go b/opslevel/resource_opslevel_check_has_documentation.go index b60df806..c936ed4a 100644 --- a/opslevel/resource_opslevel_check_has_documentation.go +++ b/opslevel/resource_opslevel_check_has_documentation.go @@ -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"` diff --git a/opslevel/resource_opslevel_check_has_recent_deploy.go b/opslevel/resource_opslevel_check_has_recent_deploy.go index 8fa092cc..9681fe05 100644 --- a/opslevel/resource_opslevel_check_has_recent_deploy.go +++ b/opslevel/resource_opslevel_check_has_recent_deploy.go @@ -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"` } diff --git a/opslevel/resource_opslevel_check_manual.go b/opslevel/resource_opslevel_check_manual.go index a515f0d0..1f2c03f3 100644 --- a/opslevel/resource_opslevel_check_manual.go +++ b/opslevel/resource_opslevel_check_manual.go @@ -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"`