The Gcore Terraform provider v2 manages CDN resources using a modernized schema with cleaner attribute names, write-only credential fields, and a map-based options syntax. The following resources are supported: origin groups, CDN resources with delivery options, SSL certificates, CA certificates, rules, and rule templates. Provider installation and authentication are covered in the Terraform overview; for migration from v0, use the migration guide.Documentation Index
Fetch the complete documentation index at: https://gcore.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Key differences from provider v0
Provider v2 introduces changes to resource names, authentication, options syntax, and credential handling compared to v0.| Area | Provider v0 | Provider v2 |
|---|---|---|
| Authentication | permanent_api_token | api_key |
| SSL certificate resource | gcore_cdn_sslcert | gcore_cdn_certificate |
| CA certificate resource | gcore_cdn_cacert | gcore_cdn_trusted_ca_certificate |
| Rule resource | gcore_cdn_rule | gcore_cdn_resource_rule |
| Origin group sources | Nested origin {} blocks | sources = [{}] list attribute |
| Delivery options | options { block {} } nested blocks | options = { key = {} } map attribute |
| S3 credentials | Stored in state | Write-only (not stored in state) |
| SSL cert fields | cert, private_key | ssl_certificate_wo, ssl_private_key_wo |
gcore_cdn_applied_preset, gcore_cdn_client_config, gcore_cdn_originshielding, and gcore_cdn_logs_uploader_*.
Workflow
Add resource configuration tomain.tf, configure the provider with api_key, then run:
Provider configuration
Configure the provider block inmain.tf with the api_key attribute.
api_key instead of permanent_api_token. The value is a Gcore API token.
Manage origin groups
An origin group defines the servers the CDN pulls content from. In v2, sources are specified as a list attribute rather than nested blocks.Create an origin group with host origins
In v2, origins are defined as asources list attribute rather than nested blocks.
- Open the
main.tffile with the Gcore provider configuration. - Copy the code below and customize the values:
- Configure the origin group.
- Specify
name— the display name in the Customer Portal. - Set
use_next:true— if the first active origin fails, CDN tries remaining active origins in order, then backup origins.false— if the first active origin fails, CDN skips remaining active origins and immediately uses backup origins.
- For each object in
sources:- Specify
source— the domain or IP of the origin. The domain must resolve in DNS. - Set
enabled = trueto make the origin active. - (optional) Set
backup = trueto designate the origin as a backup. - (optional) Set
host_header_override— customHostheader for this specific origin.
- Specify
- (optional) Set
proxy_next_upstream— a list of conditions that trigger failover to the next origin. Accepted values:error,timeout,invalid_header,http_403,http_404,http_429,http_500,http_502,http_503,http_504. Default:["error", "timeout"].
Create an origin group with an S3 origin
S3 credentials in v2 are write-only — they are sent to the API on creation but never stored in Terraform state. Increments3_credentials_version each time credentials are rotated to force Terraform to re-send them.
- Open the
main.tffile. - Copy the code below and customize the values:
- Configure the S3 origin.
- Set
s3_credentials_version— an integer incremented each time credentials are rotated, which forces Terraform to re-send the write-only values. Required when any source hasorigin_type = "s3". - For each S3 source object in
sources:- Set
origin_type = "s3". - In the nested
configobject:- Set
s3_type:"amazon"for Amazon S3,"other"for S3-compatible storage. - Specify
s3_bucket_name. - Specify
s3_region— required whens3_type = "amazon". - Specify
s3_storage_hostname— required whens3_type = "other". - Specify
s3_access_key_idands3_secret_access_key— these are write-only and will not appear in Terraform state.
- Set
- Set
Manage CDN resources
A CDN resource maps a custom domain to an origin group and controls how content is delivered. In v2, delivery options use a map attribute syntax instead of nested blocks.Create a basic CDN resource
The following configuration creates a CDN resource that serves content from an origin group over HTTPS.- Specify
cname— the custom domain for content delivery. After applying, create a CNAME DNS record pointing this domain to the Gcore CDN zone shown in the Portal setup guide. - Specify either
origin_group(ID of an origin group) ororigin(a single origin domain or IP). - Set
origin_protocol:"MATCH"— CDN uses the same protocol as the client request."HTTP"— CDN always requests the origin over HTTP."HTTPS"— CDN always requests the origin over HTTPS.
- (optional) Add
secondary_hostnames— a set of additional CNAMEs. - (optional) Add
name— a display name for the resource in the Portal. - (optional) Add
description— a free-text label. - (optional) Set
active = falseto suspend delivery. Defaults totrue.
Configure delivery options
In provider v2, delivery options use a map attribute syntax (options = { ... }) instead of nested blocks. Each option is a key-value pair where the value is an object.
In v2, setting an option to
null removes it from the CDN resource. Options not listed in the options map are not modified — they inherit account-level defaults.| Option | Description |
|---|---|
edge_cache_settings | CDN caching duration. value sets default TTL; custom_values sets per-status-code TTL. |
browser_cache_settings | Client-side Cache-Control header TTL. |
gzip_on | Gzip compression. Set value = true. |
brotli_compression | Brotli compression. Set value to a list of MIME types. |
redirect_http_to_https | Redirect HTTP to HTTPS. Set value = true. |
tls_versions | Restrict accepted TLS versions. Set value to a list: ["TLSv1.2", "TLSv1.3"]. |
cors | CORS. Set value to a list of allowed origins; use ["*"] for all. |
allowed_http_methods | Restrict allowed HTTP methods. Set value to a list. |
country_acl | Allow or deny access by country. Set policy_type and excepted_values. |
ip_address_acl | Allow or deny access by IP. Set policy_type and excepted_values. |
referrer_acl | Allow or deny access by referrer. Set policy_type and excepted_values. |
user_agent_acl | Allow or deny access by user agent. |
secure_key | Token authentication. Set key and type. |
stale | Serve stale content on specified conditions (e.g., ["http_500", "updating"]). |
host_header | Override the Host header sent to the origin. |
sni | SNI settings. Set sni_type to "dynamic" or "custom". |
rewrite | URL rewriting. Set body with rewrite pattern and flag. |
static_request_headers | Add headers to origin requests. Set value to a map. |
static_response_headers | Add headers to CDN responses. Set value to a list of objects. |
response_headers_hiding_policy | Hide response headers from clients. |
request_limiter | Rate limiting. Set rate and rate_unit. |
limit_bandwidth | Bandwidth throttling. Set limit_type, speed, and buffer. |
follow_origin_redirect | Follow redirects from the origin. Set codes to a list of redirect codes. |
websockets | Enable WebSocket pass-through. Set value = true. |
http3_enabled | Enable HTTP/3. Set value = true. |
image_stack | Image optimization. Set quality, avif_enabled, webp_enabled. |
proxy_connect_timeout | Timeout for connecting to the origin (e.g., "4s"). |
proxy_read_timeout | Timeout for reading from the origin (e.g., "10s"). |
Enable SSL delivery
Setssl_enabled and reference the certificate ID to deliver content over HTTPS.
- Set
ssl_enabled = trueto deliver content over HTTPS. - Set
ssl_datato the ID of agcore_cdn_certificateresource.
Enable origin SSL verification
Setproxy_ssl_enabled to verify the origin server’s SSL certificate before serving content.
proxy_ssl_enabled = true— verifies the origin server’s SSL certificate.proxy_ssl_ca— ID of the CA certificate used to verify the origin. Referencesgcore_cdn_trusted_ca_certificate.proxy_ssl_data— ID of a client certificate presented to the origin for mTLS. Must be a manually uploadedgcore_cdn_certificate(not automated).
Manage SSL certificates
SSL certificates secure the connection between CDN edge servers and clients. In v2, certificate fields are renamed and manual certificates use write-only attributes.Issue a Let’s Encrypt certificate automatically
Thegcore_cdn_certificate resource with automated = true requests and renews a Let’s Encrypt certificate automatically.
- Specify
name— must be unique within the account. - Set
automated = trueto request a Let’s Encrypt certificate.
cert_subject_cn, cert_subject_alt, cert_issuer, validity_not_before, validity_not_after.
Let’s Encrypt validates domain ownership before issuing the certificate, so the CNAME DNS record for the CDN domain must already point to Gcore CDN before applying.
Upload a custom SSL certificate
Certificate and private key are write-only in v2 — sent to the API but never stored in state. Incrementssl_certificate_wo_version each time the certificate is rotated to force Terraform to re-send it.
ssl_certificate_wo— the public certificate in PEM format. Include the full chain.ssl_private_key_wo— the private key in PEM format.ssl_certificate_wo_version— increment this value to force Terraform to re-send the certificate to the API. Required when using write-only certificate fields.- (optional) Set
validate_root_ca = trueto verify that the certificate chain is trusted by a CA.
Manage CA certificates for origin verification
A CA certificate (gcore_cdn_trusted_ca_certificate) is used to verify the origin server’s SSL certificate or to authenticate mutual TLS connections.
- Specify
name— must be unique within the account. - Specify
ssl_certificate— the CA certificate in PEM format. Each certificate in the chain must end with a newline character.
cert_subject_cn, cert_subject_alt, cert_issuer, validity_not_before, validity_not_after.
Manage CDN resource rules
A CDN resource rule (gcore_cdn_resource_rule) applies a separate set of delivery options to requests matching a path pattern. Rules override the CDN resource options for matched paths.
Create a rule
The following configuration creates a rule that applies extended caching and gzip compression to requests matching/images/*.png.
- Specify
resource_id— the ID of the CDN resource the rule belongs to. - Specify
name— the display name in the Customer Portal. - Specify
rule— the path pattern. Must start with/. - Set
rule_type:0— path pattern with wildcards (e.g.,/images/*.png).1— regular expression (must start with^/).
- (optional) Add an
optionsmap with the same options available on the CDN resource. - (optional) Set
active = falseto disable the rule without deleting it. - (optional) Set
weight— rule execution priority. Lower number = higher priority. - (optional) Set
origin_group— ID of an alternative origin group for requests matched by this rule. - (optional) Set
override_origin_protocol— override the origin protocol for matched requests ("HTTP","HTTPS", or"MATCH").
Manage rule templates
A rule template (gcore_cdn_rule_template) is a reusable rule configuration not tied to a specific CDN resource.
- (optional) Specify
name— the template display name. - Specify
rule— the path pattern. - Set
rule_type—0for path patterns,1for regular expressions. - Add an
optionsmap with the delivery options to apply. - (optional) Set
weight— execution priority. - (optional) Set
override_origin_protocol— override the origin protocol.
client (account ID), default (whether it is a system template), template (always true for templates), and deleted.