codekaizen-github / cloudflare-ansible-collection

GNU General Public License v3.0
0 stars 0 forks source link

Create a cloudflare_zone_settings_ssl module #9

Open AndrewJDawes opened 2 days ago

AndrewJDawes commented 2 days ago

In Cloudflare dashboard UI, we can change settings for a Zone. One of the settings we can change is the SSL setting that is used for that Zone.

https://img001.prntscr.com/file/img001/I1isrnU-RYywhKAStV04IA.png

The Cloudflare API exposes access to this SSL setting (and other settings). See the docs.

We would like an Ansible module that will allow us to fetch (state: fetched), create (state: present), and update (state: present) the ssl setting for a Zone using the Cloudflare API.

Here is an example (using curl) of how you can currently use the Cloudflare API to get settings.

# List your zones. Use the `name` query param to retrieve your zone by name.
curl --request GET \
  --url https://api.cloudflare.com/client/v4/zones?name={ YOUR_DOMAIN_NAME } \
  --header 'Authorization: Bearer { YOUR_TOKEN_HERE }' \
  --header 'Content-Type: application/json'

# List all the Zone's settings (not needed if only wanting to edit `ssl`, but helpful to visualize). Use the Zone ID from the previous request.
curl --request GET \
  --url https://api.cloudflare.com/client/v4/zones/{ YOUR_ZONE_ID_HERE }/settings \
  --header 'Authorization: Bearer { YOUR_TOKEN_HERE }' \
  --header 'Content-Type: application/json'

# Get the Zone's SSL setting
curl --request GET \
  --url https://api.cloudflare.com/client/v4/zones/{ YOUR_ZONE_ID_HERE }/settings/ssl \
  --header 'Authorization: Bearer { YOUR_TOKEN_HERE }' \
  --header 'Content-Type: application/json'

# Update the Zone's SSL setting to `full`.
curl --request PATCH \
  --url https://api.cloudflare.com/client/v4/zones/{ YOUR_ZONE_ID_HERE }/settings/ssl \
  --header 'Authorization: Bearer { YOUR_TOKEN_HERE }' \
  --header 'Content-Type: application/json' \
  --data '{
  "value": "full"
}'

Thanks!

AndrewJDawes commented 2 days ago

@kwyland22 - hoping you could take on this one! Please let me know if you have any questions. Feel free to drop them directly in Slack!