feat: Add validate_path for pre-flight API validation during terraform plan - #364
Open
johnsolomonj wants to merge 1 commit into
Open
feat: Add validate_path for pre-flight API validation during terraform plan#364johnsolomonj wants to merge 1 commit into
johnsolomonj wants to merge 1 commit into
Conversation
…m plan Adds two new optional resource attributes: - validate_path: An endpoint to call during plan with the object's data. A non-2xx response fails the plan immediately with the API's error message. - validate_method: HTTP method for the validate call (default: POST). This surfaces configuration errors before apply, prevents partial applies caused by invalid resource configs, and gives faster CI feedback when the API has richer validation logic than Terraform schema alone can express. Unit tests added in internal/apiclient/object_validate_test.go. Acceptance tests added in internal/provider/resource_api_object_validate_test.go.
Author
|
Hi @DRuggeri — would love your review on this when you get a chance! Happy to make any changes needed. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two new optional
restapi_objectresource attributes:validate_path— an endpoint to call duringterraform planwith the object'sdata. A non-2xx response immediately fails the plan with the API's error message, surfacing configuration problems before apply.validate_method— HTTP method for the validate call (default:POST).Closes #362.
Motivation
Many REST APIs expose a dedicated validation endpoint (e.g.
POST /resource/validate) that performs a dry-run check without persisting anything. Without this feature, validation only surfaces atapplytime when the API rejects thePOST/PUT, which can cause partial applies where unrelated resources succeed but the invalid one fails.Usage
Behaviour
validate_pathis not set, the feature is a no-op — fully backward compatible.datais unknown at plan time (e.g. depends on another resource), the validate call is skipped to avoid false failures.API pre-flight validation faileddiagnostic that includes the validate path and the API's error body.Changes
internal/apiclient/object.goValidatePath/ValidateMethodtoAPIObjectOptsandAPIObject; addedValidateObject()method; addedGetValidatePath()/GetValidateMethod()accessorsinternal/provider/resource_api_object.govalidate_path/validate_methodschema attributes and model fields; implementedresource.ResourceWithConfigValidatorsviavalidatePathValidatorinternal/apiclient/object_validate_test.gointernal/provider/resource_api_object_validate_test.goTest results
All existing tests pass.
go vetandgofmtclean.