@@ -13,6 +13,20 @@ import (
1313 "github.com/scaleway/scaleway-sdk-go/scw"
1414)
1515
16+ var changeKeys = []string {
17+ "geo_ip" ,
18+ "name" ,
19+ "data" ,
20+ "priority" ,
21+ "ttl" ,
22+ "type" ,
23+ "http_service" ,
24+ "weighted" ,
25+ "view" ,
26+ "dns_zone" ,
27+ "keep_empty_zone" ,
28+ }
29+
1630func resourceScalewayDomainRecord () * schema.Resource {
1731 return & schema.Resource {
1832 CreateContext : resourceScalewayDomainRecordCreate ,
@@ -412,60 +426,28 @@ func resourceScalewayDomainRecordRead(ctx context.Context, d *schema.ResourceDat
412426}
413427
414428func resourceScalewayDomainRecordUpdate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
429+ if ! d .HasChanges (changeKeys ... ) {
430+ return resourceScalewayDomainRecordRead (ctx , d , meta )
431+ }
432+
415433 domainAPI := newDomainAPI (meta )
416434
417435 req := & domain.UpdateDNSZoneRecordsRequest {
418436 DNSZone : d .Get ("dns_zone" ).(string ),
419437 ReturnAllRecords : scw .BoolPtr (false ),
420438 }
421439
422- record := & domain.Record {Name : d .Get ("name" ).(string )}
423- hasChange := false
424- if d .HasChanges ("geo_ip" ) {
425- if geoIP , ok := d .GetOk ("geo_ip" ); ok {
426- record .GeoIPConfig = expandDomainGeoIPConfig (d .Get ("data" ).(string ), geoIP , ok )
427- }
428- hasChange = true
429- }
430-
431- if d .HasChange ("name" ) {
432- record .Name = d .Get ("name" ).(string )
433- hasChange = true
434- }
435-
436- if d .HasChange ("data" ) {
437- record .Data = d .Get ("data" ).(string )
438- hasChange = true
439- }
440-
441- if d .HasChange ("priority" ) {
442- record .Priority = uint32 (d .Get ("priority" ).(int ))
443- hasChange = true
444- }
445-
446- if d .HasChange ("ttl" ) {
447- record .TTL = uint32 (d .Get ("ttl" ).(int ))
448- hasChange = true
449- }
450-
451- if d .HasChange ("type" ) {
452- record .Type = domain .RecordType (d .Get ("type" ).(string ))
453- hasChange = true
454- }
455-
456- if d .HasChanges ("http_service" ) {
457- record .HTTPServiceConfig = expandDomainHTTPService (d .GetOk ("http_service" ))
458- hasChange = true
459- }
460-
461- if d .HasChanges ("weighted" ) {
462- record .WeightedConfig = expandDomainWeighted (d .GetOk ("weighted" ))
463- hasChange = true
464- }
465-
466- if d .HasChanges ("view" ) {
467- record .ViewConfig = expandDomainView (d .GetOk ("view" ))
468- hasChange = true
440+ geoIP , okGeoIP := d .GetOk ("geo_ip" )
441+ record := & domain.Record {
442+ Name : d .Get ("name" ).(string ),
443+ Data : d .Get ("data" ).(string ),
444+ Priority : uint32 (d .Get ("priority" ).(int )),
445+ TTL : uint32 (d .Get ("ttl" ).(int )),
446+ Type : domain .RecordType (d .Get ("type" ).(string )),
447+ GeoIPConfig : expandDomainGeoIPConfig (d .Get ("data" ).(string ), geoIP , okGeoIP ),
448+ HTTPServiceConfig : expandDomainHTTPService (d .GetOk ("http_service" )),
449+ WeightedConfig : expandDomainWeighted (d .GetOk ("weighted" )),
450+ ViewConfig : expandDomainView (d .GetOk ("view" )),
469451 }
470452
471453 req .Changes = []* domain.RecordChange {
@@ -477,16 +459,14 @@ func resourceScalewayDomainRecordUpdate(ctx context.Context, d *schema.ResourceD
477459 },
478460 }
479461
480- if hasChange || d .HasChanges ("dns_zone" , "keep_empty_zone" ) {
481- _ , err := domainAPI .UpdateDNSZoneRecords (req )
482- if err != nil {
483- return diag .FromErr (err )
484- }
462+ _ , err := domainAPI .UpdateDNSZoneRecords (req )
463+ if err != nil {
464+ return diag .FromErr (err )
465+ }
485466
486- _ , err = waitForDNSRecordExist (ctx , domainAPI , d .Get ("dns_zone" ).(string ), record .Name , record .Type , d .Timeout (schema .TimeoutUpdate ))
487- if err != nil {
488- return diag .FromErr (err )
489- }
467+ _ , err = waitForDNSRecordExist (ctx , domainAPI , d .Get ("dns_zone" ).(string ), record .Name , record .Type , d .Timeout (schema .TimeoutUpdate ))
468+ if err != nil {
469+ return diag .FromErr (err )
490470 }
491471
492472 return resourceScalewayDomainRecordRead (ctx , d , meta )
0 commit comments