feat(cdn): implement redirects#1333
feat(cdn): implement redirects#1333matheuspolitano wants to merge 19 commits intostackitcloud:mainfrom
Conversation
|
Could you please adjust the acc tests to include the new fields? 😅 |
ae228fb to
f2bcc1b
Compare
its done :) |
84a7ff9 to
cf12967
Compare
|
@rubenhoenle @marceljk its done already the acc_test over weeks, Could you check again? |
| Description: schemaDescriptions["config_redirects_rule_match_condition"], | ||
| Default: stringdefault.StaticString("ANY"), | ||
| Computed: true, | ||
| Validators: []validator.String{stringvalidator.OneOfCaseInsensitive(matchCondition...)}, |
There was a problem hiding this comment.
You can use here the generated enums from the SDK. So we don't need to manually maintain the valid values.
| 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...)}, |
There was a problem hiding this comment.
same here
| 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"} |
There was a problem hiding this comment.
can be removed
| matchCondition := []string{"ANY", "ALL", "NONE"} |
| 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) | ||
| } |
There was a problem hiding this comment.
can be simplified
| 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 |
There was a problem hiding this comment.
redundant. probably solves also the linter issue
| tfStatusCode = types.Int32Value(int32(r.StatusCode)) // nolint:gosec // HTTP status codes are safely within int32 bounds | |
| tfStatusCode = types.Int32Value(r.StatusCode) |
| 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), |
There was a problem hiding this comment.
simplify it like in the previous test function
| RuleMatchCondition: cdnSdk.MatchCondition("ANY").Ptr(), | ||
| Matchers: []cdnSdk.Matcher{ | ||
| { | ||
| Values: []string{"/shop/*"}, | ||
| ValueMatchCondition: cdnSdk.MatchCondition("ANY").Ptr(), |
| 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), | ||
| }) |
| RuleMatchCondition: cdnSdk.MatchCondition("ANY").Ptr(), | ||
| Matchers: []cdnSdk.Matcher{ | ||
| { | ||
| Values: []string{"/shop/*"}, | ||
| ValueMatchCondition: cdnSdk.MatchCondition("ANY").Ptr(), |
| ), | ||
|
|
||
| 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"), |
There was a problem hiding this comment.
| 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"])), |
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
make fmtexamples/directory)make generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)