Skip to content

feat(cdn): implement redirects#1333

Open
matheuspolitano wants to merge 19 commits intostackitcloud:mainfrom
matheuspolitano:mp/cdn/feat/implement-redirects
Open

feat(cdn): implement redirects#1333
matheuspolitano wants to merge 19 commits intostackitcloud:mainfrom
matheuspolitano:mp/cdn/feat/implement-redirects

Conversation

@matheuspolitano
Copy link
Copy Markdown
Contributor

@matheuspolitano matheuspolitano commented Mar 27, 2026

Description

STACKITCDN-1104

In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->

relates to #1234

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@matheuspolitano matheuspolitano requested a review from a team as a code owner March 27, 2026 13:24
@matheuspolitano matheuspolitano changed the title feat(cdn): implement new bucket backend type feat(cdn): implement redirects Mar 27, 2026
@rubenhoenle
Copy link
Copy Markdown
Member

Could you please adjust the acc tests to include the new fields? 😅

@rubenhoenle rubenhoenle added the needs-work PR needs changes by the author. label Mar 27, 2026
@matheuspolitano matheuspolitano force-pushed the mp/cdn/feat/implement-redirects branch 2 times, most recently from ae228fb to f2bcc1b Compare March 31, 2026 12:25
@matheuspolitano
Copy link
Copy Markdown
Contributor Author

Could you please adjust the acc tests to include the new fields? 😅

its done :)

@matheuspolitano matheuspolitano force-pushed the mp/cdn/feat/implement-redirects branch from 84a7ff9 to cf12967 Compare April 1, 2026 18:49
@matheuspolitano
Copy link
Copy Markdown
Contributor Author

@rubenhoenle @marceljk its done already the acc_test over weeks, Could you check again?

@rubenhoenle rubenhoenle removed the needs-work PR needs changes by the author. label Apr 20, 2026
Description: schemaDescriptions["config_redirects_rule_match_condition"],
Default: stringdefault.StaticString("ANY"),
Computed: true,
Validators: []validator.String{stringvalidator.OneOfCaseInsensitive(matchCondition...)},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use here the generated enums from the SDK. So we don't need to manually maintain the valid values.

Suggested change
Validators: []validator.String{stringvalidator.OneOfCaseInsensitive(matchCondition...)},
Validators: []validator.String{stringvalidator.OneOfCaseInsensitive(sdkUtils.EnumSliceToStringSlice(cdnSdk.AllowedMatchConditionEnumValues)...)},

Computed: true,
Description: schemaDescriptions["config_redirects_rule_match_condition"],
Default: stringdefault.StaticString("ANY"),
Validators: []validator.String{stringvalidator.OneOfCaseInsensitive(matchCondition...)},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Suggested change
Validators: []validator.String{stringvalidator.OneOfCaseInsensitive(matchCondition...)},
Validators: []validator.String{stringvalidator.OneOfCaseInsensitive(sdkUtils.EnumSliceToStringSlice(cdnSdk.AllowedMatchConditionEnumValues)...)},


func (r *distributionResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
backendOptions := []string{"http", "bucket"}
matchCondition := []string{"ANY", "ALL", "NONE"}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

Suggested change
matchCondition := []string{"ANY", "ALL", "NONE"}

Comment on lines +955 to +964
var tfValues []attr.Value
if m.Values != nil {
for _, v := range m.Values {
tfValues = append(tfValues, types.StringValue(v))
}
}
tfValuesList, diags := types.ListValue(types.StringType, tfValues)
if diags.HasError() {
return core.DiagsToError(diags)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be simplified

Suggested change
var tfValues []attr.Value
if m.Values != nil {
for _, v := range m.Values {
tfValues = append(tfValues, types.StringValue(v))
}
}
tfValuesList, diags := types.ListValue(types.StringType, tfValues)
if diags.HasError() {
return core.DiagsToError(diags)
}
tfValuesList, diags := types.ListValueFrom(ctx, types.StringType, m.Values)
if diags.HasError() {
return core.DiagsToError(diags)
}


tfStatusCode := types.Int32Null()
if r.StatusCode > 0 {
tfStatusCode = types.Int32Value(int32(r.StatusCode)) // nolint:gosec // HTTP status codes are safely within int32 bounds
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant. probably solves also the linter issue

Suggested change
tfStatusCode = types.Int32Value(int32(r.StatusCode)) // nolint:gosec // HTTP status codes are safely within int32 bounds
tfStatusCode = types.Int32Value(r.StatusCode)

Comment on lines +284 to +295
redirectsObjType, ok := configTypes["redirects"].(basetypes.ObjectType)
if !ok {
t.Fatalf("configTypes[\"redirects\"] is not of type basetypes.ObjectType")
}
redirectsAttrTypes := redirectsObjType.AttrTypes

config := types.ObjectValueMust(configTypes, map[string]attr.Value{
"backend": backend,
"regions": regionsFixture,
"optimizer": types.ObjectNull(optimizerTypes),
"blocked_countries": blockedCountriesFixture,
"redirects": types.ObjectNull(redirectsAttrTypes),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify it like in the previous test function

Comment on lines +564 to +568
RuleMatchCondition: cdnSdk.MatchCondition("ANY").Ptr(),
Matchers: []cdnSdk.Matcher{
{
Values: []string{"/shop/*"},
ValueMatchCondition: cdnSdk.MatchCondition("ANY").Ptr(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use here the enums

Comment on lines +543 to +555
redirectsObjType, ok := configTypes["redirects"].(basetypes.ObjectType)
if !ok {
t.Fatalf("configTypes[\"redirects\"] is not of type basetypes.ObjectType")
}
redirectsAttrTypes := redirectsObjType.AttrTypes

config := types.ObjectValueMust(configTypes, map[string]attr.Value{
"backend": backend,
"regions": regionsFixture,
"blocked_countries": blockedCountriesFixture,
"optimizer": types.ObjectNull(optimizerTypes),
"redirects": types.ObjectNull(redirectsAttrTypes),
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify it here

Comment on lines +422 to +426
RuleMatchCondition: cdnSdk.MatchCondition("ANY").Ptr(),
Matchers: []cdnSdk.Matcher{
{
Values: []string{"/shop/*"},
ValueMatchCondition: cdnSdk.MatchCondition("ANY").Ptr(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the existing enums

),

resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.#", "1"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.target_url", "https://example.com/updated"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.target_url", "https://example.com/updated"),
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.redirects.rules.0.target_url", testutil.ConvertConfigVariable(configVarsHttpUpdated()["https://example.com/updated"])),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants