Skip to content

Commit

Permalink
Added compression_type property to application delivery resource. (#301)
Browse files Browse the repository at this point in the history
* Added compression_type property to application delivery resource.

* File compression description update

---------

Co-authored-by: avishay.pelach <avishay.pelach@imperva.com>
  • Loading branch information
avishaypelach and AvishPel committed Mar 12, 2023
1 parent 28501e8 commit ca57dc2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
10 changes: 6 additions & 4 deletions incapsula/client_application_delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (
)

type Compression struct {
FileCompression bool `json:"file_compression"`
MinifyJs bool `json:"minify_js"`
MinifyCss bool `json:"minify_css"`
MinifyStaticHtml bool `json:"minify_static_html"`
FileCompression bool `json:"file_compression"`
CompressionType string `json:"compression_type"`
MinifyJs bool `json:"minify_js"`
MinifyCss bool `json:"minify_css"`
MinifyStaticHtml bool `json:"minify_static_html"`
}
type CompressionStr struct {
FileCompression string `json:"file_compression"`
CompressionType string `json:"compression_type"`
MinifyJs string `json:"minify_js"`
MinifyCss string `json:"minify_css"`
MinifyStaticHtml string `json:"minify_static_html"`
Expand Down
2 changes: 2 additions & 0 deletions incapsula/client_application_delivery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func TestUpdateApplicationDeliveryConfig(t *testing.T) {
{
"compression": {
"file_compression": true,
"compression_type": "GZIP",
"minify_js": true,
"minify_css": false,
"minify_static_html": true
Expand Down Expand Up @@ -315,6 +316,7 @@ func TestReadApplicationDeliveryConfig(t *testing.T) {
{
"compression": {
"file_compression": true,
"compression_type": "GZIP",
"minify_js": true,
"minify_css": false,
"minify_static_html": true
Expand Down
15 changes: 13 additions & 2 deletions incapsula/resource_application_delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package incapsula

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

const defaultPortTo = 80
Expand Down Expand Up @@ -42,10 +44,17 @@ func resourceApplicationDelivery() *schema.Resource {
// Optional Arguments
"file_compression": {
Type: schema.TypeBool,
Description: "When this option is enabled, any textual resource, such as Javascript, CSS and HTML, is compressed using Gzip as it is being transferred, and then unzipped within the browser. All modern browsers support this feature.",
Description: "When this option is enabled, files such as JavaScript, CSS and HTML are dynamically compressed using the selected format as they are transferred. They are automatically unzipped within the browser. If Brotli is not supported by the browser, files are automatically sent in Gzip.",
Optional: true,
Default: true,
},
"compression_type": {
Type: schema.TypeString,
Description: "Gzip (default). Brotli (recommended for more efficient compression)",
Optional: true,
Default: "GZIP",
ValidateFunc: validation.StringInSlice([]string{"GZIP", "BROTLI"}, false),
},
"minify_js": {
Type: schema.TypeBool,
Description: "Minify JavaScript. Minification removes characters that are not necessary for rendering the page, such as whitespace and comments. This makes the files smaller and therefore reduces their access time. Minification has no impact on the functionality of the Javascript, CSS, and HTML files.",
Expand Down Expand Up @@ -292,6 +301,7 @@ func resourceApplicationDeliveryRead(d *schema.ResourceData, m interface{}) erro
d.SetId(siteIdStr)

d.Set("file_compression", applicationDelivery.Compression.FileCompression)
d.Set("compression_type", applicationDelivery.Compression.CompressionType)
d.Set("minify_js", applicationDelivery.Compression.MinifyJs)
d.Set("minify_css", applicationDelivery.Compression.MinifyCss)
d.Set("minify_static_html", applicationDelivery.Compression.MinifyStaticHtml)
Expand Down Expand Up @@ -331,6 +341,7 @@ func resourceApplicationDeliveryUpdate(d *schema.ResourceData, m interface{}) er

compression := Compression{
FileCompression: d.Get("file_compression").(bool),
CompressionType: d.Get("compression_type").(string),
MinifyJs: d.Get("minify_js").(bool),
MinifyCss: d.Get("minify_css").(bool),
MinifyStaticHtml: d.Get("minify_static_html").(bool),
Expand Down
2 changes: 2 additions & 0 deletions incapsula/resource_application_delivery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestAccIncapsulaApplicationDelivery_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckApplicationDeliveryExists(applicationDeliveryResource),
resource.TestCheckResourceAttr(applicationDeliveryResource, "file_compression", "true"),
resource.TestCheckResourceAttr(applicationDeliveryResource, "compression_type", "GZIP"),
resource.TestCheckResourceAttr(applicationDeliveryResource, "minify_css", "true"), //value wasn't set by tf resurce. checking default value from server
resource.TestCheckResourceAttr(applicationDeliveryResource, "minify_js", "true"),
resource.TestCheckResourceAttr(applicationDeliveryResource, "minify_static_html", "false"),
Expand Down Expand Up @@ -105,6 +106,7 @@ resource "%s" "%s" {
site_id = incapsula_site.testacc-terraform-site.id
depends_on = ["%s"]
file_compression = true
compression_file = GZIP
compress_jpeg = true
minify_static_html = false
aggressive_compression = true
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/application_delivery.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Note that destroy action will return the configuration to the default values.
resource "incapsula_application_delivery" "example_application_delivery" {
site_id = incapsula_site.testacc-terraform-site.id
file_compression = true
compression_type = "GZIP"
minify_css = true
minify_js = true
minify_static_html = false
Expand Down Expand Up @@ -46,6 +47,7 @@ The following arguments are supported:

* `site_id` - (Required) Numeric identifier of the site to operate on.
* `file_compression` - (Optional) Compress JPEG images. Compression reduces download time by reducing the file size. Default: true
* `compression_type` - (Optional) BROTLI (recommended for more efficient compression). Default: GZIP
* `minify_js` - (Optional) Minify JavaScript. Minification removes characters that are not necessary for rendering the page, such as whitespace and comments. This makes the files smaller and therefore reduces their access time. Minification has no impact on the functionality of the Javascript, CSS, and HTML files. Default: true
* `minify_css` - (Optional) Content minification can applied only to cached Javascript, CSS and HTML content. Default: true.
* `minify_static_html` - (Optional) Minify static HTML. Default: true.
Expand Down

0 comments on commit ca57dc2

Please sign in to comment.