Skip to content

Commit

Permalink
CDI-705: fix the Origin Shielding resource creating and destroying (#107
Browse files Browse the repository at this point in the history
)
  • Loading branch information
andrei-lukyanchyk authored May 16, 2024
1 parent 91585fc commit 7f93bb0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions gcore/resource_gcore_cdn_origin_shielding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package gcore

import (
"context"
"fmt"
"log"
"strconv"

"github.com/AlekSi/pointer"
"github.com/G-Core/gcorelabscdn-go/originshielding"
Expand Down Expand Up @@ -36,7 +38,11 @@ func resourceCDNOriginShielding() *schema.Resource {
}

func resourceCDNOriginShieldingRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
resourceID := d.Get("resource_id").(int)
resourceID, err := strconv.Atoi(d.Id())
if err != nil {
return diag.Errorf("Failed reading: wrong input id: %s", d.Id())
}

log.Printf("[DEBUG] Start CDN Origin Shielding reading (id=%d)\n", resourceID)
config := m.(*Config)
client := config.CDNClient
Expand Down Expand Up @@ -68,9 +74,11 @@ func resourceCDNOriginShieldingUpdate(ctx context.Context, d *schema.ResourceDat
return diag.FromErr(err)
}

log.Printf("[DEBUG] Finish CDN Origin Shielding updating")
d.SetId(fmt.Sprintf("%d", resourceID))
resourceCDNOriginShieldingRead(ctx, d, m)

return resourceCDNOriginShieldingRead(ctx, d, m)
log.Printf("[DEBUG] Finish CDN Origin Shielding updating")
return nil
}

func resourceCDNOriginShieldingDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
Expand All @@ -87,7 +95,7 @@ func resourceCDNOriginShieldingDelete(ctx context.Context, d *schema.ResourceDat
return diag.FromErr(err)
}

d.SetId("")
log.Printf("[DEBUG] Finish CDN Origin Shielding deleting")

return nil
}

0 comments on commit 7f93bb0

Please sign in to comment.