octodns / octodns-cloudflare

Cloudflare DNS provider for octoDNS
MIT License
24 stars 18 forks source link

Support creating zones in a specific account #72

Closed austinylin closed 10 months ago

austinylin commented 10 months ago

This PR adds support for creating zones in a specific Cloudflare account (as specified by the existing account_id param on the provider config).

With this change, when account_id is set on the provider it's included in the POST request to /zones when creating a new zone:

curl --request POST \
  --url https://api.cloudflare.com/client/v4/zones \
  --header 'Authorization: Bearer my-fake-cf-token' \
  --header 'Content-Type: application/json' \
  --data '{
  "account": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353"
  },
  "name": "example.com",
  "type": "full"
}'

(https://developers.cloudflare.com/api/operations/zones-post)

This resolves a current issue whereby new zones are created in the wrong account when the api token isn't created on the account where the zone is intended to be created.

As an example, say that Contoso Inc has a Cloudflare organization/account and adds Alice as an authorized administrator. Alice sets up an api token under her alice@contoso.com Cloudflare user account. If Alice uses octodns to create a new zone, the zone will be created in Alice's account not Contoso Inc's account as desired because Cloudflare interprets a request to create a zone without an account_id as a request to create it on the current user's account.

With this change, if account_id is set to the Contoso Inc's account, the zone is properly created on the Contoso Inc account.