diff --git a/internal/provider/resource_cloudflare_managed_headers.go b/internal/provider/resource_cloudflare_managed_headers.go index 55a7ddc78e5..aca11c2363e 100644 --- a/internal/provider/resource_cloudflare_managed_headers.go +++ b/internal/provider/resource_cloudflare_managed_headers.go @@ -33,34 +33,17 @@ func resourceCloudflareManagedHeadersCreate(ctx context.Context, d *schema.Resou func resourceCloudflareManagedHeadersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*cloudflare.API) zoneID := d.Get("zone_id").(string) - headers, err := client.ListZoneManagedHeaders(ctx, cloudflare.ListManagedHeadersParams{ - ZoneID: zoneID, + headers, err := client.ListZoneManagedHeaders(ctx, client.ZoneIdentifier(zoneID), cloudflare.ListManagedHeadersParams{ + OnlyEnabled: true, }) if err != nil { return diag.FromErr(fmt.Errorf("error reading managed headers: %w", err)) } - // Filter out headers that are not enabled. This will eventually move into - // the API endpoint or the SDK. - var enabledRequestHeaders []cloudflare.ManagedHeader - var enabledResponseHeaders []cloudflare.ManagedHeader - - for _, header := range headers.ManagedRequestHeaders { - if header.Enabled { - enabledRequestHeaders = append(enabledRequestHeaders, header) - } - } - - for _, header := range headers.ManagedResponseHeaders { - if header.Enabled { - enabledResponseHeaders = append(enabledResponseHeaders, header) - } - } - - if err := d.Set("managed_request_headers", buildResourceFromManagedHeaders(enabledRequestHeaders)); err != nil { + if err := d.Set("managed_request_headers", buildResourceFromManagedHeaders(headers.ManagedRequestHeaders)); err != nil { return diag.FromErr(err) } - if err := d.Set("managed_response_headers", buildResourceFromManagedHeaders(enabledResponseHeaders)); err != nil { + if err := d.Set("managed_response_headers", buildResourceFromManagedHeaders(headers.ManagedResponseHeaders)); err != nil { return diag.FromErr(err) } return nil @@ -151,8 +134,8 @@ func resourceCloudflareManagedHeadersDelete(ctx context.Context, d *schema.Resou client := meta.(*cloudflare.API) zoneID := d.Get("zone_id").(string) - headers, err := client.ListZoneManagedHeaders(ctx, cloudflare.ListManagedHeadersParams{ - ZoneID: zoneID, + headers, err := client.ListZoneManagedHeaders(ctx, client.ZoneIdentifier(zoneID), cloudflare.ListManagedHeadersParams{ + OnlyEnabled: true, }) if err != nil { return diag.FromErr(fmt.Errorf("error reading managed headers: %w", err)) diff --git a/internal/provider/resource_cloudflare_managed_headers_test.go b/internal/provider/resource_cloudflare_managed_headers_test.go index 38a39008731..90491ad8f80 100644 --- a/internal/provider/resource_cloudflare_managed_headers_test.go +++ b/internal/provider/resource_cloudflare_managed_headers_test.go @@ -31,8 +31,8 @@ func testSweepCloudflareManagedHeaders(r string) error { return errors.New("CLOUDFLARE_ZONE_ID must be set") } - managedHeaders, err := client.ListZoneManagedHeaders(context.Background(), cloudflare.ListManagedHeadersParams{ - ZoneID: zoneID, + managedHeaders, err := client.ListZoneManagedHeaders(context.Background(), client.ZoneIdentifier(zoneID), cloudflare.ListManagedHeadersParams{ + OnlyEnabled: true, }) if err != nil { tflog.Error(ctx, fmt.Sprintf("Failed to fetch Cloudflare Zone Managed Headers: %s", err))