This is a mock implementation of a Terraform provider that simulates managing synthetic monitoring checks through a fictional "CloudCanary" platform. This provider is intended for demonstration, educational purposes, and as a starting template for developing real Terraform providers.
Note: This provider doesn't connect to any real service. It simulates API interactions and returns mock data.
- HTTP Checks: Simulate monitoring websites and HTTP endpoints
- API Checks: Simulate monitoring API endpoints with JSON validation
- Multi-region: Simulate running checks from multiple geographic regions
- Results Data Source: Access mock monitoring results within Terraform
- Clone the repository
git clone https://github.com/yourorg/terraform-provider-cloudcanary.git
cd terraform-provider-cloudcanary
- Build the provider
make build
- Install the provider for local use
make install
Configure the provider:
terraform {
required_providers {
cloudcanary = {
source = "yourorg/cloudcanary"
version = "~> 0.1.0"
}
}
}
provider "cloudcanary" {
# Any non-empty string will work as an API key
api_key = "test-api-key"
# Optional: specify a custom API base URL (not used in mock implementation)
# base_url = "https://api.custom-cloudcanary.example.com/v1"
}
resource "cloudcanary_http_check" "website" {
name = "Company Website"
url = "https://example.com"
method = "GET"
expected_status = 200
interval = 60 # seconds
timeout = 10 # seconds
follow_redirects = true
regions = [
"us-east-1",
"eu-west-1"
]
headers = {
"User-Agent" = "CloudCanary/1.0"
}
expected_response = "Welcome to Example"
}
resource "cloudcanary_api_check" "api" {
name = "Status API"
endpoint = "https://api.example.com/v1/status"
method = "POST"
expected_status = 200
interval = 300 # seconds
headers = {
"Content-Type" = "application/json"
}
body = jsonencode({
query = "status"
})
auth_type = "bearer"
auth_value = "sample-token"
response_validation = [
"$.status == 'up'",
"$.version != null"
]
}
data "cloudcanary_check_results" "website_results" {
check_id = cloudcanary_http_check.website.id
limit = 10
}
output "latest_status" {
value = data.cloudcanary_check_results.website_results.results[0].status
}
name
- (Required) Name of the checkurl
- (Required) URL to checkmethod
- (Optional) HTTP method (GET, POST, etc.). Default: GETheaders
- (Optional) Map of HTTP headersbody
- (Optional) HTTP request body for POST/PUT requestsexpected_status
- (Optional) Expected HTTP status code. Default: 200expected_response
- (Optional) Text that should be in the response bodyinterval
- (Optional) Check interval in seconds. Default: 60timeout
- (Optional) Request timeout in seconds. Default: 10follow_redirects
- (Optional) Whether to follow redirects. Default: trueregions
- (Optional) List of regions to run the check fromretries
- (Optional) Number of retry attempts. Default: 0
id
- Generated unique identifier for the checklast_result
- Result of the most recent check (always "PENDING" initially, then "SUCCESS" for mock reads)last_check_time
- Time of the most recent check
name
- (Required) Name of the checkendpoint
- (Required) API endpoint URLmethod
- (Optional) HTTP method. Default: GETheaders
- (Optional) Map of HTTP headersbody
- (Optional) HTTP request body (typically JSON)expected_status
- (Optional) Expected HTTP status code. Default: 200response_validation
- (Optional) List of JSONPath validationsinterval
- (Optional) Check interval in seconds. Default: 300timeout
- (Optional) Request timeout in seconds. Default: 30auth_type
- (Optional) Authentication type (none, basic, bearer, api_key)auth_value
- (Optional) Authentication value (token, API key, etc.)
id
- Generated unique identifier for the checklast_result
- Result of the most recent check (always "PENDING" initially, then "SUCCESS" for mock reads)last_check_time
- Time of the most recent check
check_id
- (Required) ID of the check to get results forlimit
- (Optional) Maximum number of results to return. Default: 10start_time
- (Optional) Start time for results (RFC3339 format, not actually used in the mock)end_time
- (Optional) End time for results (RFC3339 format, not actually used in the mock)
id
- Generated unique identifier for this data source instanceresults
- List of simulated check results, with the following fields:id
- Generated unique identifier for the resultcheck_id
- ID of the check this result belongs tostatus
- Alternating result status (SUCCESS, FAILURE)response_time
- Simulated response time in millisecondsmessage
- Generic message associated with the resulttimestamp
- Simulated timestamp when the check was executed (RFC3339 format)region
- Region where the check was executed (if applicable)response_body
- Response body (if available)response_code
- HTTP response code (if available)failure_reason
- Reason for failure (if applicable)
This provider implements a simulated/mock version of a monitoring service:
- No actual HTTP requests are made - All API operations are simulated within the provider
- Resources persist only in Terraform state - No actual checks are created on any remote system
- Generated IDs - Check IDs are deterministically generated based on names and endpoints
- Simulated results - The data source returns mock check results with alternating success/failure patterns
make build
make test
make install
This provider carefully preserves null values in Terraform state to avoid inconsistencies. When creating or updating resources, it's important to understand that:
- Fields not specified in your configuration will remain
null
- Default values are only used internally for API calls but not imposed on Terraform state
- This ensures that Terraform's plan and apply mechanisms work correctly and don't detect false changes
The auth_value
field for API checks is marked as sensitive and will be stored securely in Terraform state. Its value will not be displayed in logs or console output.