Skip to content

Commit

Permalink
feat(image_optimizer_default_settings): add Image Optimizer default s…
Browse files Browse the repository at this point in the history
…ettings API (#832)

* Temporarily vendor go-fastly from Image Optimizer default settings API PR

* Add Image Optimizer default settings API

* Generate docs.

* Handle case where reading image optimizer settings on a service without IO enabled.

* Fix "invalid key for element" error caused by missing "name" key

* PR cleanup suggestion.

* Include default values.

I was initially trying to get Terraform to ignore settings that wern't
set in the configuration, leaving them at their previously configured
value. This seems to be counter to Terraform's design, though, so I've
relented & included the current default values for each setting here.

It seems like maybe we could have done that for the string values, and
non-0 integers, but it seems like a nonstarter for booleans
(hashicorp/terraform-plugin-sdk#817), and
I didn't want to go against Terraform's design too much.

* Update go-fastly vendored from PR

* Fix lints + add debug message.

* One more vendor update.

* Update jpeg_type, and with that, finally have a passing test!

* Update vendored code again.

* Update field documentation.

Part of this is updating field with descriptions from the final
api-documentation PR. The other part is just my messing with stuff to
try to make it look better.

* Update generated docs

(also, move image_optimizer_default_settings guide from docs to templates)

* Change Delete so it resets all settings to default.

* Overhaul Image Optimizer default settings test.

* Update vendored go-fastly to 9.4.0.

* Add debug message for ignoring image-optimizer-disabled error on deletion.

This is working well! Just wanted to add this to double-confirm it's
doing what I expect.

* Remove toolchain directive.

* Undo go version bump.

Not sure why updating had caused this, but this should still work.
  • Loading branch information
daboross committed May 16, 2024
1 parent 97e0bf7 commit 56868fd
Show file tree
Hide file tree
Showing 16 changed files with 864 additions and 9 deletions.
65 changes: 65 additions & 0 deletions docs/guides/image_optimizer_default_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
page_title: image_optimizer_default_settings
subcategory: "Guides"
---

## Image Optimizer Default Settings

[Fastly Image Optimizer](https://docs.fastly.com/products/image-optimizer) (Fastly IO) is an [image optimization](https://www.fastly.com/learning/what-is-image-optimization) service that manipulates and transforms your images in real time and caches optimized versions of them.

Fastly Image Optimizer supports a variety of image formats and applies specific settings to all images by default. These can be controlled with this API or the [web interface](https://docs.fastly.com/en/guides/about-fastly-image-optimizer#configuring-default-image-settings). Changes to other image settings, including most image transformations, require using query string parameters on individual requests.

The [Image Optimizer default settings](https://developer.fastly.com/reference/api/services/image-optimizer-default-settings/) API allows customers to configure
default settings for Image Optimizer requests, configuring the way images are optimized when not overridden by URL parameters on specific requests.

The service must have the Image Optimizer product enabled using the Product Enablement API, UI, or Terraform block to use the `image_optimizer` block.

## Example Usage

Basic usage:

```terraform
resource "fastly_service_vcl" "demo" {
name = "demofastly"
domain {
name = "demo.notexample.com"
comment = "demo"
}
backend {
address = "127.0.0.1"
name = "localhost"
port = 80
}
product_enablement {
image_optimizer = true
}
image_optimizer_default_settings {
resize_filter = "lanczos3"
webp = false
webp_quality = 85
jpeg_type = "auto"
jpeg_quality = 85
upscale = false
allow_video = false
}
force_destroy = true
}
```

All fields in `image_optimizer_default_settings` are optional.

NOTE: When added, `image_optimizer_default_settings` will always set all default settings. This will replace any settings previously changed in the UI or API.

## Delete

Deleting the resource will reset all Image Optimizer default settings to their default values.

If deleting the resource errors due to Image Optimizer no longer being enabled on the service, then this error will be ignored.

When Image Optimizer is next re-enabled on a service, that service's Image Optimizer default settings will be reset - so a disabled service effectively already
has deleted/default Image Optimizer default settings.
24 changes: 24 additions & 0 deletions docs/resources/service_compute.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ $ terraform import fastly_service_compute.demo xxxxxxxxxxxxxxxxxxxx@2
- `comment` (String) Description field for the service. Default `Managed by Terraform`
- `dictionary` (Block Set) (see [below for nested schema](#nestedblock--dictionary))
- `force_destroy` (Boolean) Services that are active cannot be destroyed. In order to destroy the Service, set `force_destroy` to `true`. Default `false`
- `image_optimizer_default_settings` (Block Set, Max: 1) (see [below for nested schema](#nestedblock--image_optimizer_default_settings))
- `logging_bigquery` (Block Set) (see [below for nested schema](#nestedblock--logging_bigquery))
- `logging_blobstorage` (Block Set) (see [below for nested schema](#nestedblock--logging_blobstorage))
- `logging_cloudfiles` (Block Set) (see [below for nested schema](#nestedblock--logging_cloudfiles))
Expand Down Expand Up @@ -187,6 +188,29 @@ Read-Only:
- `dictionary_id` (String) The ID of the dictionary


<a id="nestedblock--image_optimizer_default_settings"></a>
### Nested Schema for `image_optimizer_default_settings`

Optional:

- `allow_video` (Boolean) Enables GIF to MP4 transformations on this service.
- `jpeg_quality` (Number) The default quality to use with JPEG output. This can be overridden with the "quality" parameter on specific image optimizer requests.
- `jpeg_type` (String) The default type of JPEG output to use. This can be overridden with "format=bjpeg" and "format=pjpeg" on specific image optimizer requests. Valid values are `auto`, `baseline` and `progressive`.
- auto: Match the input JPEG type, or baseline if transforming from a non-JPEG input.
- baseline: Output baseline JPEG images
- progressive: Output progressive JPEG images
- `name` (String) Used by the provider to identify modified settings. Changing this value will force the entire block to be deleted, then recreated.
- `resize_filter` (String) The type of filter to use while resizing an image. Valid values are `lanczos3`, `lanczos2`, `bicubic`, `bilinear` and `nearest`.
- lanczos3: A Lanczos filter with a kernel size of 3. Lanczos filters can detect edges and linear features within an image, providing the best possible reconstruction.
- lanczos2: A Lanczos filter with a kernel size of 2.
- bicubic: A filter using an average of a 4x4 environment of pixels, weighing the innermost pixels higher.
- bilinear: A filter using an average of a 2x2 environment of pixels.
- nearest: A filter using the value of nearby translated pixel values. Preserves hard edges.
- `upscale` (Boolean) Whether or not we should allow output images to render at sizes larger than input.
- `webp` (Boolean) Controls whether or not to default to WebP output when the client supports it. This is equivalent to adding "auto=webp" to all image optimizer requests.
- `webp_quality` (Number) The default quality to use with WebP output. This can be overridden with the second option in the "quality" URL parameter on specific image optimizer requests.


<a id="nestedblock--logging_bigquery"></a>
### Nested Schema for `logging_bigquery`

Expand Down
24 changes: 24 additions & 0 deletions docs/resources/service_vcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ $ terraform import fastly_service_vcl.demo xxxxxxxxxxxxxxxxxxxx@2
- `header` (Block Set) (see [below for nested schema](#nestedblock--header))
- `healthcheck` (Block Set) (see [below for nested schema](#nestedblock--healthcheck))
- `http3` (Boolean) Enables support for the HTTP/3 (QUIC) protocol
- `image_optimizer_default_settings` (Block Set, Max: 1) (see [below for nested schema](#nestedblock--image_optimizer_default_settings))
- `logging_bigquery` (Block Set) (see [below for nested schema](#nestedblock--logging_bigquery))
- `logging_blobstorage` (Block Set) (see [below for nested schema](#nestedblock--logging_blobstorage))
- `logging_cloudfiles` (Block Set) (see [below for nested schema](#nestedblock--logging_cloudfiles))
Expand Down Expand Up @@ -510,6 +511,29 @@ Optional:
- `window` (Number) The number of most recent Healthcheck queries to keep for this Healthcheck. Default `5`


<a id="nestedblock--image_optimizer_default_settings"></a>
### Nested Schema for `image_optimizer_default_settings`

Optional:

- `allow_video` (Boolean) Enables GIF to MP4 transformations on this service.
- `jpeg_quality` (Number) The default quality to use with JPEG output. This can be overridden with the "quality" parameter on specific image optimizer requests.
- `jpeg_type` (String) The default type of JPEG output to use. This can be overridden with "format=bjpeg" and "format=pjpeg" on specific image optimizer requests. Valid values are `auto`, `baseline` and `progressive`.
- auto: Match the input JPEG type, or baseline if transforming from a non-JPEG input.
- baseline: Output baseline JPEG images
- progressive: Output progressive JPEG images
- `name` (String) Used by the provider to identify modified settings. Changing this value will force the entire block to be deleted, then recreated.
- `resize_filter` (String) The type of filter to use while resizing an image. Valid values are `lanczos3`, `lanczos2`, `bicubic`, `bilinear` and `nearest`.
- lanczos3: A Lanczos filter with a kernel size of 3. Lanczos filters can detect edges and linear features within an image, providing the best possible reconstruction.
- lanczos2: A Lanczos filter with a kernel size of 2.
- bicubic: A filter using an average of a 4x4 environment of pixels, weighing the innermost pixels higher.
- bilinear: A filter using an average of a 2x2 environment of pixels.
- nearest: A filter using the value of nearby translated pixel values. Preserves hard edges.
- `upscale` (Boolean) Whether or not we should allow output images to render at sizes larger than input.
- `webp` (Boolean) Controls whether or not to default to WebP output when the client supports it. This is equivalent to adding "auto=webp" to all image optimizer requests.
- `webp_quality` (Number) The default quality to use with WebP output. This can be overridden with the second option in the "quality" URL parameter on specific image optimizer requests.


<a id="nestedblock--logging_bigquery"></a>
### Nested Schema for `logging_bigquery`

Expand Down
Loading

0 comments on commit 56868fd

Please sign in to comment.