Skip to content

Commit

Permalink
refactor: Use bundle instead of sdk-go-dns
Browse files Browse the repository at this point in the history
  • Loading branch information
adeatcu-ionos committed Jan 28, 2025
1 parent 25ab0b6 commit 2e24511
Show file tree
Hide file tree
Showing 94 changed files with 3,888 additions and 7,064 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/iancoleman/strcase v0.3.0
github.com/ionos-cloud/sdk-go-api-gateway v1.0.0
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0
github.com/ionos-cloud/sdk-go-bundle/products/dns/v2 v2.0.1
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1
github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2 v2.0.0
github.com/ionos-cloud/sdk-go-bundle/products/vpn/v2 v2.0.2
Expand All @@ -28,7 +29,6 @@ require (
github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.1.1
github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.3
github.com/ionos-cloud/sdk-go-dns v1.2.1
github.com/ionos-cloud/sdk-go-kafka v1.0.0
github.com/ionos-cloud/sdk-go-nfs v1.1.1
github.com/ionos-cloud/sdk-go-object-storage v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ github.com/ionos-cloud/sdk-go-api-gateway v1.0.0 h1:T+JzarV1Iw7NjWQfEuv5bESnHoCL
github.com/ionos-cloud/sdk-go-api-gateway v1.0.0/go.mod h1:TkSlamP+qKRT8cgBaZEN8rawanVluOR0dXbXXdmmwTY=
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0 h1:8fRICa4i+GJHrCgnLe8t3uwfahkg7pcDDwoLkH3B2Xc=
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0/go.mod h1:BF6R+j1GdJEMImxkeh32qjIVWqsBfgi6VgyfsY5ezIA=
github.com/ionos-cloud/sdk-go-bundle/products/dns/v2 v2.0.1 h1:EeDVljI3St112cgokBdvbr/L6D0HzfLr0d/u2R71KXU=
github.com/ionos-cloud/sdk-go-bundle/products/dns/v2 v2.0.1/go.mod h1:S8SBfF2bJkW902JKSQ/O6zn3sXPgeLvaa8hUG/oycNg=
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1 h1:GXxdNKl7haQnHO1QewZeXazur5+LDCpHqvP+nNObGaA=
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1/go.mod h1:N0ifRq3ENqGg6qht1WPrVgSkcavPS5SRWlNfkHUZbfQ=
github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2 v2.0.0 h1:gVh+jd0o8ROtJLWqUB6/VU8vSLdj/kRYAz/qbMO7z7I=
Expand All @@ -138,8 +140,6 @@ github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1 h1:+tDoZ8IEPxYwJd6fDIpWksNJs9Zz
github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1/go.mod h1:rxOAeyAU6BTfghJibSRDdRNrKm2cIXMpSMe7JIWewJ8=
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.3 h1:T05nbKqBIw2zmPwaV2pWyFcUVjblLMoShPM9nAYQjLM=
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.3/go.mod h1:5cKJUIcXfMbG5vVkz6cYjnToZvaQylkLsIuhOW7PhEI=
github.com/ionos-cloud/sdk-go-dns v1.2.1 h1:Sy7Jg5trzObad9VPvEh7BgeJrIhaxdGlBEvG2aHJZH8=
github.com/ionos-cloud/sdk-go-dns v1.2.1/go.mod h1:l9gYdwtUshlBOiIi4nHn3RCX81XlV3VoNvLJrO2VfHg=
github.com/ionos-cloud/sdk-go-kafka v1.0.0 h1:S0Tfy/KlYW7UJW6DoU43fF0/iNPc1YKC+AC56G9wfA4=
github.com/ionos-cloud/sdk-go-kafka v1.0.0/go.mod h1:yIq1FjRtdcbwmybb42puagpLjmD2wbWAew8UMHO5wqU=
github.com/ionos-cloud/sdk-go-nfs v1.1.1 h1:tMMUPGKRQm2z5FTIMFoE/DJ8Xw3522T0jVutCGmsyMw=
Expand Down
8 changes: 4 additions & 4 deletions ionoscloud/data_source_dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
dns "github.com/ionos-cloud/sdk-go-dns"
dns "github.com/ionos-cloud/sdk-go-bundle/products/dns/v2"
)

