Skip to content

Commit

Permalink
Merge pull request #1451 from cloudflare/conditionally-fetch-argo-set…
Browse files Browse the repository at this point in the history
…tings

argo_tunnel: conditionally fetch setting for `Read`
  • Loading branch information
jacobbednarz authored Feb 13, 2022
2 parents 3398b53 + 44abfd7 commit 144b595
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/1451.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cloudflare_argo_tunnel: conditionally fetch settings based on the provided configuration
```
24 changes: 15 additions & 9 deletions cloudflare/resource_cloudflare_argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,33 @@ func resourceCloudflareArgo() *schema.Resource {
func resourceCloudflareArgoRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)
zoneID := d.Get("zone_id").(string)
tieredCaching := d.Get("tiered_caching").(string)
smartRouting := d.Get("smart_routing").(string)

log.Printf("[DEBUG] zone ID: %s", zoneID)

checksum := stringChecksum(fmt.Sprintf("%s/argo", zoneID))
d.SetId(checksum)
d.Set("zone_id", zoneID)

tieredCaching, err := client.ArgoTieredCaching(context.Background(), zoneID)
if err != nil {
return errors.Wrap(err, "failed to get tiered caching setting")
if tieredCaching != "" {
tieredCaching, err := client.ArgoTieredCaching(context.Background(), zoneID)
if err != nil {
return errors.Wrap(err, "failed to get tiered caching setting")
}

d.Set("tiered_caching", tieredCaching.Value)
}

d.Set("tiered_caching", tieredCaching.Value)
if smartRouting != "" {
smartRouting, err := client.ArgoSmartRouting(context.Background(), zoneID)
if err != nil {
return errors.Wrap(err, "failed to get smart routing setting")
}

smartRouting, err := client.ArgoSmartRouting(context.Background(), zoneID)
if err != nil {
return errors.Wrap(err, "failed to get smart routing setting")
d.Set("smart_routing", smartRouting.Value)
}

d.Set("smart_routing", smartRouting.Value)

return nil
}

Expand Down

0 comments on commit 144b595

Please sign in to comment.