-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
731 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Data Source: honeycombio_slo | ||
|
||
The `honeycombio_slo` data source retrieves the details of a single SLO. | ||
|
||
-> **Note** Terraform will fail unless an SLO is returned by the search. Ensure that your search is specific enough to return an SLO. | ||
If you want to match multiple SLOs, use the `honeycombio_slos` data source instead. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "dataset" { | ||
type = string | ||
} | ||
# Retrieve the details of a single SLO | ||
data "honeycombio_slo" "myslo" { | ||
dataset = var.dataset | ||
id = "fS4WfA82ACt" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `dataset` - (Required) The dataset this SLO is associated with | ||
* `id` - (Required) The ID of the SLO | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `name` - the name of the SLO. | ||
* `description` - the SLO's description. | ||
* `sli` - the alias of the Derived COlumn used as the SLO's SLI. | ||
* `target_percentage` - the percentage of qualified events expected to succeed during the `time_period`. | ||
* `time_period` - The time period, in days, over which the SLO is evaluated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Data Source: honeycombio_slos | ||
|
||
The SLOs data source allows the SLOs of a dataset to be retrieved. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "dataset" { | ||
type = string | ||
} | ||
# returns all SLOs | ||
data "honeycombio_slos" "all" { | ||
dataset = var.dataset | ||
} | ||
# only returns the SLOs starting with 'foo_' | ||
data "honeycombio_slos" "foo" { | ||
dataset = var.dataset | ||
detail_filter { | ||
name = "name" | ||
value_regex = "foo_*" | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `dataset` - (Required) The dataset to retrieve the SLOs list from | ||
* `detail_filter` - (Optional) a block to further filter recipients as described below. `name` must be set when providing a filter. | ||
|
||
To further filter the SLO results, a `detail_filter` block can be provided which accepts the following arguments: | ||
|
||
* `name` - (Required) The name of the detail field to filter by. Currently only `name` is supported. | ||
* `value` - (Optional) The value of the detail field to match on. | ||
* `value_regex` - (Optional) A regular expression string to apply to the value of the detail field to match on. | ||
|
||
~> **Note** one of `value` or `value_regex` is required. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `ids` - a list of all the SLO IDs found in the dataset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package filter | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
"github.com/honeycombio/terraform-provider-honeycombio/client" | ||
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper" | ||
) | ||
|
||
type SLODetailFilter struct { | ||
Type string | ||
Value *string | ||
ValueRegex *regexp.Regexp | ||
} | ||
|
||
func NewDetailSLOFilter(filterType, v, r string) (*SLODetailFilter, error) { | ||
if filterType != "name" { | ||
return nil, fmt.Errorf("only name is supported as a filter type") | ||
} | ||
if v != "" && r != "" { | ||
return nil, fmt.Errorf("only one of value or value_regex may be provided") | ||
} | ||
if v == "" && r == "" { | ||
return nil, fmt.Errorf("one of value or value_regex must be provided") | ||
} | ||
|
||
var value *string | ||
var valRegexp *regexp.Regexp | ||
if v != "" { | ||
value = helper.ToPtr(v) | ||
} | ||
if r != "" { | ||
valRegexp = regexp.MustCompile(r) | ||
} | ||
|
||
return &SLODetailFilter{ | ||
Type: filterType, | ||
Value: value, | ||
ValueRegex: valRegexp, | ||
}, nil | ||
} | ||
|
||
func (f *SLODetailFilter) Match(s client.SLO) bool { | ||
// nil filter fails open | ||
if f == nil { | ||
return true | ||
} | ||
if f.Value != nil { | ||
return s.Name == *f.Value | ||
} | ||
if f.ValueRegex != nil { | ||
return f.ValueRegex.MatchString(s.Name) | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package helper | ||
|
||
// Returns a pointer to the given value | ||
func ToPtr[T any](v T) *T { | ||
return &v | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package validation | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"regexp" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
var _ validator.String = isValidRegExpValidator{} | ||
|
||
type isValidRegExpValidator struct{} | ||
|
||
func (v isValidRegExpValidator) Description(_ context.Context) string { | ||
return "value must be a valid regular expression" | ||
} | ||
|
||
func (v isValidRegExpValidator) MarkdownDescription(ctx context.Context) string { | ||
return v.Description(ctx) | ||
} | ||
|
||
func (v isValidRegExpValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { | ||
if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
if _, err := regexp.Compile(request.ConfigValue.ValueString()); err != nil { | ||
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic( | ||
request.Path, | ||
v.Description(ctx), | ||
fmt.Sprintf("%q: %s", request.ConfigValue.ValueString(), err.Error()), | ||
)) | ||
} | ||
} | ||
|
||
// IsValidRegExp returns an AttributeValidator which ensures that any configured | ||
// attribute value is a valid regular expression. | ||
// | ||
// Null (unconfigured) and unknown (known after apply) values are skipped. | ||
func IsValidRegExp() validator.String { | ||
return isValidRegExpValidator{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package validation_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/validation" | ||
) | ||
|
||
func Test_IsValidRegexValidator(t *testing.T) { | ||
t.Parallel() | ||
|
||
type testCase struct { | ||
val types.String | ||
expectError bool | ||
} | ||
tests := map[string]testCase{ | ||
"unknown": { | ||
val: types.StringUnknown(), | ||
}, | ||
"null": { | ||
val: types.StringNull(), | ||
}, | ||
"valid regex": { | ||
val: types.StringValue("^[a-z]+$"), | ||
}, | ||
"invalid regex": { | ||
val: types.StringValue("^[a-z+$"), | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
name, test := name, test | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
request := validator.StringRequest{ | ||
Path: path.Root("test"), | ||
PathExpression: path.MatchRoot("test"), | ||
ConfigValue: test.val, | ||
} | ||
response := validator.StringResponse{} | ||
validation.IsValidRegExp().ValidateString(context.TODO(), request, &response) | ||
|
||
if !response.Diagnostics.HasError() && test.expectError { | ||
t.Fatal("expected error, got no error") | ||
} | ||
|
||
if response.Diagnostics.HasError() && !test.expectError { | ||
t.Fatalf("got unexpected error: %s", response.Diagnostics) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.