diff --git a/.changelog/1451.txt b/.changelog/1451.txt new file mode 100644 index 0000000000..3ee1068535 --- /dev/null +++ b/.changelog/1451.txt @@ -0,0 +1,3 @@ +```release-note:bug +cloudflare_argo_tunnel: conditionally fetch settings based on the provided configuration +``` diff --git a/cloudflare/resource_cloudflare_argo.go b/cloudflare/resource_cloudflare_argo.go index 3ea941813d..c784e22fb5 100644 --- a/cloudflare/resource_cloudflare_argo.go +++ b/cloudflare/resource_cloudflare_argo.go @@ -26,6 +26,8 @@ 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) @@ -33,20 +35,24 @@ func resourceCloudflareArgoRead(d *schema.ResourceData, meta interface{}) error 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 }