Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error re-adding recently removed domains #113

Open
cbrnit opened this issue Oct 9, 2024 · 2 comments
Open

Error re-adding recently removed domains #113

cbrnit opened this issue Oct 9, 2024 · 2 comments

Comments

@cbrnit
Copy link

cbrnit commented Oct 9, 2024

octodns 1.10
octodns-cloudflare 0.0.7
On Windows Server 2022 with Python 3.12.4

When I try to sync a domain to Cloudflare that was previously in Cloudflare and was recently removed I get an error:

[4540] INFO  CloudflareProvider[cloudflare] apply: making 2 changes to exampledomain.com.
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\Applications\Executables\OctoDNS\env\Scripts\octodns-sync.exe\__main__.py", line 7, in <module>
  File "D:\Applications\Executables\OctoDNS\env\Lib\site-packages\octodns\cmds\sync.py", line 62, in main
    manager.sync(
  File "D:\Applications\Executables\OctoDNS\env\Lib\site-packages\octodns\manager.py", line 856, in sync
    total_changes += target.apply(plan)
                     ^^^^^^^^^^^^^^^^^^
  File "D:\Applications\Executables\OctoDNS\env\Lib\site-packages\octodns\provider\base.py", line 298, in apply
    self._apply(plan)
  File "D:\Applications\Executables\OctoDNS\env\Lib\site-packages\octodns_cloudflare\__init__.py", line 1107, in _apply
    getattr(self, f'_apply_{class_name}')(change)
  File "D:\Applications\Executables\OctoDNS\env\Lib\site-packages\octodns_cloudflare\__init__.py", line 920, in _apply_Create
    self._try_request('POST', path, data=content)
  File "D:\Applications\Executables\OctoDNS\env\Lib\site-packages\octodns_cloudflare\__init__.py", line 131, in _try_request
    return self._request(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Applications\Executables\OctoDNS\env\Lib\site-packages\octodns_cloudflare\__init__.py", line 154, in _request
    raise CloudflareError(resp.json())
octodns_cloudflare.CloudflareError: A record with the same settings already exists.

It seems that when a recently removed domain is re-added to Cloudflare it is put back with its records intact. I confirmed that by manually re-adding a domain in the Cloudflare Dash to find previously entered DNS records. When OctoDNS tries to sync a recently removed zone it errors because the recreated zone already contains records that OctoDNS is trying to add.

@ross
Copy link
Contributor

ross commented Oct 9, 2024

It seems that when a recently removed domain is re-added to Cloudflare it is put back with its records intact.

Weird. I'm not sure how the provider could handle that situation since it would have no clue what state the previous zone was in or whether there even was a previous state or not.

It would require another plan cycle after (re)creating the zone to see what actually needs to happen which would violate the whole idea of planning and applying being separate steps.

Only thing I can think of that would work cleanly would be to list the zone's records immediately after creating it and then go through and delete them all before doing the apply. That would get to the right end state and conceptually follow the plan, but it's pretty ugly and could involve A LOT of churn on a large zone.

Short of that it could check to see if the zone has any records after the create and throw an error if it does saying what's up and that another plan and apply should be done.

None of the options seems great. Would be nice if CF supported a create option that created things empty.

@cbrnit
Copy link
Author

cbrnit commented Dec 19, 2024

I was able to work around the issue by adding a step to my implementation that re-adds any missing domains before invoking octodns. I maintain zone synchronization outside of octodns and only rely on octodns to sync records.

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

No branches or pull requests

2 participants