Skip to content

Commit

Permalink
Fix: SLO validation bug(#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrNovo authored Jan 3, 2025
1 parent 754f541 commit 8d3efe3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 7 additions & 7 deletions coralogix/resource_coralogix_slo.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2024 Coralogix Ltd.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -115,28 +115,28 @@ func (S SLOResourceValidator) ValidateResource(ctx context.Context, req resource
resp.Diagnostics = diags
return
}
if config.Type.ValueString() == "latency" && (config.ThresholdMicroseconds.IsNull() || config.ThresholdMicroseconds.IsUnknown()) {
if config.Type.ValueString() == "latency" && config.ThresholdMicroseconds.IsNull() {
resp.Diagnostics.AddError(
"ThresholdMicroseconds is required when type is latency",
"ThresholdMicroseconds is required when type is latency",
)
return
}
if config.Type.ValueString() == "latency" && (config.ThresholdSymbolType.IsNull() || config.ThresholdSymbolType.IsUnknown()) {
if config.Type.ValueString() == "latency" && config.ThresholdSymbolType.IsNull() {
resp.Diagnostics.AddError(
"ThresholdSymbolType is required when type is latency",
"ThresholdSymbolType is required when type is latency",
)
return
}
if config.Type.ValueString() == "error" && !(config.ThresholdMicroseconds.IsNull() || config.ThresholdMicroseconds.IsUnknown()) {
if config.Type.ValueString() == "error" && !config.ThresholdMicroseconds.IsNull() {
resp.Diagnostics.AddError(
"ThresholdMicroseconds is not allowed when type is error",
"ThresholdMicroseconds is not allowed when type is error",
)
return
}
if config.Type.ValueString() == "error" && !(config.ThresholdSymbolType.IsNull() || config.ThresholdSymbolType.IsUnknown()) {
if config.Type.ValueString() == "error" && !config.ThresholdSymbolType.IsNull() {
resp.Diagnostics.AddError(
"ThresholdSymbolType is not allowed when type is error",
"ThresholdSymbolType is not allowed when type is error",
Expand Down
15 changes: 10 additions & 5 deletions coralogix/resource_coralogix_slo_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2024 Coralogix Ltd.
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -77,13 +77,18 @@ func testAccSLOCheckDestroy(s *terraform.State) error {
}

func testAccCoralogixResourceSLO() string {
return `resource "coralogix_slo" "test" {
return `variable "test" {
type = number
default = 1000000
}
resource "coralogix_slo" "test" {
name = "coralogix_slo_example"
service_name = "service_name"
description = "description"
target_percentage = 30
type = "latency"
threshold_microseconds = 1000000
threshold_microseconds = var.test
threshold_symbol_type = "greater"
period = "7_days"
filters = [
Expand Down

0 comments on commit 8d3efe3

Please sign in to comment.