Skip to content

Conversation

Prajwal-Shah
Copy link

Related Issue

Fixes #300

Description

This pull request introduces a new http resource to the provider. The http resource allows users to perform HTTP requests as part of their Terraform apply or destroy operations, capturing response data such as headers, body, and status code in the Terraform state.

Key design decisions and features:

  • The resource supports methods defined in RFC7231 namely GET, HEAD, and POST methods, with optional request headers and body.
  • Read operations do not send any HTTP requests, hence no updates to state.
  • Updates to resource are made only when there are changes in input attributes.
  • Introduced a new when argument that allows users to control whether the request is sent during apply (create/update) or destroy.
    • Introduced new modelV1 for resource/http to support when attribute without affecting the existing data-source module.
    • Accepted values for when are "apply" and "destroy"
    • When when = "apply" (default):
      The provider sends the request during create and update operations. Computed response values are saved to the state file.
    • When when = "destroy":
      The provider sends the request only during resource deletion. During terraform apply, computed response attributes will be empty or zero, while input attributes are stored as provided.
  • Response data is available as computed attributes, including support for non-UTF-8 responses (with warnings).
  • Retries can be configured using a retry block, leveraging go-retryablehttp.
  • Documentation and examples have been added to the docs/ and examples/ directories.
  • Full test coverage is provided in internal/provider/resource_http_test.go.

This design provides flexibility for users needing to trigger HTTP endpoints as part of their infrastructure workflows, while maintaining a clear separation from the existing data source.

Files added/modified (main...feature/issue-300)

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Changes to Security Controls

  • The new resource/http implementation reuses the request-handling logic from data-source/http, ensuring consistency in behavior.
  • No additional security changes have been introduced beyond those already documented for data-source/http.

Sample Plan

# http.get will be created
  + resource "http" "get" {
      + body                 = (known after apply)
      + id                   = (known after apply)
      + method               = "GET"
      + response_body        = (known after apply)
      + response_body_base64 = (known after apply)
      + response_headers     = (known after apply)
      + status_code          = (known after apply)
      + url                  = "http://127.0.0.1:8000/terraform/http_resource"
      + when                 = "apply"
    }

  # http.post will be created
  + resource "http" "post" {
      + body                 = (known after apply)
      + id                   = (known after apply)
      + method               = "POST"
      + request_body         = jsonencode(
            {
              + message = "Hello, World!"
            }
        )
      + response_body        = (known after apply)
      + response_body_base64 = (known after apply)
      + response_headers     = (known after apply)
      + status_code          = (known after apply)
      + url                  = "http://127.0.0.1:8000/terraform/http_resource"
      + when                 = "destroy"

      + retry {
          + attempts     = 2
          + max_delay_ms = 5000
          + min_delay_ms = 1000
        }
    }

@Prajwal-Shah Prajwal-Shah requested a review from a team as a code owner August 28, 2025 13:25
Copy link

hashicorp-cla-app bot commented Aug 28, 2025

CLA assistant check
All committers have signed the CLA.

@Prajwal-Shah Prajwal-Shah changed the title Feature/issue 300 Feature/issue 300 - Http Resource Aug 28, 2025
- Introduce optional when attribute for http resource: apply (default) or destroy
- Execute HTTP request on Create/Update when when = "apply"
- Execute HTTP request only on Delete when when = "destroy"
- Do not send HTTP requests on Read; preserve state on Update when when = "destroy"
- Ensure all computed fields are set to known values when skipping requests (id, headers, body, body_base64, status_code)
- Add tests for apply, destroy, and default behaviors
- Update docs and examples to cover when semantics
Earlier it was using modelV1 which also changed docs for data-source
Introduced new modelV1 with when attribute for resource http
@Prajwal-Shah Prajwal-Shah requested a review from a team as a code owner October 18, 2025 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add HTTPS Resource Request

1 participant