func dataSourceDNSRecord() *schema.Resource {
Expand Down Expand Up @@ -110,7 +110,7 @@ func dataSourceRecordRead(ctx context.Context, d *schema.ResourceData, meta inte
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while fetching DNS Records: %w", err))
}
results = *records.Items
results = records.Items
} else {
// In order to have an exact name match, we must retrieve all the DNS Records and then
// build a list of exact matches based on the response, there is no other way since using
Expand All @@ -119,13 +119,13 @@ func dataSourceRecordRead(ctx context.Context, d *schema.ResourceData, meta inte
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while fetching DNS Records: %w", err))
}
for _, recordItem := range *records.Items {
for _, recordItem := range records.Items {
// Since each record has a unique name, there is no need to keep on searching if
// we already found the required record.
if len(results) == 1 {
break
}
if recordItem.Properties != nil && recordItem.Properties.Name != nil && strings.EqualFold(*recordItem.Properties.Name, recordName) {
if strings.EqualFold(recordItem.Properties.Name, recordName) {
results = append(results, recordItem)
}
}
Expand Down
8 changes: 4 additions & 4 deletions ionoscloud/data_source_dns_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
dns "github.com/ionos-cloud/sdk-go-dns"
dns "github.com/ionos-cloud/sdk-go-bundle/products/dns/v2"
)

func dataSourceDNSZone() *schema.Resource {
Expand Down Expand Up @@ -95,7 +95,7 @@ func dataSourceZoneRead(ctx context.Context, d *schema.ResourceData, meta interf
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while fetching DNS Zones: %w", err))
}
results = *zones.Items
results = zones.Items
} else {
// In order to have an exact name match, we must retrieve all the DNS Zones and then
// build a list of exact matches based on the response, there is no other way since using
Expand All @@ -104,13 +104,13 @@ func dataSourceZoneRead(ctx context.Context, d *schema.ResourceData, meta interf
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while fetching DNS Zones: %w", err))
}
for _, zoneItem := range *zones.Items {
for _, zoneItem := range zones.Items {
// Since each zone has a unique name, there is no need to keep on searching if
// we already found the required zone.
if len(results) == 1 {
break
}
if zoneItem.Properties != nil && zoneItem.Properties.ZoneName != nil && strings.EqualFold(*zoneItem.Properties.ZoneName, name) {
if strings.EqualFold(zoneItem.Properties.ZoneName, name) {
results = append(results, zoneItem)
}
}
Expand Down
28 changes: 11 additions & 17 deletions ionoscloud/resource_dns_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
dns "github.com/ionos-cloud/sdk-go-dns"
dns "github.com/ionos-cloud/sdk-go-bundle/products/dns/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
)
Expand Down Expand Up @@ -75,17 +75,13 @@ func recordCreate(ctx context.Context, d *schema.ResourceData, meta interface{})
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while creating a record for the DNS zone with ID: %s, error: %w", zoneId, err))
}
if recordResponse.Metadata == nil {
return diag.FromErr(fmt.Errorf("expected metadata in the response for the record with ID: %s, but received 'nil' instead", *recordResponse.Id))
}
if recordResponse.Metadata.State != nil {
if *recordResponse.Metadata.State == dns.PROVISIONINGSTATE_FAILED {
// This is a temporary error message since right now the API is not returning errors that we can work with.
return diag.FromErr(fmt.Errorf("record creation has failed, this can happen if the data in the request is not correct, " +
"please check again the values defined in the plan"))
}

if recordResponse.Metadata.State == dns.PROVISIONINGSTATE_FAILED {
// This is a temporary error message since right now the API is not returning errors that we can work with.
return diag.FromErr(fmt.Errorf("record creation has failed, this can happen if the data in the request is not correct, " +
"please check again the values defined in the plan"))
}
d.SetId(*recordResponse.Id)
d.SetId(recordResponse.Id)
return recordRead(ctx, d, meta)
}

Expand Down Expand Up @@ -118,12 +114,10 @@ func recordUpdate(ctx context.Context, d *schema.ResourceData, meta interface{})
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while updating the DNS Record with ID: %s, zone ID: %s, error: %w", recordId, zoneId, err))
}
if recordResponse.Metadata.State != nil {
if *recordResponse.Metadata.State == dns.PROVISIONINGSTATE_FAILED {
// This is a temporary error message since right now the API is not returning errors that we can work with.
return diag.FromErr(fmt.Errorf("record update has failed, this can happen if the data in the request is not correct, " +
"please check again the values defined in the plan"))
}
if recordResponse.Metadata.State == dns.PROVISIONINGSTATE_FAILED {
// This is a temporary error message since right now the API is not returning errors that we can work with.
return diag.FromErr(fmt.Errorf("record update has failed, this can happen if the data in the request is not correct, " +
"please check again the values defined in the plan"))
}
return recordRead(ctx, d, meta)
}
Expand Down
2 changes: 1 addition & 1 deletion ionoscloud/resource_dns_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
dns "github.com/ionos-cloud/sdk-go-dns"
dns "github.com/ionos-cloud/sdk-go-bundle/products/dns/v2"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
)
Expand Down
24 changes: 10 additions & 14 deletions ionoscloud/resource_dns_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
dns "github.com/ionos-cloud/sdk-go-dns"
dns "github.com/ionos-cloud/sdk-go-bundle/products/dns/v2"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
)
Expand Down Expand Up @@ -57,14 +57,12 @@ func zoneCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) d
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while creating a DNS Zone: %w", err))
}
if zoneResponse.Metadata.State != nil {
if *zoneResponse.Metadata.State == dns.PROVISIONINGSTATE_FAILED {
// This is a temporary error message since right now the API is not returning errors that we can work with.
return diag.FromErr(fmt.Errorf("zone creation has failed, this can happen if the data in the request is not correct, " +
"please check again the values defined in the plan"))
}
if zoneResponse.Metadata.State == dns.PROVISIONINGSTATE_FAILED {
// This is a temporary error message since right now the API is not returning errors that we can work with.
return diag.FromErr(fmt.Errorf("zone creation has failed, this can happen if the data in the request is not correct, " +
"please check again the values defined in the plan"))
}
d.SetId(*zoneResponse.Id)
d.SetId(zoneResponse.Id)
return zoneRead(ctx, d, meta)
}

