Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new aws_synthetics_runtime_verison and aws_synthetics_runtime_verisons data sources #39180

Merged
6 changes: 6 additions & 0 deletions .changelog/39180.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:new-data-source
aws_synthetics_runtime_version
```
```release-note:new-data-source
aws_synthetics_runtime_versions
```
51 changes: 51 additions & 0 deletions internal/framework/validators/bool_equals.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package validators

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

var _ validator.Bool = boolEqualsValidator{}

type boolEqualsValidator struct {
value types.Bool
}

func (v boolEqualsValidator) Description(ctx context.Context) string {
return fmt.Sprintf("Value must be %q", v.value)
}

func (v boolEqualsValidator) MarkdownDescription(ctx context.Context) string {
return v.Description(ctx)
}

func (v boolEqualsValidator) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse) {
if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() {
return
}

configValue := req.ConfigValue

if !configValue.Equal(v.value) {
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueMatchDiagnostic(
req.Path,
v.Description(ctx),
configValue.String(),
))
}
}

// BoolEquals checks that the Bool held in the attribute matches the
// given `value`
func BoolEquals(value bool) validator.Bool {
return boolEqualsValidator{
value: types.BoolValue(value),
}
}
69 changes: 69 additions & 0 deletions internal/framework/validators/bool_equals_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package validators_test

import (
"context"
"testing"

"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators"
)

func TestBoolEqualsValidator(t *testing.T) {
t.Parallel()

type testCase struct {
in types.Bool
validator validator.Bool
expErrors int
}

testCases := map[string]testCase{
"simple-match": {
in: types.BoolValue(true),
validator: fwvalidators.BoolEquals(true),
expErrors: 0,
},
"simple-mismatch": {
in: types.BoolValue(false),
validator: fwvalidators.BoolEquals(true),
expErrors: 1,
},
"skip-validation-on-null": {
in: types.BoolNull(),
validator: fwvalidators.BoolEquals(true),
expErrors: 0,
},
"skip-validation-on-unknown": {
in: types.BoolUnknown(),
validator: fwvalidators.BoolEquals(true),
expErrors: 0,
},
}

for name, test := range testCases {
t.Run(name, func(t *testing.T) {
t.Parallel()
req := validator.BoolRequest{
ConfigValue: test.in,
}
res := validator.BoolResponse{}
test.validator.ValidateBool(context.TODO(), req, &res)

if test.expErrors > 0 && !res.Diagnostics.HasError() {
t.Fatalf("expected %d error(s), got none", test.expErrors)
}

if test.expErrors > 0 && test.expErrors != res.Diagnostics.ErrorsCount() {
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, res.Diagnostics.ErrorsCount(), res.Diagnostics)
}

if test.expErrors == 0 && res.Diagnostics.HasError() {
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
}
})
}
}
Loading
Loading