generated from cisco-ospo/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Create/Update/Delete terraform handlers (#10)
Signed-off-by: Viorel Dodin <vdodin@cisco.com>
- Loading branch information
1 parent
f3086e0
commit 7a498f1
Showing
6 changed files
with
191 additions
and
59 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
type IsValidJsonString struct { | ||
JsonString string | ||
} | ||
|
||
func (v IsValidJsonString) Description(_ context.Context) string { | ||
return fmt.Sprintf("value %s must be a valid json encoding string", v.JsonString) | ||
} | ||
|
||
func (v IsValidJsonString) MarkdownDescription(ctx context.Context) string { | ||
return v.Description(ctx) | ||
} | ||
|
||
func (v IsValidJsonString) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { | ||
if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
value := request.ConfigValue | ||
|
||
if json.Valid([]byte(value.ValueString())) { | ||
return | ||
} | ||
|
||
v.JsonString = value.ValueString() | ||
|
||
response.Diagnostics.Append(validatordiag.InvalidAttributeValueMatchDiagnostic( | ||
request.Path, | ||
v.Description(ctx), | ||
value.String(), | ||
)) | ||
} |
Oops, something went wrong.