Cloudflare のゾーン削除・プラン変更

# ゾーン削除

## Free / Pro / Business Plan

### GUI

あり

![image-20211007170253015](https://cdn.jsdelivr.net/gh/kyouheicf/image@master/uPic/image-20211007170253015.png)
![image-20211007170323827](https://cdn.jsdelivr.net/gh/kyouheicf/image@master/uPic/image-20211007170323827.png)

### API

あり

https://api.cloudflare.com/#zone-delete-zone

```shell
export EMAIL='YOUR_EMAIL'
export APIKEY='YOUR_APIKEY'
export ZONE_ID='YOUR_ZONE_ID'

% curl -s -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID" \
     -H "X-Auth-Email: $EMAIL" \
     -H "X-Auth-Key: $APIKEY" \
     -H "Content-Type: application/json" | jq
{
  "result": {
    "id": "xxxxxx"
  },
  "success": true,
  "errors": [],
  "messages": []
}
```



![image-20211008020556025](https://cdn.jsdelivr.net/gh/kyouheicf/image@master/uPic/image-20211008020556025.png)

## Enterprise Plan

### GUI

なし

![image-20211007170544041](https://cdn.jsdelivr.net/gh/kyouheicf/image@master/uPic/image-20211007170544041.png)
![image-20211007170559233](https://cdn.jsdelivr.net/gh/kyouheicf/image@master/uPic/image-20211007170559233.png)

### API

なし（Enterprise Plan の一部の利用者で有効化される機能ということのようです）

```shell
export EMAIL='YOUR_EMAIL'
export APIKEY='YOUR_APIKEY'
export ZONE_ID='YOUR_ZONE_ID'

% curl -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID" \
     -H "X-Auth-Email: $EMAIL" \
     -H "X-Auth-Key: $APIKEY" \
     -H "Content-Type: application/json"
{"success":false,"errors":[{"code":1314,"message":"Please contact Cloudflare support to perform this action"}],"messages":[],"result":null}
```



# プラン変更

## Free / Pro / Business Plan

### GUI

あり

![image-20211007170253015](https://cdn.jsdelivr.net/gh/kyouheicf/image@master/uPic/image-20211007170253015.png)
![image-20211008020316352](https://cdn.jsdelivr.net/gh/kyouheicf/image@master/uPic/image-20211008020316352.png)

### API

あり

![image-20211008020828929](https://cdn.jsdelivr.net/gh/kyouheicf/image@master/uPic/image-20211008020828929.png)

## Enterprise Plan

### GUI

~~なし~~ あり（2022年11月1日更新、ダッシュボードからもダウングレードできるようになりました。）

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/101361/e26cafbc-1c19-02f4-5f18-94d8b1a33988.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/101361/bee620e5-9f45-fd9e-eb04-8ad15fa245c8.png)

### API

あり

> [Downgrading from Enterprise Website Plan to Free Website Plan - General - Cloudflare Community](https://community.cloudflare.com/t/downgrading-from-enterprise-website-plan-to-free-website-plan/200873)

```shell
export EMAIL='YOUR_EMAIL'
export APIKEY='YOUR_APIKEY'
export ZONE_ID='YOUR_ZONE_ID'

# プランIDのリスト
% curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/available_plans" \
     -H "X-Auth-Email: $EMAIL" \
     -H "X-Auth-Key: $APIKEY" \
     -H "Content-Type: application/json" | jq -r '.result[] | [.name,.id] |join(",")'
Free Plan,0feeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Business Plan,1ac039f6c29b691475c3d74fe588d1ae
Professional Plan,a577b510288e82b26486fd1df47000ec
Enterprise,94f3b7b768b0458b56d2cac4fe5ec0f9

# プランの事前確認
% curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID" \
     -H "X-Auth-Email: $EMAIL" \
     -H "X-Auth-Key: $APIKEY" \
     -H "Content-Type: application/json" | jq -r '.result.plan | [.name,.id] |join(",")'
Enterprise Website,94f3b7b768b0458b56d2cac4fe5ec0f9

# フリープランへ変更
% curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$ZONE_ID" \
     -H "X-Auth-Email: $EMAIL" \
     -H "X-Auth-Key: $APIKEY" \
     -H "Content-Type: application/json" \
     --data '{"plan":{"id":"0feeeeeeeeeeeeeeeeeeeeeeeeeeeeee"}}' | jq

# プランの事後確認
% curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID" \
     -H "X-Auth-Email: $EMAIL" \
     -H "X-Auth-Key: $APIKEY" \
     -H "Content-Type: application/json" | jq -r '.result.plan | [.name,.id] |join(",")'
Free Website,0feeeeeeeeeeeeeeeeeeeeeeeeeeeeee
```

# Enterprise Plan ゾーンを削除するには

Free Plan にダウングレード後に GUI もしくは API から削除できます。