### How to Use the Documentation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/MANIFEST.md Provides a step-by-step guide on how to navigate and utilize the generated documentation, starting with the README. ```plaintext 1. **Start with [README.md](README.md)** for navigation and overview 2. **For a specific component**, see the relevant file in `api-reference/` 3. **For configuration examples**, see [configuration.md](configuration.md) 4. **For error diagnosis**, see [errors.md](errors.md) 5. **For type definitions**, see [types.md](types.md) ``` -------------------------------- ### Provider Initialization Example Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Example demonstrating how to use the New factory function to create a provider instance and serve it using the providerserver. This is typically found in the main entry point of the provider. ```go // From main.go provider := provider.New(version) err := providerserver.Serve(context.Background(), provider, opts) ``` -------------------------------- ### Terraform HCL: GET with Headers and Parameters Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-data-source.md Shows how to make a GET request with custom headers and query parameters. This example includes setting an Authorization header and specifying limit, offset, and filter parameters. ```hcl data "terracurl_request" "filtered_data" { name = "filtered-api-call" url = "https://api.example.com/items" method = "GET" headers = { Authorization = "Bearer ${var.api_token}" Accept = "application/json" } request_parameters = { limit = "100" offset = "0" filter = "active" } response_codes = [200] timeout = 30 } ``` -------------------------------- ### Build the provider Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/README.md Use the Go install command to build the provider binary. ```sh $ go install ``` -------------------------------- ### Terraform Curl Resource Example Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-resource.md This example demonstrates how to configure the terracurl_request resource to create a new resource, including request details, headers, response codes, and destroy configurations. ```hcl resource "terracurl_request" "mount" { name = "vault-mount" url = "https://vault.example.com/v1/sys/mounts/aws" method = "POST" request_body = jsonencode({ type = "aws" config = { force_no_cache = true } }) headers = { X-Vault-Token = "root" } response_codes = [200, 204] destroy_url = "https://vault.example.com/v1/sys/mounts/aws" destroy_method = "DELETE" destroy_headers = { X-Vault-Token = "root" } destroy_response_codes = [204] } ``` -------------------------------- ### Terraform HCL: Basic GET Request Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-data-source.md Demonstrates a simple GET request to an example API. It configures the data source with a name, URL, method, and expected success response code. ```hcl data "terracurl_request" "api_data" { name = "my-api-call" url = "https://api.example.com/data" method = "GET" response_codes = [200] } ``` -------------------------------- ### Terraform Configuration Example Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Example of how to configure the TerraCurl provider in a Terraform project. It specifies the provider source and version, and notes that no explicit configuration is required within the provider block. ```hcl terraform { required_providers { terracurl = { source = "devops-rob/terracurl" version = ">= 1.0" } } } provider "terracurl" { # No configuration required } ``` -------------------------------- ### Request Failed Example (Exceeding Max Retries) Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/errors.md Illustrates a 'Request Failed' error, typically due to network issues after exhausting all retry attempts. This example shows a 'no such host' error after 3 retries. ```text Resource create API Call: failed after 3 retry attempts Request Failed: dial tcp: lookup api.example.com: no such host ``` -------------------------------- ### Terraform Framework Type Mappings Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/types.md Illustrates the mapping between Terraform plugin framework types and their corresponding Go types. Shows examples of how to create values for each type. ```go type CurlEphemeralModel struct { Id types.String Name types.String Url types.String Method types.String RequestBody types.String Headers types.Map RequestParameters types.Map RequestUrlString types.String CertFile types.String KeyFile types.String CaCertFile types.String CaCertDirectory types.String SkipTlsVerify types.Bool RetryInterval types.Int64 MaxRetry types.Int64 Timeout types.Int64 Response types.String ResponseCodes types.List StatusCode types.String SkipRenew types.Bool RenewInterval types.Int64 RenewUrl types.String RenewMethod types.String RenewRequestBody types.String RenewHeaders types.Map RenewRequestParameters types.Map RenewRequestUrlString types.String RenewCertFile types.String RenewKeyFile types.String RenewCaCertFile types.String RenewCaCertDirectory types.String RenewSkipTlsVerify types.Bool RenewRetryInterval types.Int64 RenewMaxRetry types.Int64 RenewTimeout types.Int64 RenewResponse types.String RenewResponseCodes types.List SkipClose types.Bool CloseUrl types.String CloseMethod types.String CloseRequestBody types.String CloseHeaders types.Map CloseRequestParameters types.Map CloseRequestUrlString types.String CloseCertFile types.String CloseKeyFile types.String CloseCaCertFile types.String CloseCaCertDirectory types.String CloseSkipTlsVerify types.Bool CloseRetryInterval types.Int64 CloseMaxRetry types.Int64 CloseTimeout types.Int64 CloseResponse types.String CloseResponseCodes types.List } ``` ```go type TlsConfig struct { CertFile string KeyFile string CaCertFile string CaCertDirectory string SkipTlsVerify bool } ``` ```go type RequestResourceModel struct { ConfigurableAttribute types.String Defaulted types.String Id types.String } ``` -------------------------------- ### Terraform HCL Example: Basic GET Request Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-data-source.md A basic example of using the terracurl_request data source to fetch data from a HashiCorp API. It specifies the name, URL, method, and expected response codes. ```hcl data "terracurl_request" "products" { name = "hashicorp-products" url = "https://api.releases.hashicorp.com/v1/products" method = "GET" response_codes = [200] max_retry = 3 retry_interval = 5 timeout = 15 } locals { products = jsondecode(data.terracurl_request.products.response) } output "product_list" { value = local.products } ``` -------------------------------- ### Define Placeholder RequestResourceModel Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/types.md This Go struct serves as a placeholder model for an unused example resource. It is included as a template within the codebase. ```go type RequestResourceModel struct { ConfigurableAttribute types.String Defaulted types.String Id types.String } ``` -------------------------------- ### Retry Logic Example Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-data-source.md Illustrates the retry mechanism for HTTP requests. The loop continues until a valid response code is received or the maximum number of retries is exhausted. ```go for { response := client.Do(request) if responseCodeValid(statusCode): break if retryCount < maxRetry: sleep(retryInterval) retryCount++ else: return error } ``` -------------------------------- ### Unexpected Response Code Example Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/errors.md Demonstrates an 'Unexpected Response Code' error where the received HTTP status code is not within the list of acceptable codes defined in response_codes. The example shows a resource configuration with allowed codes '200' and '201'. ```hcl resource "terracurl_request" "example" { # ... response_codes = ["200", "201"] } ``` -------------------------------- ### Documentation Standards Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/MANIFEST.md Lists the core principles guiding the documentation, emphasizing technical accuracy, completeness, and practical examples. ```plaintext 1. **No Marketing Copy** — Strictly technical content only 2. **No Tutorials** — Reference focused, not instructional 3. **Complete Signatures** — All parameter types and return types explicit 4. **Real Examples** — Practical code samples showing actual usage 5. **Cross-References** — Links between related documentation 6. **Source Locations** — File paths and line numbers for all definitions 7. **Error Catalog** — Precise trigger conditions for all errors 8. **Configuration Tables** — Parameters with types, defaults, descriptions ``` -------------------------------- ### Check Terraform Provider Version Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/README.md Use the `terraform providers` command to list installed providers and their versions. This helps in verifying that the correct provider version is being used. ```hcl terraform providers ``` -------------------------------- ### defaultTlsConfig Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/utilities.md Provides a default `TlsConfig` instance initialized with zero values for all fields. This serves as a starting point for creating custom TLS configurations. ```APIDOC ## defaultTlsConfig ### Description Returns a default `TlsConfig` instance with all zero values. ### Function Signature ```go func defaultTlsConfig() *TlsConfig ``` ### Returns - **`*TlsConfig`** - Pointer to an empty TLS configuration struct. ### Example ```go tlsCfg := defaultTlsConfig() tlsCfg.SkipTlsVerify = true ``` ``` -------------------------------- ### API Call with Retry Logic Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/configuration.md Sets up a GET request with configured retry attempts, interval, and timeout for handling flaky API responses. ```hcl resource "terracurl_request" "with_retries" { name = "api-with-retries" url = "https://api.example.com/flaky" method = "GET" response_codes = ["200"] max_retry = 5 retry_interval = 3 timeout = 30 } ``` -------------------------------- ### Authenticated Request with Bearer Token Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/README.md Configure an authenticated GET request by including an Authorization header with a Bearer token. The token should be sourced from a variable. ```hcl resource "terracurl_request" "authenticated" { name = "authenticated-request" url = "https://api.example.com/protected" method = "GET" response_codes = ["200"] headers = { Authorization = "Bearer ${var.api_token}" } } ``` -------------------------------- ### Response Code Validation Example Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/errors.md Illustrates correct and incorrect ways to specify response codes in Terraform configuration. Incorrect types can lead to errors, although the provider attempts to convert them. ```hcl response_codes = ["200", "201"] # Correct response_codes = [200, 201] # Type error (converted to "200", "201") ``` -------------------------------- ### Configure Method Implementation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Configures the provider by initializing an HTTP client for resources and data sources. It extracts provider configuration, creates an HTTP client, and assigns it to the response's data fields. ```go func (p *TerraCurlProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) ``` -------------------------------- ### Run acceptance tests Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/README.md Execute the full suite of acceptance tests using the make command. ```sh $ make test ``` -------------------------------- ### Configure Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Configures the provider by creating HTTP client instances for resources and data sources. It extracts provider configuration, creates an HTTP client, and passes it to the response data. ```APIDOC ## Configure ### Description Configures the provider by creating HTTP client instances for resources and data sources. It extracts provider configuration, creates an HTTP client, and passes it to the response data. ### Method ```go func (p *TerraCurlProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response - **resp.DataSourceData** - HTTP client for data sources. - **resp.ResourceData** - HTTP client for resources. ### Request Example ```hcl terraform { required_providers { terracurl = { source = "devops-rob/terracurl" version = "~> 1.0" } } } provider "terracurl" { # No configuration required } ``` ### Response Example None ``` -------------------------------- ### Generate Provider Documentation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/README.md Run this command to auto-generate markdown documentation for the Terraform Registry using `terraform-plugin-docs`. ```bash make docs ``` -------------------------------- ### Add provider dependencies Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/README.md Use Go modules to add and tidy dependencies for the provider. ```sh go get github.com/author/dependency go mod tidy ``` -------------------------------- ### Create TLS-Configured HTTP Client Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/utilities.md Constructs an HTTP client with custom TLS/mTLS settings based on a provided TlsConfig. Handles certificate loading and verification options. ```Go tlsConfig := &TlsConfig{ CertFile: "/path/to/client.pem", KeyFile: "/path/to/client-key.pem", CaCertFile: "/path/to/ca.pem", SkipTlsVerify: false, } client, err := createTlsClient(tlsConfig) if err != nil { log.Fatalf("Failed to create TLS client: %v", err) } resp, err := client.Do(request) ``` -------------------------------- ### Terraform Provider Configuration Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/configuration.md Configure the TerraCurl provider in your Terraform setup. No specific provider-level configuration is required. ```hcl terraform { required_providers { terracurl = { source = "devops-rob/terracurl" version = "~> 1.0" } } } provider "terracurl" { # No configuration required } ``` -------------------------------- ### Create Default TLS Configuration Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/utilities.md Initializes a default TLS configuration structure with all fields set to their zero values. Allows for subsequent modification to customize TLS/mTLS settings. ```Go tlsCfg := defaultTlsConfig() tlsCfg.SkipTlsVerify = true ``` -------------------------------- ### Metadata Method Implementation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Sets the provider's metadata, including its type name and version, in the response. ```go func (p *TerraCurlProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) ``` -------------------------------- ### Functions Method Implementation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Returns a list of provider functions. Currently, this method returns an empty array as no provider functions are defined. ```go func (p *TerraCurlProvider) Functions(ctx context.Context) []func() function.Function ``` -------------------------------- ### New Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Creates and returns a new provider factory function. It takes the provider version as input. ```APIDOC ## New ### Description Creates and returns a new provider factory function. It takes the provider version as input. ### Method ```go func New(version string) func() provider.Provider ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response - **func() provider.Provider** - A function that instantiates a `TerraCurlProvider` with the given version. ### Request Example ```go // From main.go provider := provider.New(version) err := providerserver.Serve(context.Background(), provider, opts) ``` ### Response Example None ``` -------------------------------- ### createTlsClient Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/utilities.md Constructs an `http.Client` configured with specified TLS settings. It handles loading client certificates, configuring CA certificates, and setting verification options. ```APIDOC ## createTlsClient ### Description Creates an HTTP client configured with TLS settings from the provided configuration. ### Function Signature ```go func createTlsClient(cfg *TlsConfig) (*http.Client, error) ``` ### Parameters #### Path Parameters This function does not have path parameters. #### Query Parameters This function does not have query parameters. #### Request Body This function does not have a request body. ### Parameters - **cfg** (*TlsConfig) - Required - TLS configuration object ### Returns - **`*http.Client`** - A configured HTTP client with TLS support. - **`error`** - An error if the TLS setup fails. ### Process 1. Loads client certificates if both `CertFile` and `KeyFile` are provided. 2. Initializes CA certificate pool: Starts with the system's certificate pool, or creates a new one if unavailable. 3. Loads a single CA certificate from `CaCertFile` if provided. 4. Creates a TLS configuration including loaded certificates, the root CA pool, and the `InsecureSkipVerify` flag. 5. Creates an HTTP client with a custom transport that uses the configured TLS settings. 6. Sets the client timeout to 30 seconds. ### Errors - TLS certificate loading failures. - CA certificate file reading failures. - Invalid certificate formats. - Key-pair mismatches. ### Example ```go tlsConfig := &TlsConfig{ CertFile: "/path/to/client.pem", KeyFile: "/path/to/client-key.pem", CaCertFile: "/path/to/ca.pem", SkipTlsVerify: false, } client, err := createTlsClient(tlsConfig) if err != nil { log.Fatalf("Failed to create TLS client: %v", err) } resp, err := client.Do(request) ``` ``` -------------------------------- ### Basic Ephemeral Configuration for Token Acquisition Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/configuration.md This snippet demonstrates a basic configuration for an ephemeral resource to acquire a temporary token. It specifies the URL, method, request body, and expected response codes for the initial token acquisition. ```hcl ephemeral "terracurl_request" "temporary_token" { name = "temp-token" url = "https://auth.example.com/token" method = "POST" request_body = jsonencode({ grant_type = "client_credentials" client_id = var.client_id client_secret = var.client_secret }) response_codes = ["200"] skip_renew = false renew_interval = 3600 renew_url = "https://auth.example.com/token/refresh" renew_method = "POST" renew_response_codes = ["200"] skip_close = false close_url = "https://auth.example.com/token/revoke" close_method = "POST" close_response_codes = ["204"] } locals { token_response = jsondecode(ephemeral.terracurl_request.temporary_token.response) access_token = local.token_response.access_token } # Use the ephemeral token in another resource resource "example_resource" "using_token" { api_token = local.access_token } ``` -------------------------------- ### Terraform HCL: POST with Body and Retries Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-data-source.md An example of a POST request with a JSON body, custom content type header, and configured retry logic. It specifies multiple successful response codes and retry parameters. ```hcl data "terracurl_request" "search_results" { name = "api-search" url = "https://api.example.com/search" method = "POST" request_body = jsonencode({ query = "terraform" limit = 50 }) headers = { Content-Type = "application/json" } response_codes = [200, 201] max_retry = 3 retry_interval = 2 timeout = 20 } ``` -------------------------------- ### Basic terracurl_request Resource Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/configuration.md Define a basic terracurl_request resource to manage an HTTP API call. This is useful for simple GET, POST, PUT, or DELETE operations where only the URL, method, and expected response codes are needed. ```hcl resource "terracurl_request" "example" { name = "my-api-call" url = "https://api.example.com/endpoint" method = "POST" response_codes = ["200", "201"] } ``` -------------------------------- ### EphemeralResources Method Implementation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Returns a list of ephemeral resource factory functions, specifically providing the factory for ephemeral HTTP requests. ```go func (p *TerraCurlProvider) EphemeralResources(_ context.Context) []func() ephemeral.EphemeralResource ``` -------------------------------- ### Resources Method Implementation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Returns a list of resource factory functions, specifically providing the factory for the 'terracurl_request' resource. ```go func (p *TerraCurlProvider) Resources(ctx context.Context) []func() resource.Resource ``` -------------------------------- ### Open Ephemeral Resource Configuration Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/ephemeral-resource.md Configure an ephemeral resource to make an initial HTTP request. This is useful for acquiring resources like authentication tokens that have a limited lifespan and require renewal and closing. ```hcl ephemeral "terracurl_request" "vault_token" { name = "vault-auth" url = "https://vault.example.com/v1/auth/approle/login" method = "POST" request_body = jsonencode({ role_id = var.vault_role_id secret_id = var.vault_secret_id }) response_codes = [200] skip_renew = false renew_interval = 3600 renew_url = "https://vault.example.com/v1/auth/token/renew-self" renew_method = "POST" renew_headers = { X-Vault-Token = "will_be_filled_from_response" } renew_response_codes = [200] skip_close = false close_url = "https://vault.example.com/v1/auth/token/revoke-self" close_method = "POST" close_headers = { X-Vault-Token = "will_be_filled_from_response" } close_response_codes = [204] } ``` -------------------------------- ### Generated Documentation File Structure Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/MANIFEST.md Lists the generated documentation files and their primary purposes within the project. ```plaintext output/ ├── README.md (Main index and navigation guide) ├── MANIFEST.md (This file) ├── types.md (Type definitions and models) ├── configuration.md (Configuration reference with examples) ├── errors.md (Error catalog and debugging) └── api-reference/ ├── provider.md (TerraCurlProvider implementation) ├── curl-resource.md (Managed resource implementation) ├── curl-data-source.md (Read-only data source) ├── ephemeral-resource.md (Ephemeral resource for credentials) └── utilities.md (Helper functions and TLS utilities) ``` -------------------------------- ### DataSources Method Implementation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Returns a list of data source factory functions, specifically providing the factory for the 'terracurl_request' data source. ```go func (p *TerraCurlProvider) DataSources(ctx context.Context) []func() datasource.DataSource ``` -------------------------------- ### Configure TLS/mTLS Authentication Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/types.md This Go struct defines the configuration for TLS/mTLS authentication. It includes fields for certificate and key file paths, CA certificate details, and an option to skip TLS verification. ```go type TlsConfig struct { CertFile string KeyFile string CaCertFile string CaCertDirectory string SkipTlsVerify bool } ``` -------------------------------- ### Content Summary of Documentation Files Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/MANIFEST.md Provides a table summarizing the purpose, sections, and word count for each generated documentation file. ```markdown | File | Purpose | Sections | Word Count | |------|---------|----------|-----------| | README.md | Navigation hub, quick reference | 12 | ~650 | | types.md | Type definitions | 8 | ~450 | | configuration.md | Configuration guide | 12 | ~950 | | errors.md | Error catalog | 40+ | ~800 | | api-reference/provider.md | Provider API | 6 | ~400 | | api-reference/curl-resource.md | Resource API | 15 | ~800 | | api-reference/curl-data-source.md | Data Source API | 12 | ~600 | | api-reference/ephemeral-resource.md | Ephemeral API | 14 | ~900 | | api-reference/utilities.md | Utilities API | 20 | ~700 | | **TOTAL** | | | ~2,060 | ``` -------------------------------- ### Configuration Coverage Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/MANIFEST.md Summarizes the coverage of configuration aspects, including provider, resource, data source, and ephemeral resource attributes, as well as TLS and retry parameters. ```plaintext - ✅ Provider-level configuration (none required) - ✅ Resource attributes (30+ attributes) - ✅ Data source attributes (18+ attributes) - ✅ Ephemeral resource attributes (50+ attributes) - ✅ TLS/mTLS configuration - ✅ Retry logic parameters - ✅ Common patterns and examples ``` -------------------------------- ### Functions Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Returns the list of provider functions. This is currently unused and returns an empty array. ```APIDOC ## Functions ### Description Returns the list of provider functions. This is currently unused and returns an empty array. ### Method ```go func (p *TerraCurlProvider) Functions(ctx context.Context) []func() function.Function ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response - **[]func() function.Function** - An empty array; no provider functions are currently defined. ### Request Example None ### Response Example None ``` -------------------------------- ### Schema Method Implementation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Defines the provider schema. The TerraCurl provider has no required configuration and returns an empty schema. ```go func (p *TerraCurlProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) ``` -------------------------------- ### Resource with Drift Detection Configuration Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/README.md Implement drift detection for a resource by configuring read operations. Specify the read URL, method, and response codes, and optionally ignore certain response fields. ```hcl resource "terracurl_request" "with_drift_detection" { name = "resource-with-drift" url = "https://api.example.com/create" method = "POST" response_codes = ["200"] skip_read = false read_url = "https://api.example.com/status" read_method = "GET" read_response_codes = ["200"] ignore_response_fields = ["timestamp", "request_id"] } ``` -------------------------------- ### CurlResource Metadata Method Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-resource.md Implements the Metadata method for the CurlResource, setting the resource type name. ```go func (r *CurlResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) ``` -------------------------------- ### Curl Resource Create Operation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-resource.md Executes the create operation by making an HTTP request and storing the response. It handles configuration validation, TLS client creation, request building, execution with retries, and response processing. ```APIDOC ## POST /resource ### Description Executes the create operation by making an HTTP request and storing the response. It handles configuration validation, TLS client creation, request building, execution with retries, and response processing. ### Method POST ### Endpoint /resource ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **request_body** (string) - Optional - Request body to attach to API call - **headers** (map(string)) - Optional - Map of headers for the request - **request_parameters** (map(string)) - Optional - Query parameters to add to URL - **cert_file** (string) - Optional - PEM-encoded certificate file path - **key_file** (string) - Optional - PEM-encoded private key file path - **ca_cert_file** (string) - Optional - CA certificate file for TLS validation - **ca_cert_directory** (string) - Optional - Directory containing CA certificates - **skip_tls_verify** (bool) - Optional - Skip TLS verification - **retry_interval** (int64) - Optional - Seconds between retry attempts - **max_retry** (int64) - Optional - Maximum number of retries - **timeout** (int64) - Optional - Request timeout in seconds - **skip_destroy** (bool) - Optional - Skip issuing destroy request - **destroy_url** (string) - Optional - Endpoint for destroy operation - **destroy_method** (string) - Optional - HTTP method for destroy operation - **destroy_request_body** (string) - Optional - Body for destroy request - **destroy_headers** (map(string)) - Optional - Headers for destroy request - **destroy_request_parameters** (map(string)) - Optional - Parameters for destroy request - **destroy_cert_file** (string) - Optional - Certificate for destroy request - **destroy_key_file** (string) - Optional - Private key for destroy request - **destroy_ca_cert_file** (string) - Optional - CA cert for destroy request - **destroy_ca_cert_directory** (string) - Optional - CA cert directory for destroy request - **destroy_skip_tls_verify** (bool) - Optional - Skip TLS verify for destroy - **destroy_retry_interval** (int64) - Optional - Retry interval for destroy (seconds) - **destroy_max_retry** (int64) - Optional - Max retries for destroy - **destroy_timeout** (int64) - Optional - Destroy timeout (seconds) - **destroy_response_codes** (list(string)) - Optional - Expected response codes for destroy - **skip_read** (bool) - Optional - Skip read operation (drift detection) - **read_url** (string) - Optional - Endpoint for read operation - **read_method** (string) - Optional - HTTP method for read operation - **read_headers** (map(string)) - Optional - Headers for read request - **read_parameters** (map(string)) - Optional - Parameters for read request - **read_request_body** (string) - Optional - Body for read request - **read_cert_file** (string) - Optional - Certificate for read request - **read_key_file** (string) - Optional - Private key for read request - **read_ca_cert_file** (string) - Optional - CA cert for read request - **read_ca_cert_directory** (string) - Optional - CA cert directory for read request - **read_skip_tls_verify** (bool) - Optional - Skip TLS verify for read - **read_response_codes** (list(string)) - Optional - Expected response codes for read - **ignore_response_fields** (list(string)) - Optional - JSON fields to ignore in drift detection ### Request Example ```hcl resource "terracurl_request" "mount" { name = "vault-mount" url = "https://vault.example.com/v1/sys/mounts/aws" method = "POST" request_body = jsonencode({ type = "aws" config = { force_no_cache = true } }) headers = { X-Vault-Token = "root" } response_codes = [200, 204] destroy_url = "https://vault.example.com/v1/sys/mounts/aws" destroy_method = "DELETE" destroy_headers = { X-Vault-Token = "root" } destroy_response_codes = [204] } ``` ### Response #### Success Response (200) - **id** (string) - Resource identifier (same as name) - **request_url_string** (string) - Full request URL including parameters - **response** (string) - JSON response received from API - **status_code** (string) - HTTP status code returned - **destroy_request_url_string** (string) - Destroy request URL with parameters - **drift_marker** (string) - Marker tracking state drift #### Response Example ```json { "id": "vault-mount", "request_url_string": "https://vault.example.com/v1/sys/mounts/aws?param1=value1", "response": "{\"data\": {}}", "status_code": "200", "destroy_request_url_string": "https://vault.example.com/v1/sys/mounts/aws", "drift_marker": "some_marker" } ``` ### Errors - Configuration validation errors if `skip_destroy=false` but destroy parameters missing - Configuration validation errors if `skip_read=false` but read parameters missing - TLS client creation failures - HTTP request failures after exhausting retries - Unexpected response codes ``` -------------------------------- ### Complete Ephemeral Configuration for Vault Token Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/configuration.md This snippet shows a comprehensive configuration for an ephemeral resource, specifically for obtaining a token from HashiCorp Vault. It includes detailed settings for initial acquisition, TLS configuration, automatic renewal, and cleanup operations. ```hcl ephemeral "terracurl_request" "vault_token" { # Initial Open operation name = "vault-dynamic-token" url = "https://vault.example.com/v1/auth/approle/login" method = "POST" request_body = jsonencode({ role_id = var.vault_role_id secret_id = var.vault_secret_id }) headers = { Content-Type = "application/json" } response_codes = ["200"] timeout = 10 max_retry = 2 retry_interval = 1 # TLS for initial request cert_file = "${path.module}/certs/client.pem" key_file = "${path.module}/certs/client-key.pem" ca_cert_file = "${path.module}/certs/ca.pem" # Renewal configuration skip_renew = false renew_interval = 3600 renew_url = "https://vault.example.com/v1/auth/token/renew-self" renew_method = "POST" renew_response_codes = ["200"] renew_timeout = 10 renew_max_retry = 1 renew_retry_interval = 2 renew_headers = { X-Vault-Token = "will_be_extracted_from_initial_response" } # Cleanup configuration skip_close = false close_url = "https://vault.example.com/v1/auth/token/revoke-self" close_method = "POST" close_response_codes = ["204] close_timeout = 10 close_headers = { X-Vault-Token = "will_be_extracted_from_initial_response" } } ``` -------------------------------- ### Resource with Custom Cleanup Logic Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/README.md Define a resource that includes custom cleanup logic upon destruction. Specify the destroy URL, method, and expected response codes for the cleanup operation. ```hcl resource "terracurl_request" "with_cleanup" { name = "resource-with-cleanup" url = "https://api.example.com/create" method = "POST" response_codes = ["201"] skip_destroy = false destroy_url = "https://api.example.com/delete" destroy_method = "DELETE" destroy_response_codes = ["204"] } ``` -------------------------------- ### API Request with Destroy Cleanup Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/configuration.md Configures a POST request that includes a separate destroy operation to clean up resources after creation. ```hcl resource "terracurl_request" "with_cleanup" { name = "api-with-cleanup" url = "https://api.example.com/create" method = "POST" response_codes = ["201"] skip_destroy = false destroy_url = "https://api.example.com/delete" destroy_method = "DELETE" destroy_response_codes = ["204"] } ``` -------------------------------- ### Terraform HCL: TLS Certificate Authentication Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-data-source.md Demonstrates how to configure TLS client certificate authentication for a secure API request. It includes paths to the client certificate, private key, and CA certificate. ```hcl data "terracurl_request" "secure_api" { name = "tls-api-call" url = "https://secure.example.com/api/data" method = "GET" cert_file = "${path.module}/certs/client.pem" key_file = "${path.module}/certs/client-key.pem" ca_cert_file = "${path.module}/certs/ca.pem" response_codes = [200] skip_tls_verify = false } ``` -------------------------------- ### ImportState Operation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-resource.md Implements resource import using the resource ID. It uses a passthrough import strategy, mapping the import ID to the resource's `id` attribute. ```APIDOC ## ImportState ### Description Implements resource import using the resource ID. It uses a passthrough import strategy, mapping the import ID to the resource's `id` attribute. ### Method Not applicable (Go function signature provided) ### Endpoint Not applicable (Go function signature provided) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None provided in source. ### Response #### Success Response (200) None explicitly defined. #### Response Example None provided in source. ``` -------------------------------- ### Drift Detection Update Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/errors.md Shows how drift detection updates a drift marker to trigger resource replacement on the next apply. This is a non-fatal error mechanism. ```go if oldSanitized != sanitizedResponse { data.DriftMarker = types.StringValue(time.Now().Format(time.RFC3339Nano)) // Resource will be replaced on next apply } ``` -------------------------------- ### Curl Data Source Read Operation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-data-source.md This Go function outlines the logic for executing an HTTP request as part of the data source's read operation. It handles configuration, client creation, request execution with retry logic, and response validation. ```go func (d *CurlDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) ``` -------------------------------- ### Open Ephemeral Resource Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/ephemeral-resource.md Opens (acquires) the ephemeral resource by executing the initial HTTP request. It validates configuration, builds a TLS client if necessary, executes the request with retry logic, and stores the response. Renewal and closing can be configured to be skipped. ```APIDOC ## Open Ephemeral Resource ### Description Opens (acquires) the ephemeral resource by executing the initial HTTP request. It validates configuration, builds a TLS client if necessary, executes the request with retry logic, and stores the response. Renewal and closing can be configured to be skipped. ### Method POST (inferred from example, actual method depends on implementation) ### Endpoint (Not explicitly defined, depends on resource type) ### Parameters #### Path Parameters None explicitly defined. #### Query Parameters None explicitly defined. #### Request Body - **name** (string) - Required - The name of the ephemeral resource. - **url** (string) - Required - The URL for the initial HTTP request. - **method** (string) - Required - The HTTP method for the initial request. - **request_body** (string) - Optional - The JSON-encoded request body. - **response_codes** (list of integers) - Required - Expected HTTP response codes. - **skip_renew** (boolean) - Optional - If true, renewal is skipped. - **renew_interval** (integer) - Optional - Interval in seconds for automatic renewal (required if skip_renew is false). - **renew_url** (string) - Optional - URL for the renewal request (required if skip_renew is false). - **renew_method** (string) - Optional - HTTP method for the renewal request (required if skip_renew is false). - **renew_headers** (map of strings) - Optional - Headers for the renewal request. - **renew_response_codes** (list of integers) - Optional - Expected HTTP response codes for renewal (required if skip_renew is false). - **skip_close** (boolean) - Optional - If true, closing is skipped. - **close_url** (string) - Optional - URL for the closing request (required if skip_close is false). - **close_method** (string) - Optional - HTTP method for the closing request (required if skip_close is false). - **close_headers** (map of strings) - Optional - Headers for the closing request. - **close_response_codes** (list of integers) - Optional - Expected HTTP response codes for closing (required if skip_close is false). ### Request Example ```hcl ephemeral "terracurl_request" "vault_token" { name = "vault-auth" url = "https://vault.example.com/v1/auth/approle/login" method = "POST" request_body = jsonencode({ role_id = var.vault_role_id secret_id = var.vault_secret_id }) response_codes = [200] skip_renew = false renew_interval = 3600 renew_url = "https://vault.example.com/v1/auth/token/renew-self" renew_method = "POST" renew_headers = { X-Vault-Token = "will_be_filled_from_response" } renew_response_codes = [200] skip_close = false close_url = "https://vault.example.com/v1/auth/token/revoke-self" close_method = "POST" close_headers = { X-Vault-Token = "will_be_filled_from_response" } close_response_codes = [204] } ``` ### Response #### Success Response (200) - **RenewAt** (string) - The time at which the resource will be automatically renewed. #### Response Example ```json { "RenewAt": "2023-10-27T10:00:00Z" } ``` ### Errors - Configuration validation errors - TLS client creation failures - HTTP request failures - Unexpected response codes ``` -------------------------------- ### Go Function for Creating a New CurlResource Instance Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-resource.md Provides the factory function `NewCurlResource` to create a new instance of `CurlResource`. This function returns a `resource.Resource` interface for managing HTTP API calls. ```go func NewCurlResource() resource.Resource ``` -------------------------------- ### CurlResource Schema Method Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-resource.md Defines the resource schema for CurlResource, specifying all parameters for create, read, and delete operations. ```go func (r *CurlResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) ``` -------------------------------- ### Secure Request with mTLS Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/README.md Set up a secure POST request using mutual TLS (mTLS) by providing client certificate, key, and CA certificate file paths. Ensure these files are accessible. ```hcl resource "terracurl_request" "secure" { name = "mtls-request" url = "https://secure.example.com/api" method = "POST" response_codes = ["200"] cert_file = "${path.module}/client.pem" key_file = "${path.module}/client-key.pem" ca_cert_file = "${path.module}/ca.pem" } ``` -------------------------------- ### Curl Data Source Factory Function Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-data-source.md This Go function creates and returns a new instance of the CurlDataSource. ```go func NewCurlDataSource() datasource.DataSource ``` -------------------------------- ### Quality Metrics for Documentation Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/MANIFEST.md Presents key metrics reflecting the quality and scope of the generated documentation, including lines of code, documentation lines, and documented entities. ```plaintext - **Total Lines of Code Analyzed:** ~3,300 (10 Go files) - **Total Documentation Generated:** ~2,060 lines - **Files Processed:** 10 source files - **Functions Documented:** 15+ - **Types Documented:** 7 - **Resources Documented:** 3 (1 managed, 1 data source, 1 ephemeral) - **Configuration Options:** 100+ - **Error Conditions:** 40+ - **Code Examples:** 30+ ``` -------------------------------- ### TLS Client Creation Error Handling Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/errors.md Handles errors during the creation of a TLS client. This snippet demonstrates how to add a diagnostic error to the Terraform response if TLS client creation fails. ```go if useTLS { tlsConfig := &TlsConfig{...} client, err := createTlsClient(tlsConfig) // Error here if err != nil { resp.Diagnostics.AddError("TLS Client Creation Failed", err.Error()) return } } ``` -------------------------------- ### EphemeralResources Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/provider.md Returns the list of ephemeral resource factory functions, including the factory for ephemeral HTTP requests. ```APIDOC ## EphemeralResources ### Description Returns the list of ephemeral resource factory functions, including the factory for ephemeral HTTP requests. ### Method ```go func (p *TerraCurlProvider) EphemeralResources(_ context.Context) []func() ephemeral.EphemeralResource ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response - **[]func() ephemeral.EphemeralResource** - An array containing `NewCurlEphemeralResource` factory function for ephemeral HTTP requests. ### Request Example None ### Response Example None ``` -------------------------------- ### TlsConfig Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/utilities.md Defines the structure for configuring TLS/mTLS client settings, including paths to certificate files and options for skipping TLS verification. ```APIDOC ## TlsConfig ### Description Configuration structure for TLS/mTLS client setup. ### Type Definition ```go type TlsConfig struct { CertFile string KeyFile string CaCertFile string CaCertDirectory string SkipTlsVerify bool } ``` ### Fields - **CertFile** (string) - Path to PEM-encoded client certificate - **KeyFile** (string) - Path to PEM-encoded private key - **CaCertFile** (string) - Path to PEM-encoded CA certificate file - **CaCertDirectory** (string) - Path to directory containing CA certificates - **SkipTlsVerify** (bool) - Whether to skip TLS certificate verification ``` -------------------------------- ### UpgradeState Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-resource.md Upgrades state from schema v0 to v1. This includes renaming `destroy_parameters` to `destroy_request_parameters` and adding read operation attributes. ```APIDOC ## UpgradeState ### Description Upgrades state from schema v0 to v1. This process includes renaming `destroy_parameters` to `destroy_request_parameters` and adding read operation attributes, with `skip_read` defaulting to `true` for backward compatibility. ### Method Not applicable (Go function signature provided) ### Endpoint Not applicable (Go function signature provided) ### Parameters None ### Request Example None provided in source. ### Response #### Success Response (200) - **state_upgraders** (map[int64]resource.StateUpgrader) - A map of state upgrader functions. #### Response Example None provided in source. ``` -------------------------------- ### Curl Data Source Configuration Validators Source: https://github.com/devops-rob/terraform-provider-terracurl/blob/main/_autodocs/api-reference/curl-data-source.md This Go function returns configuration validators for the Curl Data Source, ensuring consistent TLS settings and valid retry parameters. ```go func (d CurlDataSource) ConfigValidators(ctx context.Context) []datasource.ConfigValidator ```