@@ -40,6 +40,17 @@ func newHostingAPIWithRegion(d *schema.ResourceData, m interface{}) (*webhosting
4040 return api , region , nil
4141}
4242
43+ func newDnsAPIWithRegion (d * schema.ResourceData , m interface {}) (* webhosting.DnsAPI , scw.Region , error ) {
44+ api := webhosting .NewDnsAPI (meta .ExtractScwClient (m ))
45+
46+ region , err := meta .ExtractRegion (d , m )
47+ if err != nil {
48+ return nil , "" , err
49+ }
50+
51+ return api , region , nil
52+ }
53+
4354// NewAPIWithRegionAndID returns a Hosting API with region and ID extracted from the state.
4455func NewAPIWithRegionAndID (m interface {}, id string ) (* webhosting.HostingAPI , scw.Region , string , error ) {
4556 api := webhosting .NewHostingAPI (meta .ExtractScwClient (m ))
@@ -65,3 +76,30 @@ func waitForHosting(ctx context.Context, api *webhosting.HostingAPI, region scw.
6576 RetryInterval : & retryInterval ,
6677 }, scw .WithContext (ctx ))
6778}
79+
80+ func flattenDNSRecords (records []* webhosting.DNSRecord ) []map [string ]interface {} {
81+ result := []map [string ]interface {}{}
82+ for _ , r := range records {
83+ result = append (result , map [string ]interface {}{
84+ "name" : r .Name ,
85+ "type" : r .Type .String (),
86+ "ttl" : r .TTL ,
87+ "value" : r .Value ,
88+ "priority" : r .Priority ,
89+ "status" : r .Status .String (),
90+ })
91+ }
92+ return result
93+ }
94+
95+ func flattenNameServers (servers []* webhosting.Nameserver ) []map [string ]interface {} {
96+ result := []map [string ]interface {}{}
97+ for _ , s := range servers {
98+ result = append (result , map [string ]interface {}{
99+ "hostname" : s .Hostname ,
100+ "status" : s .Status .String (),
101+ "is_default" : s .IsDefault ,
102+ })
103+ }
104+ return result
105+ }
0 commit comments