Skip to content

Conversation

@tlimoncelli
Copy link
Collaborator

No description provided.

allixsenos and others added 6 commits January 27, 2026 17:22
Add support for Cloudflare's per-record CNAME flattening feature using
CF_CNAME_FLATTEN_ON and CF_CNAME_FLATTEN_OFF modifiers, similar to the
existing CF_PROXY_ON/OFF pattern.

CNAME flattening resolves CNAME targets to their IP addresses at
Cloudflare's edge, which can improve performance and compatibility.
This feature requires a paid Cloudflare plan (Pro, Business, or
Enterprise).

New record modifiers for CNAME records:
- CF_CNAME_FLATTEN_ON: Enable CNAME flattening for the record
- CF_CNAME_FLATTEN_OFF: Disable CNAME flattening (default)

Example usage:
```javascript
D("example.com", REG, DSP,
    CNAME("cdn", "cdn.provider.com.", CF_CNAME_FLATTEN_ON),
    CNAME("www", "www.example.com.", CF_CNAME_FLATTEN_OFF),
);
```

- Uses Cloudflare API's `settings.flatten_cname` field (not tags, as
  the `cf-flatten-cname` tag is reserved by Cloudflare)
- Stores state in record metadata as `cloudflare_cname_flatten`
- Only applies to CNAME record types
- Integrated with diff detection via genComparable()

- pkg/js/helpers.js: Add CF_CNAME_FLATTEN_ON/OFF constants
- commands/types/others.d.ts: Add TypeScript declarations for IDE support
- providers/cloudflare/cloudflareProvider.go:
  - Add metaCNAMEFlatten constant
  - Add checkCNAMEFlattenVal() validation function
  - Update preprocessConfig() to validate CNAME flatten setting
  - Update nativeToRecord() to read settings.flatten_cname from API
  - Update genComparable() to include flatten state in diff comparison
- providers/cloudflare/rest.go:
  - Update createRecDiff2() to set Settings.FlattenCNAME
  - Update modifyRecord() to set Settings.FlattenCNAME
- commands/getZones.go:
  - Update TSV export to include cloudflare_cname_flatten metadata
  - Update JS/DJS export to include CF_CNAME_FLATTEN_ON modifier
- pkg/prettyzone/prettyzone.go:
  - Update zone file export to include CF_CNAME_FLATTEN_ON comment

Added gated integration tests that are disabled by default since CNAME
flattening requires a paid plan:
- integrationTest/helpers_test.go: Add -cfflatten flag (default false)
- integrationTest/helpers_integration_test.go: Add test helper functions
- integrationTest/integration_test.go: Add CF_CNAME_FLATTEN test groups

Run tests on paid zones with: go test -v -provider=CLOUDFLAREAPI -cfflatten=true

Updated documentation/provider/cloudflareapi.md with:
- New CNAME flattening section with usage examples
- Warning about paid plan requirement
- Integration test flag documentation
Use of unsigned integer conflicts with assumptions of `stringer`
generated code.

---------

Co-authored-by: Tom Limoncelli <6293917+tlimoncelli@users.noreply.github.com>
…4016)

Quieten [`staticcheck`](https://staticcheck.dev) for error message with
a capital. Ideally advice would be returned to the user by another
means.

---------

Co-authored-by: Tom Limoncelli <6293917+tlimoncelli@users.noreply.github.com>
<!--
## Before submiting a pull request

Please make sure you've run the following commands from the root
directory.

    bin/generate-all.sh

(this runs commands like "go generate", fixes formatting, and so on)

## Release changelog section

Help keep the release changelog clear by pre-naming the proper section
in the GitHub pull request title.

Some examples:
* CICD: Add required GHA permissions for goreleaser
* DOCS: Fixed providers with "contributor support" table
* ROUTE53: Allow R53_ALIAS records to enable target health evaluation

More examples/context can be found in the file .goreleaser.yml under the
'build' > 'changelog' key.
!-->
@tlimoncelli tlimoncelli marked this pull request as draft January 27, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants