A Terraform provider for managing Cloudflare Origin Certificates imported into AWS ACM.
This provider automates the process of:
- Generating an EC P-256 private key
- Creating a CSR for a domain
- Requesting a Cloudflare Origin Certificate via their API
- Importing the certificate into AWS ACM
If an existing certificate for the domain already exists in ACM, it will be reused instead of creating a new one.
- Go 1.21+ (for building)
- Terraform 1.0+
- AWS credentials configured
- Cloudflare API token with Origin CA permissions
cd certificate-provider
go mod tidy
go build -o terraform-provider-cfcertFor local development, add to your ~/.terraformrc:
provider_installation {
dev_overrides {
"envato/cfcert" = "/path/to/certificate-provider"
}
direct {}
}provider "cfcert" {
region = "ap-southeast-2" # Optional, defaults to AWS_REGION
cloudflare_api_token = "your-api-token" # Optional, defaults to CLOUDFLARE_API_TOKEN
}Creates or imports a Cloudflare Origin Certificate into AWS ACM.
resource "cfcert_origin_certificate" "example" {
domain_name = "example.com"
}
output "certificate_arn" {
value = cfcert_origin_certificate.example.certificate_arn
}domain_name- (Required) The domain name for the certificate. Changing this forces a new resource.
certificate_arn- The ARN of the ACM certificate.id- Same ascertificate_arn.
Look up an existing certificate by domain name.
data "cfcert_origin_certificate" "example" {
domain_name = "example.com"
}
output "certificate_arn" {
value = data.cfcert_origin_certificate.example.certificate_arn
}domain_name- (Required) The domain name to search for.
certificate_arn- The ARN of the ACM certificate.id- Same ascertificate_arn.
AWS_REGION- AWS region (can be overridden by provider config)CLOUDFLARE_API_TOKEN- Cloudflare API token (can be overridden by provider config)- Standard AWS credential environment variables (
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, etc.)
- The resource will reuse an existing certificate if one with the same domain name already exists in ACM (with
EC_prime256v1key type and ISSUED status) - Certificates are requested with a 15-year (5475 days) validity period from Cloudflare
- Deleting the resource will delete the certificate from ACM