2016-03-23 20:53:50 +01:00
---
layout: "fastly"
2016-05-23 14:50:36 +02:00
page_title: "Fastly: service_v1"
2016-03-23 20:53:50 +01:00
sidebar_current: "docs-fastly-resource-service-v1"
description: |-
Provides an Fastly Service
---
# fastly\_service\_v1
2016-03-24 15:53:25 +01:00
Provides a Fastly Service, representing the configuration for a website, app,
2016-10-31 09:52:27 +01:00
API, or anything else to be served through Fastly. A Service encompasses Domains
2016-03-23 20:53:50 +01:00
and Backends.
2016-03-24 15:53:25 +01:00
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][fastly-cname]
2016-05-23 14:56:20 +02:00
on their documentation site for guidance.
2016-03-23 20:53:50 +01:00
## 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
}
```
2016-10-31 09:52:27 +01:00
Basic usage with an Amazon S3 Website and that removes the `x-amz-request-id` header:
2016-03-23 20:53:50 +01:00
```
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
}
2016-04-18 18:11:16 +02:00
header {
destination = "http.x-amz-request-id"
type = "cache"
action = "delete"
name = "remove x-amz-request-id"
}
2016-04-20 20:43:54 +02:00
gzip {
name = "file extensions and content types"
extensions = ["css", "js"]
content_types = ["text/html", "text/css"]
}
2016-03-23 20:53:50 +01:00
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"
}
}
```
2016-10-31 09:52:27 +01:00
Basic usage with [custom
VCL](https://docs.fastly.com/guides/vcl/uploading-custom-vcl) (must be
enabled on your Fastly account):
2016-05-17 21:49:51 +02:00
```
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")}"
}
}
```
2016-10-31 09:52:27 +01:00
-> **Note:** For an AWS S3 Bucket, the Backend address is
2016-03-23 20:53:50 +01:00
`<domain>.s3-website-<region>.amazonaws.com` . The `default_host` attribute
should be set to `<bucket_name>.s3-website-<region>.amazonaws.com` . See the
2016-04-18 18:11:16 +02:00
Fastly documentation on [Amazon S3][fastly-s3].
2016-03-23 20:53:50 +01:00
## Argument Reference
The following arguments are supported:
2016-10-31 09:52:27 +01:00
* `name` - (Required) The unique name for the Service to create.
2016-03-23 20:53:50 +01:00
* `domain` - (Required) A set of Domain names to serve as entry points for your
2016-10-31 09:52:27 +01:00
Service. Defined below.
2016-03-23 20:53:50 +01:00
* `backend` - (Required) A set of Backends to service requests from your Domains.
2016-10-31 09:52:27 +01:00
Defined below.
2016-05-09 20:08:13 +02:00
* `condition` - (Optional) A set of conditions to add logic to any basic
2016-10-31 09:52:27 +01:00
configuration object in this service. Defined below.
2016-05-23 22:07:00 +02:00
* `cache_setting` - (Optional) A set of Cache Settings, allowing you to override
when an item is not to be cached based on an above `condition` . Defined below
2016-04-20 20:43:54 +02:00
* `gzip` - (Required) A set of gzip rules to control automatic gzipping of
2016-10-31 09:52:27 +01:00
content. Defined below.
2016-04-18 18:11:16 +02:00
* `header` - (Optional) A set of Headers to manipulate for each request. Defined
2016-10-31 09:52:27 +01:00
below.
* `default_host` - (Optional) The default hostname.
* `default_ttl` - (Optional) The default Time-to-live (TTL) for
requests.
2016-03-23 20:53:50 +01:00
* `force_destroy` - (Optional) Services that are active cannot be destroyed. In
order to destroy the Service, set `force_destroy` to `true` . Default `false` .
2016-05-11 23:56:18 +02:00
* `request_setting` - (Optional) A set of Request modifiers. Defined below
2016-04-28 17:36:25 +02:00
* `s3logging` - (Optional) A set of S3 Buckets to send streaming logs too.
2016-10-31 09:52:27 +01:00
Defined below.
2017-01-30 17:05:27 +01:00
* `papertrail` - (Optional) A Papertrail endpoint to send streaming logs too.
Defined below.
2016-10-31 09:52:27 +01:00
* `vcl` - (Optional) A set of custom VCL configuration blocks. The
2016-05-17 21:49:51 +02:00
ability to upload custom VCL code is not enabled by default for new Fastly
accounts (see the [Fastly documentation ](https://docs.fastly.com/guides/vcl/uploading-custom-vcl ) for details).
2016-03-23 20:53:50 +01:00
The `domain` block supports:
2016-10-31 09:52:27 +01:00
* `name` - (Required) The domain to which this Service will respond.
* `comment` - (Optional) An optional comment about the Domain.
2016-03-23 20:53:50 +01:00
The `backend` block supports:
2016-10-31 09:52:27 +01:00
* `name` - (Required, string) Name for this Backend. Must be unique to this Service.
* `address` - (Required, string) An IPv4, hostname, or IPv6 address for the Backend.
* `auto_loadbalance` - (Optional, boolean) Denotes if this Backend should be
2016-03-23 20:53:50 +01:00
included in the pool of backends that requests are load balanced against.
2016-10-31 09:52:27 +01:00
Default `true` .
* `between_bytes_timeout` - (Optional) How long to wait between bytes in milliseconds. Default `10000` .
2016-03-23 20:53:50 +01:00
* `connect_timeout` - (Optional) How long to wait for a timeout in milliseconds.
Default `1000`
2016-10-31 09:52:27 +01:00
* `error_threshold` - (Optional) Number of errors to allow before the Backend is marked as down. Default `0` .
* `first_byte_timeout` - (Optional) How long to wait for the first bytes in milliseconds. Default `15000` .
2016-03-23 20:53:50 +01:00
* `max_conn` - (Optional) Maximum number of connections for this Backend.
2016-10-31 09:52:27 +01:00
Default `200` .
* `port` - (Optional) The port number on which the Backend responds. Default `80` .
2017-01-30 17:05:27 +01:00
* `request_condition` - (Optional, string) Condition, which if met, will select this backend during a request.
2016-10-31 09:52:27 +01:00
* `ssl_check_cert` - (Optional) Be strict about checking SSL certs. Default `true` .
2016-12-06 09:30:44 +01:00
* `ssl_hostname` - (Optional) Used for both SNI during the TLS handshake and to validate the cert.
2016-12-12 23:17:35 +01:00
* `shield` - (Optional) The POP of the shield designated to reduce inbound load.
2016-10-31 09:52:27 +01:00
* `weight` - (Optional) The [portion of traffic ](https://docs.fastly.com/guides/performance-tuning/load-balancing-configuration.html#how-weight-affects-load-balancing ) to send to this Backend. Each Backend receives `weight / total` of the traffic. Default `100` .
2016-03-23 20:53:50 +01:00
2016-05-09 20:08:13 +02:00
The `condition` block supports allows you to add logic to any basic configuration
object in a service. See Fastly's documentation
["About Conditions" ](https://docs.fastly.com/guides/conditions/about-conditions )
for more detailed information on using Conditions. The Condition `name` can be
used in the `request_condition` , `response_condition` , or
2016-10-31 09:52:27 +01:00
`cache_condition` attributes of other block settings.
2016-05-09 20:08:13 +02:00
2016-10-31 09:52:27 +01:00
* `name` - (Required) The unique name for the condition.
* `statement` - (Required) The statement used to determine if the condition is met.
2016-05-09 20:08:13 +02:00
* `priority` - (Required) A number used to determine the order in which multiple
2016-10-31 09:52:27 +01:00
conditions execute. Lower numbers execute first.
* `type` - (Required) Type of condition, either `REQUEST` (req), `RESPONSE`
(req, resp), or `CACHE` (req, beresp).
2016-05-09 20:08:13 +02:00
2016-05-23 22:07:00 +02:00
The `cache_setting` block supports:
2016-10-31 09:52:27 +01:00
* `name` - (Required) Unique name for this Cache Setting.
2016-05-23 22:07:00 +02:00
* `action` - (Required) One of `cache` , `pass` , or `restart` , as defined
2016-10-31 09:52:27 +01:00
on Fastly's documentation under ["Caching action descriptions" ](https://docs.fastly.com/guides/performance-tuning/controlling-caching#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 type `CACHE` .
2016-05-23 22:07:00 +02:00
* `stale_ttl` - (Optional) Max "Time To Live" for stale (unreachable) objects.
2016-10-31 09:52:27 +01:00
Default `300` .
* `ttl` - (Optional) The Time-To-Live (TTL) for the object.
2016-05-23 22:07:00 +02:00
2016-04-20 20:43:54 +02:00
The `gzip` block supports:
2016-10-31 09:52:27 +01:00
* `name` - (Required) A unique name.
* `content_types` - (Optional) The content-type for each type of content you wish to
have dynamically gzip'ed. Example: `["text/html", "text/css"]` .
2016-05-23 14:56:20 +02:00
* `extensions` - (Optional) File extensions for each file type to dynamically
2016-10-31 09:52:27 +01:00
gzip. Example: `["css", "js"]` .
2016-04-20 20:43:54 +02:00
2016-04-18 18:11:16 +02:00
The `Header` block supports adding, removing, or modifying Request and Response
2016-05-23 14:56:20 +02:00
headers. See Fastly's documentation on
2016-10-31 09:52:27 +01:00
[Adding or modifying headers on HTTP requests and responses ](https://docs.fastly.com/guides/basic-configuration/adding-or-modifying-headers-on-http-requests-and-responses#field-description-table ) for more detailed information on any of the properties below.
2016-04-18 18:11:16 +02:00
2016-10-31 09:52:27 +01:00
* `name` - (Required) Unique name for this header attribute.
2016-04-18 18:11:16 +02:00
* `action` - (Required) The Header manipulation action to take; must be one of
2016-10-31 09:52:27 +01:00
`set` , `append` , `delete` , `regex` , or `regex_repeat` .
* `type` - (Required) The Request type on which to apply the selected Action; must be one of `request` , `fetch` , `cache` or `response` .
* `destination` - (Required) The name of the header that is going to be affected by the Action.
* `ignore_if_set` - (Optional) Do not add the header if it is already present. (Only applies to the `set` action.). Default `false` .
* `source` - (Optional) Variable to be used as a source for the header
content. (Does not apply to the `delete` action.)
* `regex` - (Optional) Regular expression to use (Only applies to the `regex` and `regex_repeat` actions.)
* `substitution` - (Optional) Value to substitute in place of regular expression. (Only applies to the `regex` and `regex_repeat` actions.)
* `priority` - (Optional) Lower priorities execute first. Default: `100` .
2016-04-18 18:11:16 +02:00
2017-02-07 11:34:58 +01:00
The `healthcheck` block supports:
* `name` - (Required) A unique name to identify this Healthcheck.
* `host` - (Required) Address of the host to check.
* `path` - (Required) The path to check.
* `check_interval` - (Optional) How often to run the Healthcheck in milliseconds. Default `5000` .
* `expected_response` - (Optional) The status code expected from the host. Default `200` .
* `http_version` - (Optional) Whether to use version 1.0 or 1.1 HTTP. Default `1.1` .
* `initial` - (Optional) When loading a config, the initial number of probes to be seen as OK. Default `2` .
* `method` - (Optional) Which HTTP method to use. Default `HEAD` .
* `threshold` - (Optional) How many Healthchecks must succeed to be considered healthy. Default `3` .
* `timeout` - (Optional) Timeout in milliseconds. Default `500` .
* `window` - (Optional) The number of most recent Healthcheck queries to keep for this Healthcheck. Default `5` .
2016-05-11 23:56:18 +02:00
The `request_setting` block allow you to customize Fastly's request handling, by
defining behavior that should change based on a predefined `condition` :
2016-10-31 09:52:27 +01:00
* `name` - (Required) The domain for this request setting.
2016-05-11 23:56:18 +02:00
* `request_condition` - (Required) The name of the corresponding `condition` to
2016-10-31 09:52:27 +01:00
determine if this request setting should be applied. The `request_condition` must
match the name of a defined `condition` .
2016-05-11 23:56:18 +02:00
* `max_stale_age` - (Optional) How old an object is allowed to be to serve
2016-10-31 09:52:27 +01:00
`stale-if-error` or `stale-while-revalidate` , in seconds. Default `60` .
* `force_miss` - (Optional) Force a cache miss for the request. If specified,
2016-05-11 23:56:18 +02:00
can be `true` or `false` .
2016-10-31 09:52:27 +01:00
* `force_ssl` - (Optional) Forces the request to use SSL (Redirects a non-SSL request to SSL).
2016-05-11 23:56:18 +02:00
* `action` - (Optional) Allows you to terminate request handling and immediately
2016-10-31 09:52:27 +01:00
perform an action. When set it can be `lookup` or `pass` (Ignore the cache completely).
2016-05-11 23:56:18 +02:00
* `bypass_busy_wait` - (Optional) Disable collapsed forwarding, so you don't wait
2016-10-31 09:52:27 +01:00
for other objects to origin.
2016-05-11 23:56:18 +02:00
* `hash_keys` - (Optional) Comma separated list of varnish request object fields
2016-10-31 09:52:27 +01:00
that should be in the hash key.
* `xff` - (Optional) X-Forwarded-For, should be `clear` , `leave` , `append` ,
`append_all` , or `overwrite` . Default `append` .
2016-05-11 23:56:18 +02:00
* `timer_support` - (Optional) Injects the X-Timer info into the request for
2016-10-31 09:52:27 +01:00
viewing origin fetch durations.
2016-05-11 23:56:18 +02:00
* `geo_headers` - (Optional) Injects Fastly-Geo-Country, Fastly-Geo-City, and
2016-10-31 09:52:27 +01:00
Fastly-Geo-Region into the request headers.
* `default_host` - (Optional) Sets the host header.
2016-05-11 23:56:18 +02:00
2016-04-28 17:36:25 +02:00
The `s3logging` block supports:
2016-10-31 09:52:27 +01:00
* `name` - (Required) A unique name to identify this S3 Logging Bucket.
* `bucket_name` - (Optional) An optional comment about the Domain.
2016-04-28 17:36:25 +02:00
* `s3_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
2016-10-31 09:52:27 +01:00
not be encrypted. You can provide this key via an environment variable, `FASTLY_S3_ACCESS_KEY` .
2016-04-28 17:36:25 +02:00
* `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
2016-10-31 09:52:27 +01:00
not be encrypted. You can provide this secret via an environment variable, `FASTLY_S3_SECRET_KEY` .
2016-04-28 17:36:25 +02:00
* `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 of `us-east-1` ,
2016-10-31 09:52:27 +01:00
then specify the corresponding bucket endpoint. Example: `s3-us-west-2.amazonaws.com` .
2016-04-28 17:36:25 +02:00
* `period` - (Optional) How frequently the logs should be transferred, in
2016-10-31 09:52:27 +01:00
seconds. Default `3600` .
2016-04-28 17:36:25 +02:00
* `gzip_level` - (Optional) Level of GZIP compression, from `0-9` . `0` is no
compression. `1` is fastest and least compressed, `9` is slowest and most
2016-10-31 09:52:27 +01:00
compressed. Default `0` .
* `format` - (Optional) Apache-style string or VCL variables to use for log formatting. Defaults to Apache Common Log format (`%h %l %u %t %r %>s`)
2016-04-28 17:36:25 +02:00
* `timestamp_format` - (Optional) `strftime` specified timestamp formatting (default `%Y-%m-%dT%H:%M:%S.000` ).
2016-05-11 23:56:18 +02:00
* `request_condition` - (Optional) The VCL request condition to check if this
Request Setting should be applied. For detailed information about Conditionals,
2016-10-31 09:52:27 +01:00
see [Fastly's Documentation on Conditionals][fastly-conditionals].
2016-04-28 17:36:25 +02:00
2017-01-30 17:05:27 +01:00
The `papertrail` block supports:
* `name` - (Required) A unique name to identify this Papertrail endpoint.
* `address` - (Required) The address of the Papertrail endpoint.
* `port` - (Required) The port associated with the address where the Papertrail endpoint can be accessed.
* `format` - (Optional) Apache-style string or VCL variables to use for log formatting. Defaults to Apache Common Log format (`%h %l %u %t %r %>s`)
* `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][fastly-conditionals].
2016-05-17 21:49:51 +02:00
The `vcl` block supports:
2016-10-31 09:52:27 +01:00
* `name` - (Required) A unique name for this configuration block.
2016-05-17 21:49:51 +02:00
* `content` - (Required) The custom VCL code to upload.
* `main` - (Optional) If `true` , use this block as the main configuration. If
`false` , use this block as an includable library. Only a single VCL block can be
marked as the main block. Default is `false` .
2016-04-28 17:36:25 +02:00
2016-03-23 20:53:50 +01:00
## Attributes Reference
The following attributes are exported:
2016-10-31 09:52:27 +01:00
* `id` - The ID of the Service.
* `name` – Name of this service.
* `active_version` - The currently active version of your Fastly
Service.
* `domain` – Set of Domains. See above for details.
* `backend` – Set of Backends. See above for details.
* `header` – Set of Headers. See above for details.
* `s3logging` – Set of S3 Logging configurations. See above for details.
2017-01-30 17:05:27 +01:00
* `papertrail` – Set of Papertrail configurations. See above for details.
2016-10-31 09:52:27 +01:00
* `vcl` – Set of custom VCL configurations. See above for details.
* `default_host` – Default host specified.
* `default_ttl` - Default TTL.
* `force_destroy` - Force the destruction of the Service on delete.
2016-03-23 20:53:50 +01:00
2016-03-24 15:53:25 +01:00
[fastly-s3]: https://docs.fastly.com/guides/integrations/amazon-s3
[fastly-cname]: https://docs.fastly.com/guides/basic-setup/adding-cname-records
2016-05-11 23:56:18 +02:00
[fastly-conditionals]: https://docs.fastly.com/guides/conditions/using-conditions