13 KiB
layout | page_title | sidebar_current | description |
---|---|---|---|
fastly | Fastly: service_v1 | docs-fastly-resource-service-v1 | Provides an Fastly Service |
fastly_service_v1
Provides a Fastly Service, representing the configuration for a website, app, api, or anything else to be served through Fastly. A Service encompasses Domains and Backends.
The Service resource requires a domain name that is correctly set up to direct traffic to the Fastly service. See Fastly's guide on Adding CNAME Records on their documentation site for guidance.
Example Usage
Basic usage:
resource "fastly_service_v1" "demo" {
name = "demofastly"
domain {
name = "demo.notexample.com"
comment = "demo"
}
backend {
address = "127.0.0.1"
name = "localhost"
port = 80
}
force_destroy = true
}
Basic usage with an Amazon S3 Website, and removes the x-amz-request-id
header:
resource "fastly_service_v1" "demo" {
name = "demofastly"
domain {
name = "demo.notexample.com"
comment = "demo"
}
backend {
address = "demo.notexample.com.s3-website-us-west-2.amazonaws.com"
name = "AWS S3 hosting"
port = 80
}
header {
destination = "http.x-amz-request-id"
type = "cache"
action = "delete"
name = "remove x-amz-request-id"
}
gzip {
name = "file extensions and content types"
extensions = ["css", "js"]
content_types = ["text/html", "text/css"]
}
default_host = "${aws_s3_bucket.website.name}.s3-website-us-west-2.amazonaws.com"
force_destroy = true
}
resource "aws_s3_bucket" "website" {
bucket = "demo.notexample.com"
acl = "public-read"
website {
index_document = "index.html"
error_document = "error.html"
}
}
Basic usage with custom VCL (must be enabled on your Fastly account):
resource "fastly_service_v1" "demo" {
name = "demofastly"
domain {
name = "demo.notexample.com"
comment = "demo"
}
backend {
address = "127.0.0.1"
name = "localhost"
port = 80
}
force_destroy = true
vcl {
name = "my_custom_main_vcl"
content = "${file("${path.module}/my_custom_main.vcl")}"
main = true
}
vcl {
name = "my_custom_library_vcl"
content = "${file("${path.module}/my_custom_library.vcl")}"
}
}
Note: For an AWS S3 Bucket, the Backend address is
<domain>.s3-website-<region>.amazonaws.com
. The default_host
attribute
should be set to <bucket_name>.s3-website-<region>.amazonaws.com
. See the
Fastly documentation on Amazon S3.
Argument Reference
The following arguments are supported:
name
- (Required) The unique name for the Service to createdomain
- (Required) A set of Domain names to serve as entry points for your Service. Defined belowbackend
- (Required) A set of Backends to service requests from your Domains. Defined belowcondition
- (Optional) A set of conditions to add logic to any basic configuration object in this service. Defined belowcache_setting
- (Optional) A set of Cache Settings, allowing you to override when an item is not to be cached based on an abovecondition
. Defined belowgzip
- (Required) A set of gzip rules to control automatic gzipping of content. Defined belowheader
- (Optional) A set of Headers to manipulate for each request. Defined belowdefault_host
- (Optional) The default hostnamedefault_ttl
- (Optional) The default Time-to-live (TTL) for requestsforce_destroy
- (Optional) Services that are active cannot be destroyed. In order to destroy the Service, setforce_destroy
totrue
. Defaultfalse
.request_setting
- (Optional) A set of Request modifiers. Defined belows3logging
- (Optional) A set of S3 Buckets to send streaming logs too. Defined belowvcl
- (Optional) A set of custom VCL configuration blocks. Note that the ability to upload custom VCL code is not enabled by default for new Fastly accounts (see the Fastly documentation for details).
The domain
block supports:
name
- (Required) The domain that this Service will respond tocomment
- (Optional) An optional comment about the Domain
The backend
block supports:
name
- (Required, string) Name for this Backend. Must be unique to this Serviceaddress
- (Required, string) An IPv4, hostname, or IPv6 address for the Backendauto_loadbalance
- (Optional, boolean) Denote if this Backend should be included in the pool of backends that requests are load balanced against. Defaulttrue
between_bytes_timeout
- (Optional) How long to wait between bytes in milliseconds. Default10000
connect_timeout
- (Optional) How long to wait for a timeout in milliseconds. Default1000
error_threshold
- (Optional) Number of errors to allow before the Backend is marked as down. Default0
first_byte_timeout
- (Optional) How long to wait for the first bytes in milliseconds. Default15000
max_conn
- (Optional) Maximum number of connections for this Backend. Default200
port
- (Optional) The port number Backend responds on. Default80
ssl_check_cert
- (Optional) Be strict on checking SSL certs. Defaulttrue
weight
- (Optional) The portion of traffic to send to this Backend. Each Backend receivesweight / total
of the traffic. Default100
The condition
block supports allows you to add logic to any basic configuration
object in a service. See Fastly's documentation
"About Conditions"
for more detailed information on using Conditions. The Condition name
can be
used in the request_condition
, response_condition
, or
cache_condition
attributes of other block settings
name
- (Required) A unique name of the conditionstatement
- (Required) The statement used to determine if the condition is metpriority
- (Required) A number used to determine the order in which multiple conditions execute. Lower numbers execute firsttype
- (Required) Type of the condition, eitherREQUEST
(req),RESPONSE
(req, resp), orCACHE
(req, beresp)
The cache_setting
block supports:
name
- (Required) A unique name to label this Cache Settingaction
- (Required) One ofcache
,pass
, orrestart
, as defined on Fastly's documenation under "Caching action descriptions"cache_condition
- (Required) Name of the condition used to test whether this settings object should be used. This Condition must be of typeCACHE
stale_ttl
- (Optional) Max "Time To Live" for stale (unreachable) objects. Default300
ttl
- (Optional) The "Time To Live" for the object
The gzip
block supports:
name
- (Required) A unique namecontent_types
- (Optional) content-type for each type of content you wish to have dynamically gzipped. Ex:["text/html", "text/css"]
extensions
- (Optional) File extensions for each file type to dynamically gzip. Ex:["css", "js"]
The Header
block supports adding, removing, or modifying Request and Response
headers. See Fastly's documentation on
Adding or modifying headers on HTTP requests and responses for more detailed information on any
of the properties below.
name
- (Required) A unique name to refer to this header attributeaction
- (Required) The Header manipulation action to take; must be one ofset
,append
,delete
,regex
, orregex_repeat
type
- (Required) The Request type to apply the selected Action on; must be one ofrequest
,fetch
,cache
orresponse
destination
- (Required) The name of the header that is going to be affected by the Actionignore_if_set
- (Optional) Do not add the header if it is already present. (Only applies toset
action.). Defaultfalse
source
- (Optional) Variable to be used as a source for the header content (Does not apply todelete
action.)regex
- (Optional) Regular expression to use (Only applies toregex
andregex_repeat
actions.)substitution
- (Optional) Value to substitute in place of regular expression. (Only applies toregex
andregex_repeat
.)priority
- (Optional) Lower priorities execute first. (Default:100
.)
The request_setting
block allow you to customize Fastly's request handling, by
defining behavior that should change based on a predefined condition
:
name
- (Required) The domain that this request settingrequest_condition
- (Required) The name of the correspondingcondition
to determin if this request setting should be applied. Therequest_condition
must match the name of a definedcondition
max_stale_age
- (Optional) How old an object is allowed to be to serve stale-if-error or stale-while-revalidate, in seconds. Default60
force_miss
- (Optional) Force a cache miss for the request. If specfified, can betrue
orfalse
.force_ssl
- (Optional) Forces the request use SSL (redirects a non-SSL to SSL)action
- (Optional) Allows you to terminate request handling and immediately perform an action. When set it can belookup
orpass
(ignore the cache completely)bypass_busy_wait
- (Optional) Disable collapsed forwarding, so you don't wait for other objects to originhash_keys
- (Optional) Comma separated list of varnish request object fields that should be in the hash keyxff
- (Optional) X-Forwarded-For -- should beclear
,leave
,append
,append_all
, oroverwrite
. Defaultappend
timer_support
- (Optional) Injects the X-Timer info into the request for viewing origin fetch durationsgeo_headers
- (Optional) Injects Fastly-Geo-Country, Fastly-Geo-City, and Fastly-Geo-Region into the request headersdefault_host
- (Optional) Sets the host header
The s3logging
block supports:
name
- (Required) A unique name to identify this S3 Logging Bucketbucket_name
- (Optional) An optional comment about the Domains3_access_key
- (Required) AWS Access Key of an account with the required permissions to post logs. It is strongly recommended you create a separate IAM user with permissions to only operate on this Bucket. This key will be not be encrypted. You can provide this key via an environment variable,FASTLY_S3_ACCESS_KEY
s3_secret_key
- (Required) AWS Secret Key of an account with the required permissions to post logs. It is strongly recommended you create a separate IAM user with permissions to only operate on this Bucket. This secret will be not be encrypted. You can provide this secret via an environment variable,FASTLY_S3_SECRET_KEY
path
- (Optional) Path to store the files. Must end with a trailing slash. If this field is left empty, the files will be saved in the bucket's root path.domain
- (Optional) If you created the S3 bucket outside ofus-east-1
, then specify the corresponding bucket endpoint. Ex:s3-us-west-2.amazonaws.com
period
- (Optional) How frequently the logs should be transferred, in seconds. Default3600
gzip_level
- (Optional) Level of GZIP compression, from0-9
.0
is no compression.1
is fastest and least compressed,9
is slowest and most compressed. Default0
format
- (Optional) Apache-style string or VCL variables to use for log formatting. Default Apache Common Log format (%h %l %u %t %r %>s
)timestamp_format
- (Optional)strftime
specified timestamp formatting (default%Y-%m-%dT%H:%M:%S.000
).request_condition
- (Optional) The VCL request condition to check if this Request Setting should be applied. For detailed information about Conditionals, see Fastly's Documentation on Conditionals
The vcl
block supports:
name
- (Required) A unique name for this configuration blockcontent
- (Required) The custom VCL code to upload.main
- (Optional) Iftrue
, use this block as the main configuration. Iffalse
, use this block as an includable library. Only a single VCL block can be marked as the main block. Default isfalse
.
Attributes Reference
The following attributes are exported:
id
- The ID of the Servicename
– Name of this serviceactive_version
- The currently active version of your Fastly Servicedomain
– Set of Domains. See above for detailsbackend
– Set of Backends. See above for detailsheader
– Set of Headers. See above for detailss3logging
– Set of S3 Logging configurations. See above for detailsvcl
– Set of custom VCL configurations. See above for detailsdefault_host
– Default host specifieddefault_ttl
- Default TTLforce_destroy
- Force the destruction of the Service on delete