FEATURES PRICING ABOUT DOCS LOGIN

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:

The domain block supports:

The backend block supports:

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

The cache_setting block supports:

The gzip block supports:

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.

The request_setting block allow you to customize Fastly’s request handling, by defining behavior that should change based on a predefined condition:

The s3logging block supports:

The vcl block supports:

Attributes Reference

The following attributes are exported:


See the source of this document at Terraform.io

REQUEST A DEMO