Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7c989aa
feat: add redirects in convertConfig
Mar 26, 2026
7cca33f
feat: add redirect in toCreatePayload
Mar 26, 2026
e850a14
feat: add redirect in the update function
Mar 26, 2026
cf6f255
feat: add in the map field mapfield
Mar 26, 2026
72d079c
small fix and add datasource
Mar 27, 2026
cafad57
chore: update doc
Mar 27, 2026
f2bcc1b
chore: add resource example
Mar 27, 2026
a5f9f48
Merge branch 'main' into mp/cdn/feat/implement-redirects
Mar 31, 2026
9addaea
chore: add redirect in acc test and address linter issues
Mar 31, 2026
618c3a2
chore: address linter issue
Mar 31, 2026
9a22cef
chore: add doc
Mar 31, 2026
83c4b94
Merge branch 'main' into mp/cdn/feat/implement-redirects
matheuspolitano Mar 31, 2026
6d30d9b
Merge branch 'main' into mp/cdn/feat/implement-redirects
Apr 1, 2026
cf12967
chore: adjust for the new sdk version
Apr 1, 2026
45905c6
chore: implement new sdk in cdn_acc_test
Apr 1, 2026
92dfd6f
Merge branch 'main' into mp/cdn/feat/implement-redirects
matheuspolitano Apr 7, 2026
9ccd292
Merge branch 'main' into mp/cdn/feat/implement-redirects
matheuspolitano Apr 8, 2026
56f3e9c
Merge branch 'main' into mp/cdn/feat/implement-redirects
matheuspolitano Apr 13, 2026
7f5e08d
FYI: add all field in acc_test
Apr 13, 2026
a41657a
feat: DRY creatian redirect Config up
Apr 23, 2026
06c4b5c
chore: use SDK match condition
Apr 23, 2026
b756791
chore: some small tweaks to avoid redundancy
Apr 23, 2026
0fd82a0
chore: some small tweaks in test
Apr 23, 2026
535a8d8
chore: simplify the redirect set up in test
matheuspolitano Apr 23, 2026
a1eda91
fix: use the right variable instead the new one, get rif of some redu…
Apr 23, 2026
633ac4f
chore: remove redundant string in acc_test
Apr 23, 2026
ec7f0d5
Merge branch 'stackitcloud:main' into mp/cdn/feat/implement-redirects
matheuspolitano Apr 23, 2026
4cc4b60
chore: remove empty line at the end of the function and order acc imp…
Apr 23, 2026
43ad030
feat: remove the case insensitive
matheuspolitano Apr 24, 2026
e1ee94f
feat: add validation to no null values
matheuspolitano Apr 24, 2026
be8a32e
chore: remove redundant code
Apr 24, 2026
0d3507a
fix: add redirecttype
Apr 24, 2026
6c1b069
chore: change the all matcho dondition to all
Apr 24, 2026
e93dcb2
feat: make match condition sensitive
Apr 24, 2026
c308a6c
Merge branch 'main' into mp/cdn/feat/implement-redirects
matheuspolitano Apr 24, 2026
e8d4324
chore: remove portuguese comment
Apr 24, 2026
d8448a1
chore: switch to all ALL
Apr 24, 2026
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
31 changes: 31 additions & 0 deletions docs/data-sources/cdn_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Read-Only:

- `backend` (Attributes) The configured backend for the distribution (see [below for nested schema](#nestedatt--config--backend))
- `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

<a id="nestedatt--config--backend"></a>
Expand All @@ -74,6 +75,36 @@ Read-Only:
- `enabled` (Boolean)


<a id="nestedatt--config--redirects"></a>
### Nested Schema for `config.redirects`

Read-Only:

- `rules` (Attributes List) A list of redirect rules. The order of rules matters for evaluation (see [below for nested schema](#nestedatt--config--redirects--rules))

<a id="nestedatt--config--redirects--rules"></a>
### Nested Schema for `config.redirects.rules`

Read-Only:

- `description` (String) An optional description for the redirect rule
- `enabled` (Boolean) A toggle to enable or disable the redirect rule. Default to true
- `matchers` (Attributes List) A list of matchers that define when this rule should apply. At least one matcher is required (see [below for nested schema](#nestedatt--config--redirects--rules--matchers))
- `rule_match_condition` (String) Defines how multiple matchers within this rule are combined (ALL, ANY, NONE). Defaults to ANY.
- `status_code` (Number) The HTTP status code for the redirect. Must be one of 301, 302, 303, 307, or 308.
- `target_url` (String) The target URL to redirect to. Must be a valid URI

<a id="nestedatt--config--redirects--rules--matchers"></a>
### Nested Schema for `config.redirects.rules.matchers`

Read-Only:

- `value_match_condition` (String) Defines how multiple matchers within this rule are combined (ALL, ANY, NONE). Defaults to ANY.
- `values` (List of String) A list of glob patterns to match against the request path. At least one value is required. Examples: "/shop/*" or "*/img/*"





<a id="nestedatt--domains"></a>
### Nested Schema for `domains`
Expand Down
55 changes: 55 additions & 0 deletions docs/resources/cdn_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ resource "stackit_cdn_distribution" "example_bucket_distribution" {
optimizer = {
enabled = false
}

redirects = {
rules = [
{
description = "test redirect"
enabled = true
rule_match_condition = "ANY"
status_code = 302
target_url = "https://stackit.de/"
matchers = [
{
values = ["*/otherPath/"]
value_match_condition = "ANY"
}
]
}
]
}
}
}

Expand Down Expand Up @@ -96,6 +114,7 @@ Optional:

- `blocked_countries` (List of String) The configured countries where distribution of content is blocked
- `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))

