Skip to content

Commit

Permalink
fix special enum types
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss committed Oct 23, 2024
1 parent 1fcf733 commit 6777ac3
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 93 deletions.
17 changes: 12 additions & 5 deletions opslevel/resource_opslevel_integration_custom_event_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/opslevel/opslevel-go/v2024"
Expand All @@ -35,11 +37,11 @@ type IntegrationCustomEventCheckResourceModel struct {
Type types.String `tfsdk:"type"`
}

func NewIntegrationCustomEventCheckResourceModel(cecIntegration opslevel.Integration) IntegrationCustomEventCheckResourceModel {
func NewIntegrationCustomEventCheckResourceModel(cecIntegration opslevel.Integration, givenModel IntegrationCustomEventCheckResourceModel) IntegrationCustomEventCheckResourceModel {
return IntegrationCustomEventCheckResourceModel{
Id: ComputedStringValue(string(cecIntegration.Id)),
Name: RequiredStringValue(cecIntegration.Name),
Type: RequiredStringValue(cecIntegration.Type),
Type: RequiredStringValue(givenModel.Type.ValueString()),
}
}

Expand All @@ -48,6 +50,8 @@ func (r *IntegrationCustomEventCheckResource) Metadata(ctx context.Context, req
}

func (r *IntegrationCustomEventCheckResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
// validTypes := slices.Concat(opslevel.AllEventIntegrationEnum, []string{"filter", "framework", "language", "lifecycle", "owner", "product", "tag", "tier"})

resp.Schema = schema.Schema{
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Custom Event Check Integration resource",
Expand All @@ -70,6 +74,9 @@ func (r *IntegrationCustomEventCheckResource) Schema(ctx context.Context, req re
strings.Join(opslevel.AllEventIntegrationEnum, "`, `"),
),
Required: true,
Validators: []validator.String{
stringvalidator.OneOf(opslevel.AllEventIntegrationEnum...),
},
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Expand Down Expand Up @@ -98,7 +105,7 @@ func (r *IntegrationCustomEventCheckResource) Create(ctx context.Context, req re
return
}

stateModel := NewIntegrationCustomEventCheckResourceModel(*cecIntegration)
stateModel := NewIntegrationCustomEventCheckResourceModel(*cecIntegration, planModel)

tflog.Trace(ctx, "created a Custom Event Check integration resource")
resp.Diagnostics.Append(resp.State.Set(ctx, &stateModel)...)
Expand All @@ -119,7 +126,7 @@ func (r *IntegrationCustomEventCheckResource) Read(ctx context.Context, req reso
return
}

verifiedStateModel := NewIntegrationCustomEventCheckResourceModel(*cecIntegration)
verifiedStateModel := NewIntegrationCustomEventCheckResourceModel(*cecIntegration, stateModel)

// Save updated data into Terraform state
tflog.Trace(ctx, "read a Custom Event Check integration resource")
Expand All @@ -146,7 +153,7 @@ func (r *IntegrationCustomEventCheckResource) Update(ctx context.Context, req re
return
}

stateModel := NewIntegrationCustomEventCheckResourceModel(*cecIntegration)
stateModel := NewIntegrationCustomEventCheckResourceModel(*cecIntegration, planModel)

tflog.Trace(ctx, "updated a Custom Event Check integration resource")
resp.Diagnostics.Append(resp.State.Set(ctx, &stateModel)...)
Expand Down
171 changes: 83 additions & 88 deletions tests/integration_custom_event_check.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,25 @@ run "resource_integration_custom_event_check_create_aqua_security_type" {
}
}

# run "resource_integration_custom_event_check_create_argocd_type" {

# variables {
# NOTE: returns "argocdDeploy"
# type = "argocd"
# }

# module {
# source = "./opslevel_modules/modules/integration/custom_event_check"
# }

# assert {
# condition = opslevel_integration_custom_event_check.this.type == var.type
# error_message = format(
# "expected '%v' but got '%v'",
# var.type,
# opslevel_integration_custom_event_check.this.type,
# )
# }
# }
run "resource_integration_custom_event_check_create_argocd_type" {

variables {
type = "argocd"
}

module {
source = "./opslevel_modules/modules/integration/custom_event_check"
}

assert {
condition = opslevel_integration_custom_event_check.this.type == var.type
error_message = format(
"expected '%v' but got '%v'",
var.type,
opslevel_integration_custom_event_check.this.type,
)
}
}

run "resource_integration_custom_event_check_create_aws_ecr_type" {

Expand Down Expand Up @@ -130,26 +129,25 @@ run "resource_integration_custom_event_check_create_bugsnag_type" {
}
}

# run "resource_integration_custom_event_check_create_circleci_type" {
run "resource_integration_custom_event_check_create_circleci_type" {

# variables {
# NOTE: returns "circleciDeploy"
# type = "circleci"
# }
variables {
type = "circleci"
}

# module {
# source = "./opslevel_modules/modules/integration/custom_event_check"
# }
module {
source = "./opslevel_modules/modules/integration/custom_event_check"
}

# assert {
# condition = opslevel_integration_custom_event_check.this.type == var.type
# error_message = format(
# "expected '%v' but got '%v'",
# var.type,
# opslevel_integration_custom_event_check.this.type,
# )
# }
# }
assert {
condition = opslevel_integration_custom_event_check.this.type == var.type
error_message = format(
"expected '%v' but got '%v'",
var.type,
opslevel_integration_custom_event_check.this.type,
)
}
}

run "resource_integration_custom_event_check_create_codacy_type" {

Expand Down Expand Up @@ -191,26 +189,25 @@ run "resource_integration_custom_event_check_create_coveralls_type" {
}
}

# run "resource_integration_custom_event_check_create_custom_event_type" {
run "resource_integration_custom_event_check_create_custom_event_type" {

# variables {
# # NOTE: returns "generic"
# type = "customEvent"
# }
variables {
type = "customEvent"
}

# module {
# source = "./opslevel_modules/modules/integration/custom_event_check"
# }
module {
source = "./opslevel_modules/modules/integration/custom_event_check"
}

# assert {
# condition = opslevel_integration_custom_event_check.this.type == var.type
# error_message = format(
# "expected '%v' but got '%v'",
# var.type,
# opslevel_integration_custom_event_check.this.type,
# )
# }
# }
assert {
condition = opslevel_integration_custom_event_check.this.type == var.type
error_message = format(
"expected '%v' but got '%v'",
var.type,
opslevel_integration_custom_event_check.this.type,
)
}
}

run "resource_integration_custom_event_check_create_datadog_check_type" {

Expand Down Expand Up @@ -331,26 +328,25 @@ run "resource_integration_custom_event_check_create_github_actions_type" {
}
}

# run "resource_integration_custom_event_check_create_gitlab_ci_type" {
run "resource_integration_custom_event_check_create_gitlab_ci_type" {

# variables {
# NOTE: returns "gitLabCI"
# type = "gitlabCi"
# }
variables {
type = "gitlabCi"
}

# module {
# source = "./opslevel_modules/modules/integration/custom_event_check"
# }
module {
source = "./opslevel_modules/modules/integration/custom_event_check"
}

# assert {
# condition = opslevel_integration_custom_event_check.this.type == var.type
# error_message = format(
# "expected '%v' but got '%v'",
# var.type,
# opslevel_integration_custom_event_check.this.type,
# )
# }
# }
assert {
condition = opslevel_integration_custom_event_check.this.type == var.type
error_message = format(
"expected '%v' but got '%v'",
var.type,
opslevel_integration_custom_event_check.this.type,
)
}
}

run "resource_integration_custom_event_check_create_grafana_type" {

Expand Down Expand Up @@ -472,26 +468,25 @@ run "resource_integration_custom_event_check_create_new_relic_check_type" {
}
}

# run "resource_integration_custom_event_check_create_octopus_type" {
run "resource_integration_custom_event_check_create_octopus_type" {

# variables {
# NOTE: returns "octopusDeploy"
# type = "octopus"
# }
variables {
type = "octopus"
}

# module {
# source = "./opslevel_modules/modules/integration/custom_event_check"
# }
module {
source = "./opslevel_modules/modules/integration/custom_event_check"
}

# assert {
# condition = opslevel_integration_custom_event_check.this.type == var.type
# error_message = format(
# "expected '%v' but got '%v'",
# var.type,
# opslevel_integration_custom_event_check.this.type,
# )
# }
# }
assert {
condition = opslevel_integration_custom_event_check.this.type == var.type
error_message = format(
"expected '%v' but got '%v'",
var.type,
opslevel_integration_custom_event_check.this.type,
)
}
}

run "resource_integration_custom_event_check_create_prisma_cloud_type" {

Expand Down

0 comments on commit 6777ac3

Please sign in to comment.