Expand Down Expand Up @@ -98,12 +96,10 @@ func zoneUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) d
if err != nil {
return diag.FromErr(fmt.Errorf("an error occurred while updating the DNS Zone with ID: %s, error: %w", zoneId, err))
}
if zoneResponse.Metadata.State != nil {
if *zoneResponse.Metadata.State == dns.PROVISIONINGSTATE_FAILED {
// This is a temporary error message since right now the API is not returning errors that we can work with.
return diag.FromErr(fmt.Errorf("zone update has failed, this can happen if the data in the request is not correct, " +
"please check again the values defined in the plan"))
}
if zoneResponse.Metadata.State == dns.PROVISIONINGSTATE_FAILED {
// This is a temporary error message since right now the API is not returning errors that we can work with.
return diag.FromErr(fmt.Errorf("zone update has failed, this can happen if the data in the request is not correct, " +
"please check again the values defined in the plan"))
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion ionoscloud/resource_dns_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
dns "github.com/ionos-cloud/sdk-go-dns"
dns "github.com/ionos-cloud/sdk-go-bundle/products/dns/v2"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
)
Expand Down
20 changes: 10 additions & 10 deletions services/dns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ package dns
import (
"fmt"
"net/http"
"os"
"runtime"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"

"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
dns "github.com/ionos-cloud/sdk-go-dns"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
dns "github.com/ionos-cloud/sdk-go-bundle/products/dns/v2"
"github.com/ionos-cloud/sdk-go-bundle/shared"
)

type Client struct {
sdkClient dns.APIClient
}

func NewClient(username, password, token, url, version, terraformVersion string, insecure bool) *Client {
newConfigDNS := dns.NewConfiguration(username, password, token, url)
newConfigDNS := shared.NewConfiguration(username, password, token, url)

if os.Getenv(constant.IonosDebug) != "" {
newConfigDNS.Debug = true
}
newConfigDNS.MaxRetries = constant.MaxRetries
newConfigDNS.MaxWaitTime = constant.MaxWaitTime
newConfigDNS.HTTPClient = &http.Client{Transport: utils.CreateTransport(insecure)}
newConfigDNS.UserAgent = fmt.Sprintf(
"terraform-provider/%s_ionos-cloud-sdk-go-dns/%s_hashicorp-terraform/%s_terraform-plugin-sdk/%s_os/%s_arch/%s",
version, dns.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH) //nolint:staticcheck
client := &Client{
sdkClient: *dns.NewAPIClient(newConfigDNS),
}
client.sdkClient.GetConfig().HTTPClient = &http.Client{Transport: utils.CreateTransport(insecure)}

return &Client{sdkClient: *dns.NewAPIClient(newConfigDNS)}
return client
}
Loading

0 comments on commit 2e24511

Please sign in to comment.