Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/data-sources/cdn_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ Optional:
Read-Only:

- `backend` (Attributes) The configured backend for the distribution (see [below for nested schema](#nestedatt--config--backend))
- `blocked_ips` (List of String) Restricts access to your content by specifying a list of blocked IPv4 addresses. This feature enhances security and privacy by preventing these addresses from accessing your distribution.
- `default_cache_duration` (String) Sets the default cache duration for the distribution. The default cache duration is applied when a 'Cache-Control' header is not presented in the origin's response. We use ISO8601 duration format for cache duration (e.g. P1DT2H30M)
- `forward_host_header` (Boolean) Enable this allows the 'Host' header to be passed through to the origin.
- `monthly_limit_bytes` (Number) Sets the monthly limit of bandwidth in bytes that the pullzone is allowed to use.
- `optimizer` (Attributes) Configuration for the Image Optimizer. This is a paid feature that automatically optimizes images to reduce their file size for faster delivery, leading to improved website performance and a better user experience. (see [below for nested schema](#nestedatt--config--optimizer))
- `redirects` (Attributes) A wrapper for a list of redirect rules that allows for redirect settings on a distribution (see [below for nested schema](#nestedatt--config--redirects))
- `regions` (List of String) The configured regions where content will be hosted
Expand Down
11 changes: 11 additions & 0 deletions docs/resources/cdn_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ resource "stackit_cdn_distribution" "example_distribution" {
}
regions = ["EU", "US", "ASIA", "AF", "SA"]
blocked_countries = ["DE", "AT", "CH"]
blocked_ips = ["1.1.1.1"]

default_cache_duration = "P1DT2H30M"
monthly_limit_bytes = 1048576

optimizer = {
enabled = true
Expand All @@ -52,6 +56,10 @@ resource "stackit_cdn_distribution" "example_bucket_distribution" {
}
regions = ["EU", "US"]
blocked_countries = ["CN", "RU"]
blocked_ips = ["1.1.1.1"]

default_cache_duration = "P1DT2H30M"
monthly_limit_bytes = 1048576

optimizer = {
enabled = false
Expand Down Expand Up @@ -147,7 +155,10 @@ Required:
Optional:

- `blocked_countries` (List of String) The configured countries where distribution of content is blocked
- `blocked_ips` (List of String) Restricts access to your content by specifying a list of blocked IPv4 addresses. This feature enhances security and privacy by preventing these addresses from accessing your distribution.
- `default_cache_duration` (String) Sets the default cache duration for the distribution. The default cache duration is applied when a 'Cache-Control' header is not presented in the origin's response. We use ISO8601 duration format for cache duration (e.g. P1DT2H30M)
- `forward_host_header` (Boolean) Enable this allows the 'Host' header to be passed through to the origin.
- `monthly_limit_bytes` (Number) Sets the monthly limit of bandwidth in bytes that the pullzone is allowed to use.
- `optimizer` (Attributes) Configuration for the Image Optimizer. This is a paid feature that automatically optimizes images to reduce their file size for faster delivery, leading to improved website performance and a better user experience. (see [below for nested schema](#nestedatt--config--optimizer))
- `redirects` (Attributes) A wrapper for a list of redirect rules that allows for redirect settings on a distribution (see [below for nested schema](#nestedatt--config--redirects))
- `strip_response_cookies` (Boolean) Enable this to prevent origin-level cookies from being forwarded to the end user.
Expand Down
8 changes: 8 additions & 0 deletions examples/resources/stackit_cdn_distribution/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ resource "stackit_cdn_distribution" "example_distribution" {
}
regions = ["EU", "US", "ASIA", "AF", "SA"]
blocked_countries = ["DE", "AT", "CH"]
blocked_ips = ["1.1.1.1"]

default_cache_duration = "P1DT2H30M"
monthly_limit_bytes = 1048576

optimizer = {
enabled = true
Expand All @@ -34,6 +38,10 @@ resource "stackit_cdn_distribution" "example_bucket_distribution" {
}
regions = ["EU", "US"]
blocked_countries = ["CN", "RU"]
blocked_ips = ["1.1.1.1"]

default_cache_duration = "P1DT2H30M"
monthly_limit_bytes = 1048576

optimizer = {
enabled = false
Expand Down
107 changes: 75 additions & 32 deletions stackit/internal/services/cdn/cdn_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,39 +107,59 @@ func wafConfigVariable(mode, wafType, paranoiaLevel, allowedMethod, allowedConte
}

var testConfigVarsHttp = config.Variables{
"project_id": config.StringVariable(testutil.ProjectId),
"name": config.StringVariable(httpTestName),
"regions": config.ListVariable(config.StringVariable("EU"), config.StringVariable("US")),
"dns_zone_name": config.StringVariable("acc_cdn_test_zone"),
"dns_name": config.StringVariable(dnsNameHttp),
"dns_record_name": config.StringVariable(dnsRecordNameHttp),
"optimizer": config.BoolVariable(true),
"backend_http_type": config.StringVariable("http"),
"blocked_countries": config.ListVariable(config.StringVariable("CU")),
"backend_origin_url": config.StringVariable("https://test-backend-1.cdn-dev.runs.onstackit.cloud"),
"geofencing_list": config.ListVariable(config.StringVariable("DE")),
"origin_request_headers_name": config.StringVariable("X-Custom-Header"),
"origin_request_headers_value": config.StringVariable("x-custom-value"),
"certificate": config.StringVariable(string(cert)),
"private_key": config.StringVariable(string(key)),
"redirect_target_url": config.StringVariable("https://example.com"),
"redirect_status_code": config.IntegerVariable(301),
"redirect_matcher_values": config.ListVariable(config.StringVariable("/shop/*")),
"redirect_rule_description": config.StringVariable("Acc test redirect"),
"redirect_rule_enabled": config.BoolVariable(true),
"redirect_rule_match_condition": config.StringVariable("ANY"),
"redirect_matcher_condition": config.StringVariable("ANY"),
"waf": wafConfigVariable("ENABLED", "FREE", "L2", "GET", "application/json", "HTTP/1.0", wafRule1, wafRule2, wafRule3),
"tls_enable_tls_10": config.BoolVariable(true),
"tls_enable_tls_11": config.BoolVariable(true),
"strip_response_cookies": config.BoolVariable(false),
"forward_host_header": config.BoolVariable(true),
"project_id": config.StringVariable(testutil.ProjectId),
"name": config.StringVariable(httpTestName),
"regions": config.ListVariable(config.StringVariable("EU"), config.StringVariable("US")),
"dns_zone_name": config.StringVariable("acc_cdn_test_zone"),
"dns_name": config.StringVariable(dnsNameHttp),
"dns_record_name": config.StringVariable(dnsRecordNameHttp),
"optimizer": config.BoolVariable(true),
"backend_http_type": config.StringVariable("http"),
"blocked_countries": config.ListVariable(config.StringVariable("CU")),
"blocked_ips": config.ListVariable(config.StringVariable("1.1.1.1")),
"backend_origin_url": config.StringVariable("https://test-backend-1.cdn-dev.runs.onstackit.cloud"),
"geofencing_list": config.ListVariable(config.StringVariable("DE")),
"origin_request_headers_name": config.StringVariable("X-Custom-Header"),
"origin_request_headers_value": config.StringVariable("x-custom-value"),
"certificate": config.StringVariable(string(cert)),
"private_key": config.StringVariable(string(key)),
"redirect_target_url": config.StringVariable("https://example.com"),
"redirect_status_code": config.IntegerVariable(301),
"redirect_matcher_value": config.StringVariable("/shop/*"),
"redirect_rule_description": config.StringVariable("Acc test redirect"),
"redirect_rule_enabled": config.BoolVariable(true),
"redirect_rule_match_condition": config.StringVariable("ANY"),
"redirect_matcher_condition": config.StringVariable("ANY"),
"waf_mode": config.StringVariable("ENABLED"),
"waf_type": config.StringVariable("FREE"),
"waf_allowed_http_methods_0": config.StringVariable("GET"),
"waf_allowed_request_content_types_0": config.StringVariable("application/json"),
"waf_allowed_http_versions_0": config.StringVariable("HTTP/1.0"),
"waf_paranoia_level": config.StringVariable("L2"),
"waf_disabled_rule_ids_0": config.StringVariable(wafRule1),
"waf_disabled_rule_group_ids_0": config.StringVariable(wafRule1),
"waf_disabled_rule_collection_ids_0": config.StringVariable(wafRule1),
"waf_enabled_rule_ids_0": config.StringVariable(wafRule2),
"waf_enabled_rule_group_ids_0": config.StringVariable(wafRule2),
"waf_enabled_rule_collection_ids_0": config.StringVariable(wafRule2),
"waf_log_only_rule_ids_0": config.StringVariable(wafRule3),
"waf_log_only_rule_group_ids_0": config.StringVariable(wafRule3),
"waf_log_only_rule_collection_ids_0": config.StringVariable(wafRule3),
"tls_enable_tls_10": config.BoolVariable(true),
"tls_enable_tls_11": config.BoolVariable(true),
"strip_response_cookies": config.BoolVariable(false),
"forward_host_header": config.BoolVariable(true),
"monthly_limit_bytes": config.IntegerVariable(104857600),
"default_cache_duration": config.StringVariable("PT2H"),
}

func configVarsHttpUpdated() config.Variables {
updatedConfig := maps.Clone(testConfigVarsHttp)
updatedConfig["regions"] = config.ListVariable(config.StringVariable("EU"), config.StringVariable("US"), config.StringVariable("ASIA"))
updatedConfig["redirect_target_url"] = config.StringVariable("https://example.com/updated")
updatedConfig["monthly_limit_bytes"] = config.IntegerVariable(209715200)
updatedConfig["default_cache_duration"] = config.StringVariable("PT4H")
updatedConfig["blocked_ips"] = config.ListVariable(config.StringVariable("1.1.1.1"), config.StringVariable("2.2.2.2"))

// Update WAF configuration to test mutation
updatedConfig["waf"] = wafConfigVariable("LOG_ONLY", "PREMIUM", "L3", "POST", "text/plain", "HTTP/1.1", wafRule3, wafRule2, wafRule1)
Expand Down Expand Up @@ -220,8 +240,13 @@ func TestAccCDNDistributionHttp(t *testing.T) {
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.matchers.#", "1"),
testutil.CheckListAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.matchers.0.values", testConfigVarsHttp["redirect_matcher_values"]),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.matchers.0.value_match_condition", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_matcher_condition"])),
testutil.CheckListAttr("stackit_cdn_distribution.distribution", "config.regions", testConfigVarsHttp["regions"]),
testutil.CheckListAttr("stackit_cdn_distribution.distribution", "config.blocked_countries", testConfigVarsHttp["blocked_countries"]),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.regions.#", "2"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.regions.0", "EU"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.regions.1", "US"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_countries.#", "1"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_countries.0", "CU"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_ips.#", "1"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_ips.0", "1.1.1.1"),
resource.TestCheckResourceAttr(
"stackit_cdn_distribution.distribution",
fmt.Sprintf("config.backend.origin_request_headers.%s", testutil.ConvertConfigVariable(testConfigVarsHttp["origin_request_headers_name"])),
Expand All @@ -239,6 +264,8 @@ func TestAccCDNDistributionHttp(t *testing.T) {
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.tls.enable_tls_11", testutil.ConvertConfigVariable(testConfigVarsHttp["tls_enable_tls_11"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.forward_host_header", testutil.ConvertConfigVariable(testConfigVarsHttp["forward_host_header"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.strip_response_cookies", testutil.ConvertConfigVariable(testConfigVarsHttp["strip_response_cookies"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.monthly_limit_bytes", testutil.ConvertConfigVariable(testConfigVarsHttp["monthly_limit_bytes"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.default_cache_duration", testutil.ConvertConfigVariable(testConfigVarsHttp["default_cache_duration"])),

// WAF Checks
testutil.CheckObjectAttr("stackit_cdn_distribution.distribution", "config.waf", testConfigVarsHttp["waf"]),
Expand Down Expand Up @@ -340,14 +367,21 @@ func TestAccCDNDistributionHttp(t *testing.T) {
fmt.Sprintf("config.backend.geofencing.%s", testutil.ConvertConfigVariable(testConfigVarsHttp["backend_origin_url"])),
testConfigVarsHttp["geofencing_list"],
),
testutil.CheckListAttr("data.stackit_cdn_distribution.distribution", "config.blocked_countries", testConfigVarsHttp["blocked_countries"]),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.regions.0", "EU"),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.regions.1", "US"),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.blocked_countries.#", "1"),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.blocked_countries.0", "CU"),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.blocked_ips.#", "1"),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.blocked_ips.0", "1.1.1.1"),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.optimizer.enabled", testutil.ConvertConfigVariable(testConfigVarsHttp["optimizer"])),

// TLS Checks inside Data Source
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.tls.enable_tls_10", testutil.ConvertConfigVariable(testConfigVarsHttp["tls_enable_tls_10"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.tls.enable_tls_11", testutil.ConvertConfigVariable(testConfigVarsHttp["tls_enable_tls_11"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.forward_host_header", testutil.ConvertConfigVariable(testConfigVarsHttp["forward_host_header"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.strip_response_cookies", testutil.ConvertConfigVariable(testConfigVarsHttp["strip_response_cookies"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.monthly_limit_bytes", testutil.ConvertConfigVariable(testConfigVarsHttp["monthly_limit_bytes"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.default_cache_duration", testutil.ConvertConfigVariable(testConfigVarsHttp["default_cache_duration"])),

// WAF Checks inside Data Source
testutil.CheckObjectAttr("data.stackit_cdn_distribution.distribution", "config.waf", testConfigVarsHttp["waf"]),
Expand Down Expand Up @@ -384,15 +418,24 @@ func TestAccCDNDistributionHttp(t *testing.T) {
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "domains.1.status", "ACTIVE"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "domains.0.type", "managed"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "domains.1.type", "custom"),
testutil.CheckListAttr("stackit_cdn_distribution.distribution", "config.regions", configVarsHttpUpdated()["regions"]),
testutil.CheckListAttr("stackit_cdn_distribution.distribution", "config.blocked_countries", configVarsHttpUpdated()["blocked_countries"]),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.regions.#", "3"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.regions.0", "EU"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.regions.1", "US"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.regions.2", "ASIA"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_countries.#", "1"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_countries.0", "CU"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_ips.#", "2"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_ips.0", "1.1.1.1"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_ips.1", "2.2.2.2"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.optimizer.enabled", testutil.ConvertConfigVariable(testConfigVarsHttp["optimizer"])),

// TLS Configuration
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.tls.enable_tls_10", testutil.ConvertConfigVariable(configVarsHttpUpdated()["tls_enable_tls_10"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.tls.enable_tls_11", testutil.ConvertConfigVariable(configVarsHttpUpdated()["tls_enable_tls_11"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.forward_host_header", testutil.ConvertConfigVariable(configVarsHttpUpdated()["forward_host_header"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.strip_response_cookies", testutil.ConvertConfigVariable(configVarsHttpUpdated()["strip_response_cookies"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.monthly_limit_bytes", testutil.ConvertConfigVariable(configVarsHttpUpdated()["monthly_limit_bytes"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.default_cache_duration", testutil.ConvertConfigVariable(configVarsHttpUpdated()["default_cache_duration"])),

// Checking WAF Mutated Configurations
testutil.CheckObjectAttr("stackit_cdn_distribution.distribution", "config.waf", configVarsHttpUpdated()["waf"]),
Expand Down
Loading