Skip to content

Commit 95e5825

Browse files
author
Matheus Politano
committed
chore: revert for old version for while because we have a task in cdn team to fix it
1 parent 95cdcb0 commit 95e5825

11 files changed

Lines changed: 425 additions & 408 deletions

File tree

stackit/internal/services/cdn/cdn_acc_test.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
2222
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
2323
"github.com/hashicorp/terraform-plugin-testing/terraform"
24+
coreConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
2425
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
2526
"github.com/stackitcloud/stackit-sdk-go/services/cdn/wait"
2627
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
@@ -149,7 +150,7 @@ func TestAccCDNDistributionHttp(t *testing.T) {
149150
Steps: []resource.TestStep{
150151
// Distribution Create (Only Base config)
151152
{
152-
Config: testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig() + "\n" + resourceHttpBase,
153+
Config: testutil.CdnProviderConfig() + "\n" + resourceHttpBase,
153154
ConfigVariables: testConfigVarsHttp,
154155
Check: resource.ComposeAggregateTestCheckFunc(
155156
resource.TestCheckResourceAttrSet("stackit_cdn_distribution.distribution", "distribution_id"),
@@ -186,7 +187,7 @@ func TestAccCDNDistributionHttp(t *testing.T) {
186187
},
187188
// Wait step, confirms the CNAME record has "propagated" before trying to add the custom domain
188189
{
189-
Config: testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig() + "\n" + resourceHttpBase,
190+
Config: testutil.CdnProviderConfig() + "\n" + resourceHttpBase,
190191
ConfigVariables: testConfigVarsHttp,
191192
Check: func(_ *terraform.State) error {
192193
_, err := blockUntilDomainResolves(fullDomainNameHttp)
@@ -195,7 +196,7 @@ func TestAccCDNDistributionHttp(t *testing.T) {
195196
},
196197
// Custom Domain Create (Now using Full config)
197198
{
198-
Config: testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig() + "\n" + resourceHttpFull,
199+
Config: testutil.CdnProviderConfig() + "\n" + resourceHttpFull,
199200
ConfigVariables: testConfigVarsHttp,
200201
Check: resource.ComposeAggregateTestCheckFunc(
201202
resource.TestCheckResourceAttr("stackit_cdn_custom_domain.custom_domain", "status", "ACTIVE"),
@@ -253,7 +254,7 @@ func TestAccCDNDistributionHttp(t *testing.T) {
253254
},
254255
// Data Source
255256
{
256-
Config: testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig() + "\n" + resourceHttpFull,
257+
Config: testutil.CdnProviderConfig() + "\n" + resourceHttpFull,
257258
ConfigVariables: testConfigVarsHttp,
258259
Check: resource.ComposeAggregateTestCheckFunc(
259260
resource.TestCheckResourceAttrSet("data.stackit_cdn_distribution.distribution", "distribution_id"),
@@ -296,7 +297,7 @@ func TestAccCDNDistributionHttp(t *testing.T) {
296297
},
297298
// Update
298299
{
299-
Config: testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig() + "\n" + resourceHttpFull,
300+
Config: testutil.CdnProviderConfig() + "\n" + resourceHttpFull,
300301
ConfigVariables: configVarsHttpUpdated(),
301302
Check: resource.ComposeAggregateTestCheckFunc(
302303
resource.TestCheckResourceAttrSet("stackit_cdn_distribution.distribution", "distribution_id"),
@@ -354,7 +355,7 @@ func TestAccCDNDistributionBucket(t *testing.T) {
354355
Steps: []resource.TestStep{
355356
// Distribution Create
356357
{
357-
Config: testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig() + "\n" + resourceBucket,
358+
Config: testutil.CdnProviderConfig() + "\n" + resourceBucket,
358359
ConfigVariables: testConfigVarsBucket,
359360
Check: resource.ComposeAggregateTestCheckFunc(
360361
resource.TestCheckResourceAttrSet("stackit_cdn_distribution.distribution", "distribution_id"),
@@ -413,7 +414,7 @@ func TestAccCDNDistributionBucket(t *testing.T) {
413414
},
414415
// Data Source
415416
{
416-
Config: testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig() + "\n" + resourceBucket,
417+
Config: testutil.CdnProviderConfig() + "\n" + resourceBucket,
417418
ConfigVariables: testConfigVarsBucket,
418419
Check: resource.ComposeAggregateTestCheckFunc(
419420
resource.TestCheckResourceAttrSet("data.stackit_cdn_distribution.bucket_ds", "distribution_id"),
@@ -440,7 +441,7 @@ func TestAccCDNDistributionBucket(t *testing.T) {
440441
},
441442
// Update
442443
{
443-
Config: testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig() + "\n" + resourceBucket,
444+
Config: testutil.CdnProviderConfig() + "\n" + resourceBucket,
444445
ConfigVariables: configVarsBucketUpdated(),
445446
Check: resource.ComposeAggregateTestCheckFunc(
446447
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "status", "ACTIVE"),
@@ -466,7 +467,7 @@ func TestAccCDNDistributionBucket(t *testing.T) {
466467
// empty list '[]', causing a state mismatch. The 'Default' modifier in the schema now
467468
// ensures the missing config is treated as an empty list, matching the API response.
468469
{
469-
Config: testutil.NewConfigBuilder().EnableBetaResources(true).BuildProviderConfig() + "\n" + resourceBucket,
470+
Config: testutil.CdnProviderConfig() + "\n" + resourceBucket,
470471
ConfigVariables: configVarsBucketUpdated(),
471472
Check: resource.ComposeAggregateTestCheckFunc(
472473
resource.TestCheckResourceAttr("stackit_cdn_distribution.distribution", "config.blocked_countries.#", "0"),
@@ -478,7 +479,15 @@ func TestAccCDNDistributionBucket(t *testing.T) {
478479

479480
func testAccCheckCDNDistributionDestroy(s *terraform.State) error {
480481
ctx := context.Background()
481-
client, err := cdn.NewAPIClient(testutil.NewConfigBuilder().BuildClientOptions(testutil.CdnCustomEndpoint, false)...)
482+
var client *cdn.APIClient
483+
var err error
484+
if testutil.CdnCustomEndpoint == "" {
485+
client, err = cdn.NewAPIClient()
486+
} else {
487+
client, err = cdn.NewAPIClient(
488+
coreConfig.WithEndpoint(testutil.CdnCustomEndpoint),
489+
)
490+
}
482491
if err != nil {
483492
return fmt.Errorf("creating client: %w", err)
484493
}
@@ -548,7 +557,7 @@ func blockUntilDomainResolves(domain string) (net.IP, error) {
548557
func retry[T any](attempts int, sleep time.Duration, f func() (T, error)) (T, error) {
549558
var zero T
550559
var errOuter error
551-
for range attempts {
560+
for i := 0; i < attempts; i++ {
552561
dist, err := f()
553562
if err == nil {
554563
return dist, nil

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66

7-
cdnSdk "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
87
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
98
cdnUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/cdn/utils"
109
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
@@ -15,6 +14,7 @@ import (
1514
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1615
"github.com/hashicorp/terraform-plugin-framework/types"
1716
"github.com/hashicorp/terraform-plugin-log/tflog"
17+
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
1818
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
1919
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/features"
2020
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
@@ -27,11 +27,11 @@ var (
2727
)
2828

2929
var certificateDataSourceTypes = map[string]attr.Type{
30-
"version": types.Int32Type,
30+
"version": types.Int64Type,
3131
}
3232

3333
type customDomainDataSource struct {
34-
client *cdnSdk.APIClient
34+
client *cdn.APIClient
3535
}
3636

3737
func NewCustomDomainDataSource() datasource.DataSource {
@@ -106,7 +106,7 @@ func (r *customDomainDataSource) Schema(_ context.Context, _ datasource.SchemaRe
106106
Description: certificateSchemaDescriptions["main"],
107107
Optional: true,
108108
Attributes: map[string]schema.Attribute{
109-
"version": schema.Int32Attribute{
109+
"version": schema.Int64Attribute{
110110
Description: certificateSchemaDescriptions["version"],
111111
Computed: true,
112112
},
@@ -133,7 +133,7 @@ func (r *customDomainDataSource) Read(ctx context.Context, req datasource.ReadRe
133133
name := model.Name.ValueString()
134134
ctx = tflog.SetField(ctx, "name", name)
135135

136-
customDomainResp, err := r.client.DefaultAPI.GetCustomDomain(ctx, projectId, distributionId, name).Execute()
136+
customDomainResp, err := r.client.GetCustomDomain(ctx, projectId, distributionId, name).Execute()
137137
if err != nil {
138138
utils.LogError(
139139
ctx,
@@ -165,19 +165,23 @@ func (r *customDomainDataSource) Read(ctx context.Context, req datasource.ReadRe
165165
tflog.Info(ctx, "CDN custom domain read")
166166
}
167167

168-
func mapCustomDomainDataSourceFields(customDomainResponse *cdnSdk.GetCustomDomainResponse, model *customDomainDataSourceModel, projectId, distributionId string) error {
168+
func mapCustomDomainDataSourceFields(customDomainResponse *cdn.GetCustomDomainResponse, model *customDomainDataSourceModel, projectId, distributionId string) error {
169169
if customDomainResponse == nil {
170170
return fmt.Errorf("response input is nil")
171171
}
172172
if model == nil {
173173
return fmt.Errorf("model input is nil")
174174
}
175175

176-
if customDomainResponse.CustomDomain.Name == "" {
177-
return fmt.Errorf("name is empty in response")
176+
if customDomainResponse.CustomDomain == nil {
177+
return fmt.Errorf("CustomDomain is missing in response")
178178
}
179-
if customDomainResponse.CustomDomain.Status == "" {
180-
return fmt.Errorf("status is empty in response")
179+
180+
if customDomainResponse.CustomDomain.Name == nil {
181+
return fmt.Errorf("name is missing in response")
182+
}
183+
if customDomainResponse.CustomDomain.Status == nil {
184+
return fmt.Errorf("status missing in response")
181185
}
182186

183187
normalizedCert, err := normalizeCertificate(customDomainResponse.Certificate)
@@ -190,9 +194,9 @@ func mapCustomDomainDataSourceFields(customDomainResponse *cdnSdk.GetCustomDomai
190194
model.Certificate = types.ObjectNull(certificateDataSourceTypes)
191195
} else {
192196
// For custom certificates, we only care about the version.
193-
version := types.Int32Null()
197+
version := types.Int64Null()
194198
if normalizedCert.Version != nil {
195-
version = types.Int32Value(*normalizedCert.Version)
199+
version = types.Int64Value(*normalizedCert.Version)
196200
}
197201

198202
certificateObj, diags := types.ObjectValue(certificateDataSourceTypes, map[string]attr.Value{
@@ -204,16 +208,16 @@ func mapCustomDomainDataSourceFields(customDomainResponse *cdnSdk.GetCustomDomai
204208
model.Certificate = certificateObj
205209
}
206210

207-
model.ID = types.StringValue(fmt.Sprintf("%s,%s,%s", projectId, distributionId, customDomainResponse.CustomDomain.Name))
208-
model.Status = types.StringValue(string(customDomainResponse.CustomDomain.Status))
211+
model.ID = types.StringValue(fmt.Sprintf("%s,%s,%s", projectId, distributionId, *customDomainResponse.CustomDomain.Name))
212+
model.Status = types.StringValue(string(*customDomainResponse.CustomDomain.Status))
209213

210214
customDomainErrors := []attr.Value{}
211215
if customDomainResponse.CustomDomain.Errors != nil {
212-
for _, e := range customDomainResponse.CustomDomain.Errors {
213-
if e.En == "" {
216+
for _, e := range *customDomainResponse.CustomDomain.Errors {
217+
if e.En == nil {
214218
return fmt.Errorf("error description missing")
215219
}
216-
customDomainErrors = append(customDomainErrors, types.StringValue(e.En))
220+
customDomainErrors = append(customDomainErrors, types.StringValue(*e.En))
217221
}
218222
}
219223
modelErrors, diags := types.ListValue(types.StringType, customDomainErrors)
@@ -225,7 +229,7 @@ func mapCustomDomainDataSourceFields(customDomainResponse *cdnSdk.GetCustomDomai
225229
// Also map the fields back to the model from the config
226230
model.ProjectId = types.StringValue(projectId)
227231
model.DistributionId = types.StringValue(distributionId)
228-
model.Name = types.StringValue(customDomainResponse.CustomDomain.Name)
232+
model.Name = types.StringValue(*customDomainResponse.CustomDomain.Name)
229233

230234
return nil
231235
}

stackit/internal/services/cdn/customdomain/datasource_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
"github.com/google/go-cmp/cmp"
77
"github.com/hashicorp/terraform-plugin-framework/attr"
88
"github.com/hashicorp/terraform-plugin-framework/types"
9-
cdnSdk "github.com/stackitcloud/stackit-sdk-go/services/cdn/v1api"
9+
"github.com/stackitcloud/stackit-sdk-go/services/cdn"
1010
)
1111

1212
func TestMapDataSourceFields(t *testing.T) {
1313
emtpyErrorsList := types.ListValueMust(types.StringType, []attr.Value{})
1414

1515
// Expected certificate object when a custom certificate is returned
1616
certAttributes := map[string]attr.Value{
17-
"version": types.Int32Value(3),
17+
"version": types.Int64Value(3),
1818
}
1919
certificateObj, _ := types.ObjectValue(certificateDataSourceTypes, certAttributes)
2020

@@ -37,30 +37,30 @@ func TestMapDataSourceFields(t *testing.T) {
3737

3838
// API response fixtures for custom and managed certificates
3939
customType := "custom"
40-
customVersion := int32(3)
41-
getRespCustom := cdnSdk.GetCustomDomainResponseCertificate{
42-
GetCustomDomainCustomCertificate: &cdnSdk.GetCustomDomainCustomCertificate{
43-
Type: customType,
44-
Version: customVersion,
40+
customVersion := int64(3)
41+
getRespCustom := cdn.GetCustomDomainResponseGetCertificateAttributeType(&cdn.GetCustomDomainResponseCertificate{
42+
GetCustomDomainCustomCertificate: &cdn.GetCustomDomainCustomCertificate{
43+
Type: &customType,
44+
Version: &customVersion,
4545
},
46-
}
46+
})
4747

4848
managedType := "managed"
49-
getRespManaged := cdnSdk.GetCustomDomainResponseCertificate{
50-
GetCustomDomainManagedCertificate: &cdnSdk.GetCustomDomainManagedCertificate{
51-
Type: managedType,
49+
getRespManaged := cdn.GetCustomDomainResponseGetCertificateAttributeType(&cdn.GetCustomDomainResponseCertificate{
50+
GetCustomDomainManagedCertificate: &cdn.GetCustomDomainManagedCertificate{
51+
Type: &managedType,
5252
},
53-
}
53+
})
5454

5555
// Helper to create API response fixtures
56-
customDomainFixture := func(mods ...func(*cdnSdk.GetCustomDomainResponse)) *cdnSdk.GetCustomDomainResponse {
57-
distribution := &cdnSdk.CustomDomain{
58-
Errors: []cdnSdk.StatusError{},
59-
Name: "https://testdomain.com",
60-
Status: cdnSdk.DOMAINSTATUS_ACTIVE,
56+
customDomainFixture := func(mods ...func(*cdn.GetCustomDomainResponse)) *cdn.GetCustomDomainResponse {
57+
distribution := &cdn.CustomDomain{
58+
Errors: &[]cdn.StatusError{},
59+
Name: new("https://testdomain.com"),
60+
Status: cdn.DOMAINSTATUS_ACTIVE.Ptr(),
6161
}
62-
customDomainResponse := &cdnSdk.GetCustomDomainResponse{
63-
CustomDomain: *distribution,
62+
customDomainResponse := &cdn.GetCustomDomainResponse{
63+
CustomDomain: distribution,
6464
Certificate: getRespCustom,
6565
}
6666

@@ -72,7 +72,7 @@ func TestMapDataSourceFields(t *testing.T) {
7272

7373
// Test cases
7474
tests := map[string]struct {
75-
Input *cdnSdk.GetCustomDomainResponse
75+
Input *cdn.GetCustomDomainResponse
7676
Expected *customDomainDataSourceModel
7777
IsValid bool
7878
}{
@@ -87,7 +87,7 @@ func TestMapDataSourceFields(t *testing.T) {
8787
Expected: expectedModel(func(m *customDomainDataSourceModel) {
8888
m.Certificate = types.ObjectNull(certificateDataSourceTypes)
8989
}),
90-
Input: customDomainFixture(func(gcdr *cdnSdk.GetCustomDomainResponse) {
90+
Input: customDomainFixture(func(gcdr *cdn.GetCustomDomainResponse) {
9191
gcdr.Certificate = getRespManaged
9292
}),
9393
IsValid: true,
@@ -97,8 +97,8 @@ func TestMapDataSourceFields(t *testing.T) {
9797
m.Status = types.StringValue("ERROR")
9898
m.Certificate = certificateObj
9999
}),
100-
Input: customDomainFixture(func(d *cdnSdk.GetCustomDomainResponse) {
101-
d.CustomDomain.Status = cdnSdk.DOMAINSTATUS_ERROR
100+
Input: customDomainFixture(func(d *cdn.GetCustomDomainResponse) {
101+
d.CustomDomain.Status = cdn.DOMAINSTATUS_ERROR.Ptr()
102102
}),
103103
IsValid: true,
104104
},
@@ -109,8 +109,8 @@ func TestMapDataSourceFields(t *testing.T) {
109109
},
110110
"sad_path_name_missing": {
111111
Expected: expectedModel(),
112-
Input: customDomainFixture(func(d *cdnSdk.GetCustomDomainResponse) {
113-
d.CustomDomain.Name = ""
112+
Input: customDomainFixture(func(d *cdn.GetCustomDomainResponse) {
113+
d.CustomDomain.Name = nil
114114
}),
115115
IsValid: false,
116116
},

0 commit comments

Comments
 (0)