From 1755478166d13ef742eab6b8b627bfa82632e5f2 Mon Sep 17 00:00:00 2001 From: Jonathan Elkharrat Date: Thu, 6 Feb 2025 12:40:21 +0200 Subject: [PATCH 1/6] add resources --- incapsula/client_performance.go | 10 +- incapsula/provider.go | 1 + incapsula/resource_application_performance.go | 256 ++++++++++++++++++ .../docs/r/application_delivery.html.markdown | 1 - .../r/application_performance.html.markdown | 84 ++++++ 5 files changed, 346 insertions(+), 6 deletions(-) create mode 100644 incapsula/resource_application_performance.go create mode 100644 website/docs/r/application_performance.html.markdown diff --git a/incapsula/client_performance.go b/incapsula/client_performance.go index c63297d1..b059fb35 100644 --- a/incapsula/client_performance.go +++ b/incapsula/client_performance.go @@ -53,14 +53,14 @@ type PerformanceSettings struct { } // GetPerformanceSettings gets the site performance settings -func (c *Client) GetPerformanceSettings(siteID string) (*PerformanceSettings, int, error) { +func (c *Client) GetPerformanceSettings(siteID string) (*PerformanceSettings, error) { log.Printf("[INFO] Getting Incapsula Performance Settings for Site ID %s\n", siteID) // Post form to Incapsula reqURL := fmt.Sprintf("%s/sites/%s/settings/cache", c.config.BaseURLRev2, siteID) resp, err := c.DoJsonRequestWithHeaders(http.MethodGet, reqURL, nil, ReadSitePerformance) if err != nil { - return nil, 0, fmt.Errorf("Error from Incapsula service when reading Incap Performance Settings for Site ID %s: %s", siteID, err) + return nil, fmt.Errorf("Error from Incapsula service when reading Incap Performance Settings for Site ID %s: %s", siteID, err) } // Read the body @@ -72,17 +72,17 @@ func (c *Client) GetPerformanceSettings(siteID string) (*PerformanceSettings, in // Check the response code if resp.StatusCode != 200 { - return nil, resp.StatusCode, fmt.Errorf("Error status code %d from Incapsula service when reading Incap Performance Settings for Site ID %s: %s", resp.StatusCode, siteID, string(responseBody)) + return nil, fmt.Errorf("Error status code %d from Incapsula service when reading Incap Performance Settings for Site ID %s: %s", resp.StatusCode, siteID, string(responseBody)) } // Parse the JSON var performanceSettings PerformanceSettings err = json.Unmarshal([]byte(responseBody), &performanceSettings) if err != nil { - return nil, resp.StatusCode, fmt.Errorf("Error parsing Incap Performance Settings JSON response for Site ID %s: %s\nresponse: %s", siteID, err, string(responseBody)) + return nil, fmt.Errorf("Error parsing Incap Performance Settings JSON response for Site ID %s: %s\nresponse: %s", siteID, err, string(responseBody)) } - return &performanceSettings, resp.StatusCode, nil + return &performanceSettings, nil } // UpdatePerformanceSettings updates the site performance settings diff --git a/incapsula/provider.go b/incapsula/provider.go index c795a84f..ec5a569c 100644 --- a/incapsula/provider.go +++ b/incapsula/provider.go @@ -153,6 +153,7 @@ func Provider() *schema.Provider { "incapsula_abp_websites": resourceAbpWebsites(), "incapsula_delivery_rules_configuration": resourceDeliveryRulesConfiguration(), "incapsula_simplified_redirect_rules_configuration": resourceSimplifiedRedirectRulesConfiguration(), + "incapsula_application_performance": resourceApplicationPerformance(), }, } diff --git a/incapsula/resource_application_performance.go b/incapsula/resource_application_performance.go new file mode 100644 index 00000000..2671dac7 --- /dev/null +++ b/incapsula/resource_application_performance.go @@ -0,0 +1,256 @@ +package incapsula + +import ( + "fmt" + "log" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +func resourceApplicationPerformance() *schema.Resource { + return &schema.Resource{ + Create: resourceApplicationPerformanceUpdate, + Read: resourceApplicationPerformanceRead, + Update: resourceApplicationPerformanceUpdate, + Delete: resourceApplicationPerformanceDelete, + Importer: &schema.ResourceImporter{ + State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + siteID, err := strconv.Atoi(d.Id()) + if err != nil { + return nil, fmt.Errorf("failed to convert Site Id from import command for Application Performance resource, actual value: %s, expected numeric id", d.Id()) + } + + d.Set("site_id", siteID) + log.Printf("[DEBUG] Import Application Performance for Site ID %d", siteID) + return []*schema.ResourceData{d}, nil + }, + }, + + Schema: map[string]*schema.Schema{ + // Required Arguments + "site_id": { + Description: "Numeric identifier of the site to operate on. ", + Type: schema.TypeInt, + Required: true, + ForceNew: true, + }, + "client_comply_no_cache": { + Description: "Comply with No-Cache and Max-Age directives in client requests. By default, these cache directives are ignored. Resources are dynamically profiled and re-configured to optimize performance.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "client_enable_client_side_caching": { + Description: "Cache content on client browsers or applications. When not enabled, content is cached only on the Imperva proxies.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "client_send_age_header": { + Description: "Send Cache-Control: max-age and Age headers.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "key_comply_vary": { + Description: "Comply with Vary. Cache resources in accordance with the Vary response header.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "key_unite_naked_full_cache": { + Description: "Use the Same Cache for Full and Naked Domains. For example, use the same cached resource for www.example.com/a and example.com/a.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "mode_https": { + Description: "The resources that are cached over HTTPS, the general level applies. Options are `disabled`, `dont_include_html`, `include_html`, and `include_all_resources`.", + Type: schema.TypeString, + Computed: true, + Optional: true, + }, + "mode_level": { + Description: "Caching level. Options are `disabled`, `standard`, `smart`, and `all_resources`.", + Type: schema.TypeString, + Computed: true, + Optional: true, + }, + "mode_time": { + Description: "The time, in seconds, that you set for this option determines how often the cache is refreshed. Relevant for the `include_html` and `include_all_resources` levels only.", + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "response_cache_300x": { + Description: "When this option is checked Imperva will cache 301, 302, 303, 307, and 308 redirect response headers containing the target URI.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "response_cache_404_enabled": { + Description: "Whether or not to cache 404 responses.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "response_cache_404_time": { + Description: "The time in seconds to cache 404 responses.", + Type: schema.TypeInt, + Computed: true, + Optional: true, + ValidateFunc: validation.IntDivisibleBy(60), + }, + "response_cache_empty_responses": { + Description: "Cache responses that don’t have a message body.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "response_cache_http_10_responses": { + Description: "Cache HTTP 1.0 type responses that don’t include the Content-Length header or chunking.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "response_cache_response_header_mode": { + Description: "The working mode for caching response headers. Options are `all` and `custom`.", + Type: schema.TypeString, + Computed: true, + Optional: true, + }, + "response_cache_response_headers": { + Description: "An array of strings representing the response headers to be cached when working in `custom` mode. If empty, no response headers are cached.", + Type: schema.TypeList, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Computed: true, + Optional: true, + DiffSuppressFunc: suppressEquivalentStringDiffs, + }, + "response_cache_shield": { + Description: "Adds an intermediate cache between other Imperva PoPs and your origin servers to protect your servers from redundant requests.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "response_stale_content_mode": { + Description: "The working mode for serving stale content. Options are `disabled`, `adaptive`, and `custom`.", + Type: schema.TypeString, + Computed: true, + Optional: true, + }, + "response_stale_content_time": { + Description: "The time, in seconds, to serve stale content for when working in `custom` work mode.", + Type: schema.TypeInt, + Computed: true, + Optional: true, + }, + "response_tag_response_header": { + Description: "Tag the response according to the value of this header. Specify which origin response header contains the cache tags in your resources.", + Type: schema.TypeString, + Computed: true, + Optional: true, + }, + "ttl_prefer_last_modified": { + Description: "Prefer 'Last Modified' over eTag. When this option is checked, Imperva prefers using Last Modified values (if available) over eTag values (recommended on multi-server setups).", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + "ttl_use_shortest_caching": { + Description: "Use shortest caching duration in case of conflicts. By default, the longest duration is used in case of conflict between caching rules or modes. When this option is checked, Imperva uses the shortest duration in case of conflict.", + Type: schema.TypeBool, + Computed: true, + Optional: true, + }, + }, + } +} + +func resourceApplicationPerformanceUpdate(d *schema.ResourceData, m interface{}) error { + client := m.(*Client) + siteID := d.Get("site_id").(int) + siteIdStr := strconv.Itoa(siteID) + + performanceSettings := PerformanceSettings{} + performanceSettings.ClientSide.ComplyNoCache = d.Get("client_comply_no_cache").(bool) + performanceSettings.ClientSide.EnableClientSideCaching = d.Get("client_enable_client_side_caching").(bool) + performanceSettings.ClientSide.SendAgeHeader = d.Get("client_send_age_header").(bool) + performanceSettings.Key.ComplyVary = d.Get("key_comply_vary").(bool) + performanceSettings.Key.UniteNakedFullCache = d.Get("key_unite_naked_full_cache").(bool) + performanceSettings.Mode.HTTPS = d.Get("mode_https").(string) + performanceSettings.Mode.Level = d.Get("mode_level").(string) + performanceSettings.Mode.Time = d.Get("mode_time").(int) + performanceSettings.Response.Cache300X = d.Get("response_cache_300x").(bool) + performanceSettings.Response.Cache404.Enabled = d.Get("response_cache_404_enabled").(bool) + performanceSettings.Response.Cache404.Time = d.Get("response_cache_404_time").(int) + performanceSettings.Response.CacheEmptyResponses = d.Get("response_cache_empty_responses").(bool) + performanceSettings.Response.CacheHTTP10Responses = d.Get("response_cache_http_10_responses").(bool) + if !d.GetRawConfig().GetAttr("response_cache_response_header_mode").IsNull() { + performanceSettings.Response.CacheResponseHeader.Mode = d.Get("response_cache_response_header_mode").(string) + } + if !d.GetRawConfig().GetAttr("response_cache_response_headers").IsNull() { + performanceSettings.Response.CacheResponseHeader.Headers = d.Get("response_cache_response_headers").([]interface{}) + } + performanceSettings.Response.CacheShield = d.Get("response_cache_shield").(bool) + performanceSettings.Response.StaleContent.Mode = d.Get("response_stale_content_mode").(string) + performanceSettings.Response.StaleContent.Time = d.Get("response_stale_content_time").(int) + if !d.GetRawConfig().GetAttr("response_tag_response_header").IsNull() { + performanceSettings.Response.TagResponseHeader = d.Get("response_tag_response_header").(string) + } + performanceSettings.TTL.PreferLastModified = d.Get("ttl_prefer_last_modified").(bool) + performanceSettings.TTL.UseShortestCaching = d.Get("ttl_use_shortest_caching").(bool) + + _, err := client.UpdatePerformanceSettings(siteIdStr, &performanceSettings) + if err != nil { + log.Printf("[ERROR] Could not update Incapsula performance settings for site_id: %s %s\n", d.Id(), err) + return err + } + + return resourceApplicationPerformanceRead(d, m) +} + +func resourceApplicationPerformanceRead(d *schema.ResourceData, m interface{}) error { + client := m.(*Client) + siteID := d.Get("site_id").(int) + siteIdStr := strconv.Itoa(siteID) + + performanceSettingsResponse, err := client.GetPerformanceSettings(siteIdStr) + if err != nil { + log.Printf("[ERROR] Could not read Incapsula site peformance settings for site id: %d, %s\n", siteID, err) + return err + } + + d.Set("client_comply_no_cache", performanceSettingsResponse.ClientSide.ComplyNoCache) + d.Set("client_enable_client_side_caching", performanceSettingsResponse.ClientSide.EnableClientSideCaching) + d.Set("client_send_age_header", performanceSettingsResponse.ClientSide.SendAgeHeader) + d.Set("key_comply_vary", performanceSettingsResponse.Key.ComplyVary) + d.Set("key_unite_naked_full_cache", performanceSettingsResponse.Key.UniteNakedFullCache) + d.Set("mode_https", performanceSettingsResponse.Mode.HTTPS) + d.Set("mode_level", performanceSettingsResponse.Mode.Level) + d.Set("mode_time", performanceSettingsResponse.Mode.Time) + d.Set("response_cache_300x", performanceSettingsResponse.Response.Cache300X) + d.Set("response_cache_404_enabled", performanceSettingsResponse.Response.Cache404.Enabled) + d.Set("response_cache_404_time", performanceSettingsResponse.Response.Cache404.Time) + d.Set("response_cache_empty_responses", performanceSettingsResponse.Response.CacheEmptyResponses) + d.Set("response_cache_http_10_responses", performanceSettingsResponse.Response.CacheHTTP10Responses) + d.Set("response_cache_response_header_mode", performanceSettingsResponse.Response.CacheResponseHeader.Mode) + d.Set("response_cache_response_headers", performanceSettingsResponse.Response.CacheResponseHeader.Headers) + d.Set("response_cache_shield", performanceSettingsResponse.Response.CacheShield) + d.Set("response_stale_content_mode", performanceSettingsResponse.Response.StaleContent.Mode) + d.Set("response_stale_content_time", performanceSettingsResponse.Response.StaleContent.Time) + d.Set("response_tag_response_header", performanceSettingsResponse.Response.TagResponseHeader) + d.Set("ttl_prefer_last_modified", performanceSettingsResponse.TTL.PreferLastModified) + d.Set("ttl_use_shortest_caching", performanceSettingsResponse.TTL.UseShortestCaching) + + return nil +} + +func resourceApplicationPerformanceDelete(d *schema.ResourceData, m interface{}) error { + d.SetId("") + return nil +} diff --git a/website/docs/r/application_delivery.html.markdown b/website/docs/r/application_delivery.html.markdown index f2c02f98..de8c257a 100644 --- a/website/docs/r/application_delivery.html.markdown +++ b/website/docs/r/application_delivery.html.markdown @@ -9,7 +9,6 @@ description: |- # incapsula_application_delivery Configure delivery options to help you optimize your content delivery and improve performance by providing faster loading of your web pages. -Note that the destroy command returns the configuration to the default values. ## Example Usage diff --git a/website/docs/r/application_performance.html.markdown b/website/docs/r/application_performance.html.markdown new file mode 100644 index 00000000..c7d0907c --- /dev/null +++ b/website/docs/r/application_performance.html.markdown @@ -0,0 +1,84 @@ +--- +subcategory: "Provider Reference" +layout: "incapsula" +page_title: "incapsula_application_performance" +description: |- + Provides a Incapsula Application Performance resource. +--- + +# incapsula_application_performance + +Configure content caching for your website. + +## Example Usage + +### Basic Usage - Application Performance + +```hcl +resource "incapsula_application_performance" "example_application_performance" { + site_id = incapsula_site.testacc-terraform-site.id + client_comply_no_cache = true + client_enable_client_side_caching = true + client_send_age_header = true + key_comply_vary = true + key_unite_naked_full_cache = true + mode_https = "include_all_resources" + mode_level = "standard" + mode_time = 1000 + response_cache_300x = true + response_cache_404_enabled = true + response_cache_404_time = 60 + response_cache_empty_responses = true + response_cache_http_10_responses = true + response_cache_response_header_mode = "custom" + response_cache_response_headers = ["Access-Control-Allow-Origin", "Foo-Bar-Header"] + response_cache_shield = true + response_stale_content_mode = "custom" + response_stale_content_time = 1000 + response_tag_response_header = "Example-Tag-Value-Header" + ttl_prefer_last_modified = true + ttl_use_shortest_caching = true +} +``` + +## Argument Reference + +The following arguments are supported: + +* `client_comply_no_cache` - (Optional) Comply with No-Cache and Max-Age directives in client requests. By default, these cache directives are ignored. Resources are dynamically profiled and re-configured to optimize performance. +* `client_enable_client_side_caching` - (Optional) Cache content on client browsers or applications. When not enabled, content is cached only on the Imperva proxies. +* `client_send_age_header` - (Optional) Send Cache-Control: max-age and Age headers. +* `key_comply_vary` - (Optional) Comply with Vary. Cache resources in accordance with the Vary response header. +* `key_unite_naked_full_cache` - (Optional) Use the Same Cache for Full and Naked Domains. For example, use the same cached resource for www.example.com/a and example.com/a. +* `mode_https` - (Optional) The resources that are cached over HTTPS, the general level applies. Options are `disabled`, `dont_include_html`, `include_html`, and `include_all_resources`. +* `mode_level` - (Optional) Caching level. Options are `disabled`, `custom_cache_rules_only`, `standard`, `smart`, and `all_resources`. +* `mode_time` - (Optional) The time, in seconds, that you set for this option determines how often the cache is refreshed. Relevant for the `include_html` and `include_all_resources` levels only. +* `response_cache_300x` - (Optional) When this option is checked Imperva will cache 301, 302, 303, 307, and 308 redirect response headers containing the target URI. +* `response_cache_404_enabled` - (Optional) Whether or not to cache 404 responses. +* `response_cache_404_time` - (Optional) The time in seconds to cache 404 responses. Value should be divisible by + 60. +* `response_cache_empty_responses` - (Optional) Cache responses that don’t have a message body. +* `response_cache_http_10_responses` - (Optional) Cache HTTP 1.0 type responses that don’t include the Content-Length header or chunking. +* `response_cache_response_header_mode` - (Optional) The working mode for caching response headers. Options are `all` and `custom`. +* `response_cache_response_headers` - (Optional) An array of strings representing the response headers to be cached when working in `custom` mode. If empty, no response headers are cached. +For example: `["Access-Control-Allow-Origin","Access-Control-Allow-Methods"]`. +* `response_cache_shield` - (Optional) Adds an intermediate cache between other Imperva PoPs and your origin servers to protect your servers from redundant requests. +* `response_stale_content_mode` - (Optional) The working mode for serving stale content. Options are `disabled`, `adaptive`, and `custom`. +* `response_stale_content_time` - (Optional) The time, in seconds, to serve stale content for when working in `custom` work mode. +* `response_tag_response_header` - (Optional) Tag the response according to the value of this header. Specify which origin response header contains the cache tags in your resources. +* `ttl_prefer_last_modified` - (Optional) Prefer 'Last Modified' over eTag. When this option is checked, Imperva prefers using Last Modified values (if available) over eTag values (recommended on multi-server setups). +* `ttl_use_shortest_caching` - (Optional) Use shortest caching duration in case of conflicts. By default, the longest duration is used in case of conflict between caching rules or modes. When this option is checked, Imperva uses the shortest duration in case of conflict. + +## Attributes Reference + +The following attributes are exported: + +* `id` - Unique identifier in the API for the application performance configuration. The id is identical to Site id. + +## Import + +Application performance configuration can be imported using the `id`, e.g.: + +``` +$ terraform import incapsula_application_performance.example_application_performance 1234 +``` From 8ba3f3409dc50b803043cb40f7eb290c847d93ed Mon Sep 17 00:00:00 2001 From: Jonathan Elkharrat Date: Thu, 6 Feb 2025 14:04:37 +0200 Subject: [PATCH 2/6] add resources --- incapsula/resource_site.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/incapsula/resource_site.go b/incapsula/resource_site.go index 47636c77..ba1488e2 100644 --- a/incapsula/resource_site.go +++ b/incapsula/resource_site.go @@ -514,7 +514,7 @@ func resourceSiteRead(d *schema.ResourceData, m interface{}) error { d.Set("hash_salt", maskingResponse.HashSalt) // Get the performance settings for the site - performanceSettingsResponse, _, err := client.GetPerformanceSettings(d.Id()) + performanceSettingsResponse, err := client.GetPerformanceSettings(d.Id()) if err != nil { log.Printf("[ERROR] Could not read Incapsula site peformance settings for domain: %s and site id: %d, %s\n", domain, siteID, err) return err From dbc742381b6e033242921c6330510f54956320cd Mon Sep 17 00:00:00 2001 From: Jonathan Elkharrat Date: Sun, 9 Feb 2025 12:31:50 +0200 Subject: [PATCH 3/6] add resources --- incapsula/resource_application_performance.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/incapsula/resource_application_performance.go b/incapsula/resource_application_performance.go index 2671dac7..5eef5390 100644 --- a/incapsula/resource_application_performance.go +++ b/incapsula/resource_application_performance.go @@ -247,6 +247,8 @@ func resourceApplicationPerformanceRead(d *schema.ResourceData, m interface{}) e d.Set("ttl_prefer_last_modified", performanceSettingsResponse.TTL.PreferLastModified) d.Set("ttl_use_shortest_caching", performanceSettingsResponse.TTL.UseShortestCaching) + d.SetId(siteIdStr) + return nil } From 8528171a06b8cd899c60f2a5e61d2426013feafb Mon Sep 17 00:00:00 2001 From: Jonathan Elkharrat Date: Sun, 9 Feb 2025 22:36:38 +0200 Subject: [PATCH 4/6] add resources --- incapsula/client_performance_test.go | 8 +- .../resource_application_performance_test.go | 183 ++++++++++++++++++ 2 files changed, 187 insertions(+), 4 deletions(-) create mode 100644 incapsula/resource_application_performance_test.go diff --git a/incapsula/client_performance_test.go b/incapsula/client_performance_test.go index 67a55816..9de92625 100644 --- a/incapsula/client_performance_test.go +++ b/incapsula/client_performance_test.go @@ -17,7 +17,7 @@ func TestClientGetPerformanceSettingsBadConnection(t *testing.T) { config := &Config{APIID: "foo", APIKey: "bar", BaseURL: "badness.incapsula.com"} client := &Client{config: config, httpClient: &http.Client{Timeout: time.Millisecond * 1}} siteID := "123" - performanceSettings, _, err := client.GetPerformanceSettings(siteID) + performanceSettings, err := client.GetPerformanceSettings(siteID) if err == nil { t.Errorf("Should have received an error") } @@ -47,7 +47,7 @@ func TestClientGetPerformanceSettingsBadJSON(t *testing.T) { config := &Config{APIID: apiID, APIKey: apiKey, BaseURL: server.URL, BaseURLRev2: server.URL, BaseURLAPI: server.URL} client := &Client{config: config, httpClient: &http.Client{}} - performanceSettings, _, err := client.GetPerformanceSettings(siteID) + performanceSettings, err := client.GetPerformanceSettings(siteID) if err == nil { t.Errorf("Should have received an error") } @@ -78,7 +78,7 @@ func TestClientGetPerformanceSettingsInvalidSite(t *testing.T) { config := &Config{APIID: apiID, APIKey: apiKey, BaseURL: server.URL, BaseURLRev2: server.URL, BaseURLAPI: server.URL} client := &Client{config: config, httpClient: &http.Client{}} - performanceSettings, _, err := client.GetPerformanceSettings(siteID) + performanceSettings, err := client.GetPerformanceSettings(siteID) if err == nil { t.Errorf("Should have received an error") } @@ -108,7 +108,7 @@ func TestClientGetPerformanceSettingsValidSite(t *testing.T) { config := &Config{APIID: apiID, APIKey: apiKey, BaseURL: server.URL, BaseURLRev2: server.URL, BaseURLAPI: server.URL} client := &Client{config: config, httpClient: &http.Client{}} - performanceSettings, _, err := client.GetPerformanceSettings(siteID) + performanceSettings, err := client.GetPerformanceSettings(siteID) if err != nil { t.Errorf("Should not have received an error") } diff --git a/incapsula/resource_application_performance_test.go b/incapsula/resource_application_performance_test.go new file mode 100644 index 00000000..1919da3d --- /dev/null +++ b/incapsula/resource_application_performance_test.go @@ -0,0 +1,183 @@ +package incapsula + +import ( + "fmt" + "log" + "strconv" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +const applicationPerformanceResourceName = "incapsula_application_performance" +const applicationPerformanceResource = applicationPerformanceResourceName + "." + applicationPerformanceName +const applicationPerformanceName = "testacc-terraform-application_performance" + +func TestAccIncapsulaApplicationPerformance_basic(t *testing.T) { + var domainName = GenerateTestDomain(t) + log.Printf("======================== BEGIN TEST ========================") + log.Printf("[DEBUG] Running test resource_application_performance_test.TestAccIncapsulaApplicationPerformance_basic") + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAllCachingEnabled(domainName), + Check: resource.ComposeTestCheckFunc( + testCheckApplicationPerformanceExists(applicationPerformanceResource), + resource.TestCheckResourceAttr(applicationPerformanceResource, "client_comply_no_cache", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "client_enable_client_side_caching", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "client_send_age_header", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "key_comply_vary", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "key_unite_naked_full_cache", "true"), + + resource.TestCheckResourceAttr(applicationPerformanceResource, "mode_level", "all_resources"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "mode_https", "disabled"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "mode_time", "120"), + + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_300x", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_404_enabled", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_404_time", "120"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_empty_responses", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_http_10_responses", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_response_header_mode", "custom"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_response_headers.#", "1"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_response_headers.0", "cache"), + + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_stale_content_mode", "custom"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_stale_content_time", "120"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_tag_response_header", "cache"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "ttl_prefer_last_modified", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "ttl_use_shortest_caching", "true"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_shield", "false"), + ), + }, + { + Config: testAllCachingDisabled(domainName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(applicationPerformanceResource, "client_comply_no_cache", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "client_enable_client_side_caching", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "client_send_age_header", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "key_comply_vary", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "key_unite_naked_full_cache", "false"), + + resource.TestCheckResourceAttr(applicationPerformanceResource, "mode_level", "disabled"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "mode_https", "disabled"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "mode_time", "0"), + + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_300x", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_404_enabled", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_404_time", "0"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_empty_responses", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_http_10_responses", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_response_header_mode", "disabled"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_response_headers.#", "0"), + + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_stale_content_mode", "disabled"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_stale_content_time", "0"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_tag_response_header", ""), + resource.TestCheckResourceAttr(applicationPerformanceResource, "ttl_prefer_last_modified", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "ttl_use_shortest_caching", "false"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_shield", "false"), + ), + }, + { + ResourceName: applicationPerformanceResource, + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: testAccStateApplicationPerformanceID, + }, + }, + }) +} + +func testCheckApplicationPerformanceExists(name string) resource.TestCheckFunc { + return func(state *terraform.State) error { + _, ok := state.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Incapsula Application Performance resource not found: %s", name) + } + + client := testAccProvider.Meta().(*Client) + _, err2 := client.GetPerformanceSettings(siteId) + if err2 != nil { + fmt.Errorf("Incapsula Application Performance doesn't exist") + } + + return nil + } +} + +func testAccStateApplicationPerformanceID(s *terraform.State) (string, error) { + for _, rs := range s.RootModule().Resources { + if rs.Type != applicationPerformanceResourceName { + continue + } + + siteID, err := strconv.Atoi(rs.Primary.Attributes["site_id"]) + + if err != nil { + return "", fmt.Errorf("Error parsing ID %v to int in Application Delivery resource test", rs.Primary.Attributes["site_id"]) + } + return fmt.Sprintf("%d", siteID), nil + } + return "", fmt.Errorf("Error finding site_id argument in Application Delivery resource test") +} + +func testAllCachingEnabled(domainName string) string { + return testCheckIncapsulaSiteV3ConfigBasic(domainName, "CLOUD_WAF") + fmt.Sprintf(` +resource "%s" "%s" { + site_id = incapsula_site_v3.test-terraform-site-v3.id + depends_on = ["incapsula_site_v3.test-terraform-site-v3"] + client_comply_no_cache = true + client_enable_client_side_caching = true + client_send_age_header = true + key_comply_vary = true + key_unite_naked_full_cache = true + mode_level = "all_resources" + mode_https = "disabled" + mode_time = 120 + response_cache_300x = true + response_cache_404_enabled = true + response_cache_404_time = 120 + response_cache_empty_responses = true + response_cache_http_10_responses = true + response_cache_response_header_mode = "custom" + response_cache_response_headers = ["cache"] + response_stale_content_mode = "custom" + response_stale_content_time = 120 + ttl_prefer_last_modified = true + ttl_use_shortest_caching = true +}`, + applicationPerformanceResourceName, applicationPerformanceName, + ) +} + +func testAllCachingDisabled(domainName string) string { + return testCheckIncapsulaSiteV3ConfigBasic(domainName, "CLOUD_WAF") + fmt.Sprintf(` +resource "%s" "%s" { + site_id = incapsula_site_v3.test-terraform-site-v3.id + depends_on = ["incapsula_site_v3.test-terraform-site-v3"] + client_comply_no_cache = false + client_enable_client_side_caching = false + client_send_age_header = false + key_comply_vary = false + key_unite_naked_full_cache = false + mode_level = "disabled" + mode_https = "disabled" + mode_time = 0 + response_cache_300x = false + response_cache_404_enabled = false + response_cache_404_time = 0 + response_cache_empty_responses = false + response_cache_http_10_responses = false + response_cache_response_header_mode = "disabled" + response_stale_content_mode = "disabled" + response_stale_content_time = 0 + ttl_prefer_last_modified = false + ttl_use_shortest_caching = false +}`, + applicationPerformanceResourceName, applicationPerformanceName, + ) +} From 00740d71b7dbf1c742468122187220d1e770fcc0 Mon Sep 17 00:00:00 2001 From: Jonathan Elkharrat Date: Sun, 9 Feb 2025 23:09:19 +0200 Subject: [PATCH 5/6] fix typo --- incapsula/resource_application_performance_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/incapsula/resource_application_performance_test.go b/incapsula/resource_application_performance_test.go index 1919da3d..4d51a667 100644 --- a/incapsula/resource_application_performance_test.go +++ b/incapsula/resource_application_performance_test.go @@ -118,11 +118,11 @@ func testAccStateApplicationPerformanceID(s *terraform.State) (string, error) { siteID, err := strconv.Atoi(rs.Primary.Attributes["site_id"]) if err != nil { - return "", fmt.Errorf("Error parsing ID %v to int in Application Delivery resource test", rs.Primary.Attributes["site_id"]) + return "", fmt.Errorf("Error parsing ID %v to int in Application Performance resource test", rs.Primary.Attributes["site_id"]) } return fmt.Sprintf("%d", siteID), nil } - return "", fmt.Errorf("Error finding site_id argument in Application Delivery resource test") + return "", fmt.Errorf("Error finding site_id argument in Application Performance resource test") } func testAllCachingEnabled(domainName string) string { From 211848f811370d4e7cd1c9a3d7f6f6c64e3fa2bb Mon Sep 17 00:00:00 2001 From: Jonathan Elkharrat Date: Mon, 17 Feb 2025 13:28:03 +0200 Subject: [PATCH 6/6] Add defaults to new resource --- incapsula/client_performance.go | 4 +- incapsula/resource_application_performance.go | 79 +++++++++---------- .../resource_application_performance_test.go | 7 +- .../r/application_performance.html.markdown | 32 ++++---- website/docs/r/site.html.markdown | 2 +- 5 files changed, 62 insertions(+), 62 deletions(-) diff --git a/incapsula/client_performance.go b/incapsula/client_performance.go index b059fb35..bcf0eddb 100644 --- a/incapsula/client_performance.go +++ b/incapsula/client_performance.go @@ -30,9 +30,9 @@ type PerformanceSettings struct { CacheShield bool `json:"cache_shield"` CacheResponseHeader struct { Mode string `json:"mode,omitempty"` - Headers []interface{} `json:"headers,omitempty"` + Headers []interface{} `json:"headers"` } `json:"cache_response_header,omitempty"` - TagResponseHeader string `json:"tag_response_header,omitempty"` + TagResponseHeader string `json:"tag_response_header"` CacheEmptyResponses bool `json:"cache_empty_responses"` Cache300X bool `json:"cache_300x"` CacheHTTP10Responses bool `json:"cache_http_10_responses"` diff --git a/incapsula/resource_application_performance.go b/incapsula/resource_application_performance.go index 5eef5390..570ab241 100644 --- a/incapsula/resource_application_performance.go +++ b/incapsula/resource_application_performance.go @@ -39,44 +39,46 @@ func resourceApplicationPerformance() *schema.Resource { "client_comply_no_cache": { Description: "Comply with No-Cache and Max-Age directives in client requests. By default, these cache directives are ignored. Resources are dynamically profiled and re-configured to optimize performance.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "client_enable_client_side_caching": { Description: "Cache content on client browsers or applications. When not enabled, content is cached only on the Imperva proxies.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "client_send_age_header": { Description: "Send Cache-Control: max-age and Age headers.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "key_comply_vary": { Description: "Comply with Vary. Cache resources in accordance with the Vary response header.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "key_unite_naked_full_cache": { Description: "Use the Same Cache for Full and Naked Domains. For example, use the same cached resource for www.example.com/a and example.com/a.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "mode_https": { - Description: "The resources that are cached over HTTPS, the general level applies. Options are `disabled`, `dont_include_html`, `include_html`, and `include_all_resources`.", - Type: schema.TypeString, - Computed: true, - Optional: true, + Description: "The resources that are cached over HTTPS, the general level applies. Options are `disabled`, `dont_include_html`, `include_html`, and `include_all_resources`.", + Type: schema.TypeString, + Optional: true, + Default: "disabled", + ValidateFunc: validation.StringInSlice([]string{"disabled", "dont_include_html", "include_html", "include_all_resources"}, false), }, "mode_level": { - Description: "Caching level. Options are `disabled`, `standard`, `smart`, and `all_resources`.", - Type: schema.TypeString, - Computed: true, - Optional: true, + Description: "Caching level. Options are `disabled`, `standard`, `smart`, and `all_resources`.", + Type: schema.TypeString, + Optional: true, + Default: "smart", + ValidateFunc: validation.StringInSlice([]string{"disabled", "standard", "smart", "all_resources"}, false), }, "mode_time": { Description: "The time, in seconds, that you set for this option determines how often the cache is refreshed. Relevant for the `include_html` and `include_all_resources` levels only.", @@ -87,14 +89,14 @@ func resourceApplicationPerformance() *schema.Resource { "response_cache_300x": { Description: "When this option is checked Imperva will cache 301, 302, 303, 307, and 308 redirect response headers containing the target URI.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "response_cache_404_enabled": { Description: "Whether or not to cache 404 responses.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "response_cache_404_time": { Description: "The time in seconds to cache 404 responses.", @@ -106,20 +108,21 @@ func resourceApplicationPerformance() *schema.Resource { "response_cache_empty_responses": { Description: "Cache responses that don’t have a message body.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "response_cache_http_10_responses": { Description: "Cache HTTP 1.0 type responses that don’t include the Content-Length header or chunking.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "response_cache_response_header_mode": { - Description: "The working mode for caching response headers. Options are `all` and `custom`.", - Type: schema.TypeString, - Computed: true, - Optional: true, + Description: "The working mode for caching response headers. Options are `all`, `custom` and `disabled`.", + Type: schema.TypeString, + Optional: true, + Default: "disabled", + ValidateFunc: validation.StringInSlice([]string{"disabled", "custom", "all"}, false), }, "response_cache_response_headers": { Description: "An array of strings representing the response headers to be cached when working in `custom` mode. If empty, no response headers are cached.", @@ -127,21 +130,24 @@ func resourceApplicationPerformance() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, }, - Computed: true, - Optional: true, + Optional: true, + DefaultFunc: func() (interface{}, error) { + return []interface{}{}, nil + }, DiffSuppressFunc: suppressEquivalentStringDiffs, }, "response_cache_shield": { Description: "Adds an intermediate cache between other Imperva PoPs and your origin servers to protect your servers from redundant requests.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "response_stale_content_mode": { - Description: "The working mode for serving stale content. Options are `disabled`, `adaptive`, and `custom`.", - Type: schema.TypeString, - Computed: true, - Optional: true, + Description: "The working mode for serving stale content. Options are `disabled`, `adaptive`, and `custom`.", + Type: schema.TypeString, + Optional: true, + Default: "disabled", + ValidateFunc: validation.StringInSlice([]string{"disabled", "adaptive", "custom"}, false), }, "response_stale_content_time": { Description: "The time, in seconds, to serve stale content for when working in `custom` work mode.", @@ -152,20 +158,19 @@ func resourceApplicationPerformance() *schema.Resource { "response_tag_response_header": { Description: "Tag the response according to the value of this header. Specify which origin response header contains the cache tags in your resources.", Type: schema.TypeString, - Computed: true, Optional: true, }, "ttl_prefer_last_modified": { Description: "Prefer 'Last Modified' over eTag. When this option is checked, Imperva prefers using Last Modified values (if available) over eTag values (recommended on multi-server setups).", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, "ttl_use_shortest_caching": { Description: "Use shortest caching duration in case of conflicts. By default, the longest duration is used in case of conflict between caching rules or modes. When this option is checked, Imperva uses the shortest duration in case of conflict.", Type: schema.TypeBool, - Computed: true, Optional: true, + Default: false, }, }, } @@ -190,18 +195,12 @@ func resourceApplicationPerformanceUpdate(d *schema.ResourceData, m interface{}) performanceSettings.Response.Cache404.Time = d.Get("response_cache_404_time").(int) performanceSettings.Response.CacheEmptyResponses = d.Get("response_cache_empty_responses").(bool) performanceSettings.Response.CacheHTTP10Responses = d.Get("response_cache_http_10_responses").(bool) - if !d.GetRawConfig().GetAttr("response_cache_response_header_mode").IsNull() { - performanceSettings.Response.CacheResponseHeader.Mode = d.Get("response_cache_response_header_mode").(string) - } - if !d.GetRawConfig().GetAttr("response_cache_response_headers").IsNull() { - performanceSettings.Response.CacheResponseHeader.Headers = d.Get("response_cache_response_headers").([]interface{}) - } + performanceSettings.Response.CacheResponseHeader.Mode = d.Get("response_cache_response_header_mode").(string) + performanceSettings.Response.CacheResponseHeader.Headers = d.Get("response_cache_response_headers").([]interface{}) performanceSettings.Response.CacheShield = d.Get("response_cache_shield").(bool) performanceSettings.Response.StaleContent.Mode = d.Get("response_stale_content_mode").(string) performanceSettings.Response.StaleContent.Time = d.Get("response_stale_content_time").(int) - if !d.GetRawConfig().GetAttr("response_tag_response_header").IsNull() { - performanceSettings.Response.TagResponseHeader = d.Get("response_tag_response_header").(string) - } + performanceSettings.Response.TagResponseHeader = d.Get("response_tag_response_header").(string) performanceSettings.TTL.PreferLastModified = d.Get("ttl_prefer_last_modified").(bool) performanceSettings.TTL.UseShortestCaching = d.Get("ttl_use_shortest_caching").(bool) diff --git a/incapsula/resource_application_performance_test.go b/incapsula/resource_application_performance_test.go index 4d51a667..10441dc6 100644 --- a/incapsula/resource_application_performance_test.go +++ b/incapsula/resource_application_performance_test.go @@ -43,11 +43,11 @@ func TestAccIncapsulaApplicationPerformance_basic(t *testing.T) { resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_http_10_responses", "true"), resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_response_header_mode", "custom"), resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_response_headers.#", "1"), - resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_response_headers.0", "cache"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_response_headers.0", "cache2"), resource.TestCheckResourceAttr(applicationPerformanceResource, "response_stale_content_mode", "custom"), resource.TestCheckResourceAttr(applicationPerformanceResource, "response_stale_content_time", "120"), - resource.TestCheckResourceAttr(applicationPerformanceResource, "response_tag_response_header", "cache"), + resource.TestCheckResourceAttr(applicationPerformanceResource, "response_tag_response_header", "myHeader3"), resource.TestCheckResourceAttr(applicationPerformanceResource, "ttl_prefer_last_modified", "true"), resource.TestCheckResourceAttr(applicationPerformanceResource, "ttl_use_shortest_caching", "true"), resource.TestCheckResourceAttr(applicationPerformanceResource, "response_cache_shield", "false"), @@ -144,8 +144,9 @@ resource "%s" "%s" { response_cache_empty_responses = true response_cache_http_10_responses = true response_cache_response_header_mode = "custom" - response_cache_response_headers = ["cache"] + response_cache_response_headers = ["cache2"] response_stale_content_mode = "custom" + response_tag_response_header = "myHeader3" response_stale_content_time = 120 ttl_prefer_last_modified = true ttl_use_shortest_caching = true diff --git a/website/docs/r/application_performance.html.markdown b/website/docs/r/application_performance.html.markdown index c7d0907c..042394fb 100644 --- a/website/docs/r/application_performance.html.markdown +++ b/website/docs/r/application_performance.html.markdown @@ -45,29 +45,29 @@ resource "incapsula_application_performance" "example_application_performance" { The following arguments are supported: -* `client_comply_no_cache` - (Optional) Comply with No-Cache and Max-Age directives in client requests. By default, these cache directives are ignored. Resources are dynamically profiled and re-configured to optimize performance. -* `client_enable_client_side_caching` - (Optional) Cache content on client browsers or applications. When not enabled, content is cached only on the Imperva proxies. -* `client_send_age_header` - (Optional) Send Cache-Control: max-age and Age headers. -* `key_comply_vary` - (Optional) Comply with Vary. Cache resources in accordance with the Vary response header. -* `key_unite_naked_full_cache` - (Optional) Use the Same Cache for Full and Naked Domains. For example, use the same cached resource for www.example.com/a and example.com/a. -* `mode_https` - (Optional) The resources that are cached over HTTPS, the general level applies. Options are `disabled`, `dont_include_html`, `include_html`, and `include_all_resources`. -* `mode_level` - (Optional) Caching level. Options are `disabled`, `custom_cache_rules_only`, `standard`, `smart`, and `all_resources`. +* `client_comply_no_cache` - (Optional) Comply with No-Cache and Max-Age directives in client requests. By default, these cache directives are ignored. Resources are dynamically profiled and re-configured to optimize performance. **Default:** false +* `client_enable_client_side_caching` - (Optional) Cache content on client browsers or applications. When not enabled, content is cached only on the Imperva proxies. **Default:** false +* `client_send_age_header` - (Optional) Send Cache-Control: max-age and Age headers. **Default:** false +* `key_comply_vary` - (Optional) Comply with Vary. Cache resources in accordance with the Vary response header. **Default:** false +* `key_unite_naked_full_cache` - (Optional) Use the Same Cache for Full and Naked Domains. For example, use the same cached resource for www.example.com/a and example.com/a. **Default:** false +* `mode_https` - (Optional) The resources that are cached over HTTPS, the general level applies. Options are `disabled`, `dont_include_html`, `include_html`, and `include_all_resources`. **Default:** `disabled` +* `mode_level` - (Optional) Caching level. Options are `disabled`, `custom_cache_rules_only`, `standard`, `smart`, and `all_resources`. **Default:** smart * `mode_time` - (Optional) The time, in seconds, that you set for this option determines how often the cache is refreshed. Relevant for the `include_html` and `include_all_resources` levels only. -* `response_cache_300x` - (Optional) When this option is checked Imperva will cache 301, 302, 303, 307, and 308 redirect response headers containing the target URI. -* `response_cache_404_enabled` - (Optional) Whether or not to cache 404 responses. +* `response_cache_300x` - (Optional) When this option is checked Imperva will cache 301, 302, 303, 307, and 308 redirect response headers containing the target URI. **Default:** false +* `response_cache_404_enabled` - (Optional) Whether or not to cache 404 responses. **Default:** false * `response_cache_404_time` - (Optional) The time in seconds to cache 404 responses. Value should be divisible by 60. -* `response_cache_empty_responses` - (Optional) Cache responses that don’t have a message body. -* `response_cache_http_10_responses` - (Optional) Cache HTTP 1.0 type responses that don’t include the Content-Length header or chunking. -* `response_cache_response_header_mode` - (Optional) The working mode for caching response headers. Options are `all` and `custom`. +* `response_cache_empty_responses` - (Optional) Cache responses that don’t have a message body. **Default:** false +* `response_cache_http_10_responses` - (Optional) Cache HTTP 1.0 type responses that don’t include the Content-Length header or chunking. **Default:** false +* `response_cache_response_header_mode` - (Optional) The working mode for caching response headers. Options are `all`, `custom` and `disabled`. **Default:** `disabled` * `response_cache_response_headers` - (Optional) An array of strings representing the response headers to be cached when working in `custom` mode. If empty, no response headers are cached. For example: `["Access-Control-Allow-Origin","Access-Control-Allow-Methods"]`. -* `response_cache_shield` - (Optional) Adds an intermediate cache between other Imperva PoPs and your origin servers to protect your servers from redundant requests. -* `response_stale_content_mode` - (Optional) The working mode for serving stale content. Options are `disabled`, `adaptive`, and `custom`. +* `response_cache_shield` - (Optional) Adds an intermediate cache between other Imperva PoPs and your origin servers to protect your servers from redundant requests. **Default:** false +* `response_stale_content_mode` - (Optional) The working mode for serving stale content. Options are `disabled`, `adaptive`, and `custom`. **Default:** `disabled` * `response_stale_content_time` - (Optional) The time, in seconds, to serve stale content for when working in `custom` work mode. * `response_tag_response_header` - (Optional) Tag the response according to the value of this header. Specify which origin response header contains the cache tags in your resources. -* `ttl_prefer_last_modified` - (Optional) Prefer 'Last Modified' over eTag. When this option is checked, Imperva prefers using Last Modified values (if available) over eTag values (recommended on multi-server setups). -* `ttl_use_shortest_caching` - (Optional) Use shortest caching duration in case of conflicts. By default, the longest duration is used in case of conflict between caching rules or modes. When this option is checked, Imperva uses the shortest duration in case of conflict. +* `ttl_prefer_last_modified` - (Optional) Prefer 'Last Modified' over eTag. When this option is checked, Imperva prefers using Last Modified values (if available) over eTag values (recommended on multi-server setups). **Default:** false +* `ttl_use_shortest_caching` - (Optional) Use shortest caching duration in case of conflicts. By default, the longest duration is used in case of conflict between caching rules or modes. When this option is checked, Imperva uses the shortest duration in case of conflict. **Default:** false ## Attributes Reference diff --git a/website/docs/r/site.html.markdown b/website/docs/r/site.html.markdown index 501f7359..0076a53b 100644 --- a/website/docs/r/site.html.markdown +++ b/website/docs/r/site.html.markdown @@ -93,7 +93,7 @@ The following arguments are supported: 60. * `perf_response_cache_empty_responses` - (Optional) Cache responses that don’t have a message body. * `perf_response_cache_http_10_responses` - (Optional) Cache HTTP 1.0 type responses that don’t include the Content-Length header or chunking. -* `perf_response_cache_response_header_mode` - (Optional) The working mode for caching response headers. Options are `all` and `custom`. +* `perf_response_cache_response_header_mode` - (Optional) The working mode for caching response headers. Options are `all`, `custom` and `disabled`. * `perf_response_cache_response_headers` - (Optional) An array of strings representing the response headers to be cached when working in `custom` mode. If empty, no response headers are cached. For example: `["Access-Control-Allow-Origin","Access-Control-Allow-Methods"]`. * `perf_response_cache_shield` - (Optional) Adds an intermediate cache between other Imperva PoPs and your origin servers to protect your servers from redundant requests.