Skip to content

Commit cf12967

Browse files
author
Matheus Politano
committed
chore: adjust for the new sdk version
1 parent 6d30d9b commit cf12967

File tree

2 files changed

+37
-44
lines changed

2 files changed

+37
-44
lines changed

stackit/internal/services/cdn/distribution/datasource.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,15 @@ func mapDataSourceFields(ctx context.Context, distribution *cdnSdk.Distribution,
356356

357357
// redirects
358358
redirectsVal := types.ObjectNull(redirectsTypes)
359-
if distribution.Config != nil && distribution.Config.Redirects != nil && distribution.Config.Redirects.Rules != nil {
359+
if distribution.Config.Redirects != nil && distribution.Config.Redirects.Rules != nil {
360360
var tfRules []attr.Value
361-
for _, r := range *distribution.Config.Redirects.Rules {
361+
for _, r := range distribution.Config.Redirects.Rules {
362362
var tfMatchers []attr.Value
363363
if r.Matchers != nil {
364-
for _, m := range *r.Matchers {
364+
for _, m := range r.Matchers {
365365
var tfValues []attr.Value
366366
if m.Values != nil {
367-
for _, v := range *m.Values {
367+
for _, v := range m.Values {
368368
tfValues = append(tfValues, types.StringValue(v))
369369
}
370370
}
@@ -405,13 +405,13 @@ func mapDataSourceFields(ctx context.Context, distribution *cdnSdk.Distribution,
405405
}
406406

407407
tfTargetUrl := types.StringNull()
408-
if r.TargetUrl != nil {
409-
tfTargetUrl = types.StringValue(*r.TargetUrl)
408+
if r.TargetUrl != "" {
409+
tfTargetUrl = types.StringValue(r.TargetUrl)
410410
}
411411

412412
tfStatusCode := types.Int32Null()
413-
if r.StatusCode != nil {
414-
tfStatusCode = types.Int32Value(int32(*r.StatusCode)) // nolint:gosec // HTTP status codes are safely within int32 bounds
413+
if r.StatusCode != 0 {
414+
tfStatusCode = types.Int32Value(int32(r.StatusCode)) // nolint:gosec // HTTP status codes are safely within int32 bounds
415415
}
416416

417417
tfRuleMatchCond := types.StringNull()

stackit/internal/services/cdn/distribution/resource.go

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
3131
"github.com/hashicorp/terraform-plugin-log/tflog"
3232
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
33-
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
3433
cdnSdk "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
3534
"github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api/wait"
3635
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
@@ -684,7 +683,7 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
684683

685684
// blockedCountries
686685
// Use a pointer to a slice to distinguish between an empty list (unblock all) and nil (no change).
687-
var blockedCountries *[]string
686+
var blockedCountries []string
688687
if configModel.BlockedCountries != nil {
689688
// Use a temporary slice
690689
tempBlockedCountries := []string{}
@@ -699,7 +698,7 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
699698
}
700699

701700
// Point to the populated slice
702-
blockedCountries = &tempBlockedCountries
701+
blockedCountries = tempBlockedCountries
703702
}
704703

705704
// redirects
@@ -717,7 +716,7 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
717716
}
718717

719718
matchers = append(matchers, cdnSdk.Matcher{
720-
Values: &matcher.Values,
719+
Values: matcher.Values,
721720
ValueMatchCondition: matchCond,
722721
})
723722
}
@@ -727,23 +726,21 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
727726
cond := cdnSdk.MatchCondition(*rule.RuleMatchCondition)
728727
ruleMatchCond = &cond
729728
}
730-
731-
statusCode := cdnSdk.RedirectRuleStatusCode(rule.StatusCode)
732729
targetUrl := rule.TargetUrl
733730

734731
sdkConfigRule := cdnSdk.RedirectRule{
735732
Description: rule.Description,
736733
Enabled: rule.Enabled,
737-
Matchers: &matchers,
734+
Matchers: matchers,
738735
RuleMatchCondition: ruleMatchCond,
739-
StatusCode: &statusCode,
740-
TargetUrl: &targetUrl,
736+
StatusCode: rule.StatusCode,
737+
TargetUrl: targetUrl,
741738
}
742739
sdkRules = append(sdkRules, sdkConfigRule)
743740
}
744741
}
745742
redirectsConfig = &cdnSdk.RedirectConfig{
746-
Rules: &sdkRules,
743+
Rules: sdkRules,
747744
}
748745
}
749746

@@ -790,7 +787,7 @@ func (r *distributionResource) Update(ctx context.Context, req resource.UpdateRe
790787

791788
configPatch := &cdnSdk.ConfigPatch{
792789
Backend: configPatchBackend,
793-
Regions: &regions,
790+
Regions: regions,
794791
BlockedCountries: blockedCountries,
795792
Redirects: redirectsConfig,
796793
}
@@ -949,15 +946,15 @@ func mapFields(ctx context.Context, distribution *cdnSdk.Distribution, model *Mo
949946

950947
// redirects
951948
redirectsVal := types.ObjectNull(redirectsTypes)
952-
if distribution.Config != nil && distribution.Config.Redirects != nil && distribution.Config.Redirects.Rules != nil {
949+
if distribution.Config.Redirects != nil && distribution.Config.Redirects.Rules != nil {
953950
var tfRules []attr.Value
954-
for _, r := range *distribution.Config.Redirects.Rules {
951+
for _, r := range distribution.Config.Redirects.Rules {
955952
var tfMatchers []attr.Value
956953
if r.Matchers != nil {
957-
for _, m := range *r.Matchers {
954+
for _, m := range r.Matchers {
958955
var tfValues []attr.Value
959956
if m.Values != nil {
960-
for _, v := range *m.Values {
957+
for _, v := range m.Values {
961958
tfValues = append(tfValues, types.StringValue(v))
962959
}
963960
}
@@ -998,13 +995,13 @@ func mapFields(ctx context.Context, distribution *cdnSdk.Distribution, model *Mo
998995
}
999996

1000997
tfTargetUrl := types.StringNull()
1001-
if r.TargetUrl != nil {
1002-
tfTargetUrl = types.StringValue(*r.TargetUrl)
998+
if r.TargetUrl != "" {
999+
tfTargetUrl = types.StringValue(r.TargetUrl)
10031000
}
10041001

10051002
tfStatusCode := types.Int32Null()
1006-
if r.StatusCode != nil {
1007-
tfStatusCode = types.Int32Value(int32(*r.StatusCode)) // nolint:gosec // HTTP status codes are safely within int32 bounds
1003+
if r.StatusCode > 0 {
1004+
tfStatusCode = types.Int32Value(int32(r.StatusCode)) // nolint:gosec // HTTP status codes are safely within int32 bounds
10081005
}
10091006

10101007
tfRuleMatchCond := types.StringValue("ANY")
@@ -1275,9 +1272,8 @@ func toCreatePayload(ctx context.Context, model *Model) (*cdnSdk.CreateDistribut
12751272
},
12761273
}
12771274
}
1278-
intendId := uuid.NewString()
12791275
payload := &cdnSdk.CreateDistributionPayload{
1280-
IntentId: new(intendId),
1276+
IntentId: new(uuid.NewString()),
12811277
Regions: cfg.Regions,
12821278
Backend: *backend,
12831279
BlockedCountries: cfg.BlockedCountries,
@@ -1335,42 +1331,39 @@ func convertConfig(ctx context.Context, model *Model) (*cdnSdk.Config, error) {
13351331

13361332
if len(configModel.Redirects.Rules) > 0 {
13371333
for _, rule := range configModel.Redirects.Rules {
1338-
matchers := []cdn.Matcher{}
1334+
matchers := []cdnSdk.Matcher{}
13391335
for _, matcher := range rule.Matchers {
1340-
var matchCond *cdn.MatchCondition
1336+
var matchCond *cdnSdk.MatchCondition
13411337
if matcher.ValueMatchCondition != nil {
1342-
cond := cdn.MatchCondition(*matcher.ValueMatchCondition)
1338+
cond := cdnSdk.MatchCondition(*matcher.ValueMatchCondition)
13431339
matchCond = &cond
13441340
}
13451341

1346-
matchers = append(matchers, cdn.Matcher{
1347-
Values: &matcher.Values,
1342+
matchers = append(matchers, cdnSdk.Matcher{
1343+
Values: matcher.Values,
13481344
ValueMatchCondition: matchCond,
13491345
})
13501346
}
13511347

1352-
var ruleMatchCond *cdn.MatchCondition
1348+
var ruleMatchCond *cdnSdk.MatchCondition
13531349
if rule.RuleMatchCondition != nil {
1354-
cond := cdn.MatchCondition(*rule.RuleMatchCondition)
1350+
cond := cdnSdk.MatchCondition(*rule.RuleMatchCondition)
13551351
ruleMatchCond = &cond
13561352
}
13571353

1358-
statusCode := cdn.RedirectRuleStatusCode(rule.StatusCode)
1359-
targerUrl := rule.TargetUrl
1360-
1361-
sdkConfigRule := cdn.RedirectRule{
1354+
sdkConfigRule := cdnSdk.RedirectRule{
13621355
Description: rule.Description,
13631356
Enabled: rule.Enabled,
1364-
Matchers: &matchers,
1357+
Matchers: matchers,
13651358
RuleMatchCondition: ruleMatchCond,
1366-
StatusCode: &statusCode,
1367-
TargetUrl: &targerUrl,
1359+
StatusCode: rule.StatusCode,
1360+
TargetUrl: rule.TargetUrl,
13681361
}
13691362
sdkRules = append(sdkRules, sdkConfigRule)
13701363
}
13711364
}
13721365
redirectsConfig = &cdnSdk.RedirectConfig{
1373-
Rules: &sdkRules,
1366+
Rules: sdkRules,
13741367
}
13751368
}
13761369

0 commit comments

Comments
 (0)