'Delete a Cloudflare zone
I'm currently working on a terraform script which creates a cloudflare zone and make some configurations and if user sets a boolean variable to true I need to delete this cloudflare zone. This cloudflare zone is in the enterprise plan. Can any of you help me to delete this cloudflare zone using my terraform script? I can downgrade the plan to free plan using a api request to cloudflare.
Is there any terraform function which can be used to delete a zone?
Code
resource "cloudflare_zone" "cloudflarecreatezone" {
count = var.delete ? 0 : 1
jump_start = "true"
zone = var.zone_name
type = "partial"
plan = "enterprise"
}
resource "cloudflare_waf_group" "Cloudflare_Joomla" {
count = var.delete ? 0 : 1
group_id = "dc85d7a0s342918s886s32056069dfa94"
zone_id = cloudflare_zone.cloudflarecreatezone[count.index].id
mode = "off"
}
resource "null_resource" "dg" {
count = var.delete ? 1 : 0
provisioner "local-exec" {
command = "id=curl -s -k -X GET
'https://api.cloudflare.com/client/v4/zones/?name=${var.zone_name}' -H \"X-Auth-Email: ${var.email}\" -H \"X-Auth-Key: ${var.api_key}\" -H \"Content-Type: application/json\"|awk -F ':' '{print $3}'|awk -F '\"' '{print $2}';curl -s -k -X PATCH -d '{\"plan\":{\"id\":\"0feeeeeeeeeeeeeeeeeeeeeeeeeeeeee\"}}' 'api.cloudflare.com/client/v4/zones/'$id -H \"X-Auth-Email: ${var.email}\" -H \"X-Auth-Key: ${var.api_key}\" -H \"Content-Type: application/json\"" interpreter = ["/bin/bash", "-c"]
}
}
resource "null_resource" "delete_zone" {
count = var.delete ? 1 : 0
}
TIA
I expect my script to be able to delete the cloudflare zone once the delete variable is set to true
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