<a id="nestedatt--config--backend"></a>
### Nested Schema for `config.backend`
Expand Down Expand Up @@ -131,6 +150,42 @@ Optional:
- `enabled` (Boolean)


<a id="nestedatt--config--redirects"></a>
### Nested Schema for `config.redirects`

Required:

- `rules` (Attributes List) A list of redirect rules. The order of rules matters for evaluation (see [below for nested schema](#nestedatt--config--redirects--rules))

<a id="nestedatt--config--redirects--rules"></a>
### Nested Schema for `config.redirects.rules`

Required:

- `matchers` (Attributes List) A list of matchers that define when this rule should apply. At least one matcher is required (see [below for nested schema](#nestedatt--config--redirects--rules--matchers))
- `status_code` (Number) The HTTP status code for the redirect. Must be one of 301, 302, 303, 307, or 308.
- `target_url` (String) The target URL to redirect to. Must be a valid URI

Optional:

- `description` (String) An optional description for the redirect rule
- `enabled` (Boolean) A toggle to enable or disable the redirect rule. Default to true
- `rule_match_condition` (String) Defines how multiple matchers within this rule are combined (ALL, ANY, NONE). Defaults to ANY.

<a id="nestedatt--config--redirects--rules--matchers"></a>
### Nested Schema for `config.redirects.rules.matchers`

Required:

- `values` (List of String) A list of glob patterns to match against the request path. At least one value is required. Examples: "/shop/*" or "*/img/*"

Optional:

- `value_match_condition` (String) Defines how multiple matchers within this rule are combined (ALL, ANY, NONE). Defaults to ANY.





<a id="nestedatt--domains"></a>
### Nested Schema for `domains`
Expand Down
18 changes: 18 additions & 0 deletions examples/resources/stackit_cdn_distribution/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ resource "stackit_cdn_distribution" "example_bucket_distribution" {
optimizer = {
enabled = false
}

redirects = {
rules = [
{
description = "test redirect"
enabled = true
rule_match_condition = "ANY"
status_code = 302
target_url = "https://stackit.de/"
matchers = [
{
values = ["*/otherPath/"]
value_match_condition = "ANY"
}
]
}
]
}
}
}

Expand Down
63 changes: 46 additions & 17 deletions stackit/internal/services/cdn/cdn_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
cdnSdk "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
"github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api/wait"

"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil"

cdnSdk "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
)

var (
Expand Down Expand Up @@ -77,27 +78,34 @@ func configVarsBucketUpdated() config.Variables {
}

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)),
"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_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"),
}

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")
return updatedConfig
}

Expand Down Expand Up @@ -157,6 +165,15 @@ func TestAccCDNDistributionHttp(t *testing.T) {
resource.TestCheckResourceAttrSet("stackit_cdn_distribution.distribution", "domains.0.name"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "domains.0.type", "managed"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "domains.0.status", "ACTIVE"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.#", "1"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.target_url", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_target_url"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.status_code", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_status_code"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.description", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_rule_description"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.enabled", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_rule_enabled"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.rule_match_condition", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_rule_match_condition"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.matchers.#", "1"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.matchers.0.values.0", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_matcher_value"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.matchers.0.value_match_condition", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_matcher_condition"])),
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"),
Expand Down Expand Up @@ -277,6 +294,14 @@ func TestAccCDNDistributionHttp(t *testing.T) {
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.optimizer.enabled", testutil.ConvertConfigVariable(testConfigVarsHttp["optimizer"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "project_id", testutil.ProjectId),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "status", "ACTIVE"),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.redirects.rules.#", "1"),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.redirects.rules.0.target_url", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_target_url"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.redirects.rules.0.status_code", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_status_code"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.redirects.rules.0.description", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_rule_description"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.redirects.rules.0.enabled", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_rule_enabled"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.redirects.rules.0.rule_match_condition", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_rule_match_condition"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.redirects.rules.0.matchers.0.values.0", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_matcher_value"])),
resource.TestCheckResourceAttr("data.stackit_cdn_distribution.distribution", "config.redirects.rules.0.matchers.0.value_match_condition", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_matcher_condition"])),

resource.TestCheckResourceAttr("data.stackit_cdn_custom_domain.custom_domain", "status", "ACTIVE"),
resource.TestCheckResourceAttr("data.stackit_cdn_custom_domain.custom_domain", "name", fullDomainNameHttp),
Expand Down Expand Up @@ -319,6 +344,10 @@ func TestAccCDNDistributionHttp(t *testing.T) {
"DE",
),

resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.#", "1"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.target_url", testutil.ConvertConfigVariable(configVarsHttpUpdated()["redirect_target_url"])),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.status_code", testutil.ConvertConfigVariable(testConfigVarsHttp["redirect_status_code"])),

resource.TestCheckResourceAttr("stackit_cdn_custom_domain.custom_domain", "status", "ACTIVE"),
resource.TestCheckResourceAttr("stackit_cdn_custom_domain.custom_domain", "name", fullDomainNameHttp),
resource.TestCheckResourceAttr("stackit_cdn_custom_domain.custom_domain", "certificate.version", "1"),
Expand Down
Loading
Loading