Skip to content

Feature request: Support pre-flight validation via configurable validate endpoint during terraform plan #362

Description

@johnsolomonj

Summary

Many REST APIs expose a dedicated validation endpoint (e.g. POST /resource/validate) that performs a dry-run check of a resource configuration without persisting anything. Today there is no way to call this during terraform plan — validation only surfaces at apply time when the API rejects the request.

Proposed solution

Add optional validate_path and validate_method attributes to the restapi_object resource. When set, the provider would call this endpoint during plan (via the ConfigValidators hook in the Terraform Plugin Framework) and fail the plan if the API returns a non-2xx response.

Example configuration:

resource "restapi_object" "example" {
  path            = "/resources"
  data            = jsonencode({ ... })
  validate_path   = "/resources/validate"
  validate_method = "POST"
}

Implementation notes

The Terraform Plugin Framework already supports this via the resource.ResourceWithConfigValidators interface. The work would involve:

  1. Adding validate_path / validate_method schema attributes to resource_api_object.go
  2. Implementing ConfigValidators() returning a custom validator
  3. Adding a ValidateObject() method to APIObject in apiclient/object.go mirroring the existing CreateObject() pattern

Happy to contribute a PR if there is interest.

Why this matters

Catching misconfigured resources at plan time rather than apply time:

  • Prevents partial applies where unrelated resources succeed but the invalid one fails
  • Gives faster feedback in CI pipelines
  • Is especially valuable for complex resource configs where the API has richer validation logic than what can be expressed in Terraform schema

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions