Skip to content

Commit

Permalink
add support for cloudflare_web_analytics_site
Browse files Browse the repository at this point in the history
  • Loading branch information
broswen committed Nov 7, 2023
1 parent 2ece26a commit e90d773
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ existing binary, or you wish to provide a Terraform compatible binary (such as
Any resources not listed are currently not supported.

| Resource | Resource Scope | Generate Supported | Import Supported |
| ------------------------------------------------------------------------------------------------------------------------------------------------ | --------------- | ------------------ | ---------------- |
|--------------------------------------------------------------------------------------------------------------------------------------------------|-----------------| ------------------ | ---------------- |
| [cloudflare_access_application](https://www.terraform.io/docs/providers/cloudflare/r/access_application) | Account |||
| [cloudflare_access_group](https://www.terraform.io/docs/providers/cloudflare/r/access_group) | Account |||
| [cloudflare_access_identity_provider](https://www.terraform.io/docs/providers/cloudflare/r/access_identity_provider) | Account |||
Expand Down Expand Up @@ -255,6 +255,7 @@ Any resources not listed are currently not supported.
| [cloudflare_waf_package](https://www.terraform.io/docs/providers/cloudflare/r/waf_package) | Zone |||
| [cloudflare_waf_rule](https://www.terraform.io/docs/providers/cloudflare/r/waf_rule) | Zone |||
| [cloudflare_waiting_room](https://www.terraform.io/docs/providers/cloudflare/r/waiting_room) | Zone |||
| [cloudflare_web_analytics_site](https://www.terraform.io/docs/providers/cloudflare/r/web_analytics_site) | Account |||
| [cloudflare_worker_cron_trigger](https://www.terraform.io/docs/providers/cloudflare/r/worker_cron_trigger) | Account |||
| [cloudflare_worker_route](https://www.terraform.io/docs/providers/cloudflare/r/worker_route) | Zone |||
| [cloudflare_worker_script](https://www.terraform.io/docs/providers/cloudflare/r/worker_script) | Account |||
Expand Down
11 changes: 11 additions & 0 deletions internal/app/cf-terraforming/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,17 @@ func generateResources() func(cmd *cobra.Command, args []string) {
log.Fatal(err)
}
jsonStructData = []interface{}{jsonPayloadInterface}
case "cloudflare_web_analytics_site":
jsonPayload, _, err := api.ListWebAnalyticsSites(context.Background(), cloudflare.AccountIdentifier(accountID), cloudflare.ListWebAnalyticsSitesParams{})
if err != nil {
log.Fatal(err)
}
resourceCount = len(jsonPayload)
m, _ := json.Marshal(jsonPayload)
err = json.Unmarshal(m, &jsonStructData)
if err != nil {
log.Fatal(err)
}
case "cloudflare_workers_kv_namespace":
jsonPayload, _, err := api.ListWorkersKVNamespaces(context.Background(), identifier, cloudflare.ListWorkersKVNamespacesParams{})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/app/cf-terraforming/cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func TestResourceGeneration(t *testing.T) {
"cloudflare waiting room event": {identiferType: "zone", resourceType: "cloudflare_waiting_room_event", testdataFilename: "cloudflare_waiting_room_event"},
"cloudflare waiting room rules": {identiferType: "zone", resourceType: "cloudflare_waiting_room_rules", testdataFilename: "cloudflare_waiting_room_rules"},
"cloudflare waiting room settings": {identiferType: "zone", resourceType: "cloudflare_waiting_room_settings", testdataFilename: "cloudflare_waiting_room_settings"},
"cloudflare web analytics site": {identiferType: "account", resourceType: "cloudflare_web_analytics_site", testdataFilename: "cloudflare_web_analytics_site"},
"cloudflare worker route": {identiferType: "zone", resourceType: "cloudflare_worker_route", testdataFilename: "cloudflare_worker_route"},
"cloudflare workers kv namespace": {identiferType: "account", resourceType: "cloudflare_workers_kv_namespace", testdataFilename: "cloudflare_workers_kv_namespace"},
"cloudflare zone lockdown": {identiferType: "zone", resourceType: "cloudflare_zone_lockdown", testdataFilename: "cloudflare_zone_lockdown"},
Expand Down
11 changes: 11 additions & 0 deletions internal/app/cf-terraforming/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var resourceImportStringFormats = map[string]string{
"cloudflare_turnstile_widget": ":account_id/:id",
"cloudflare_waf_override": ":zone_id/:id",
"cloudflare_waiting_room": ":zone_id/:id",
"cloudflare_web_analytics_site": ":account_id/:id",
"cloudflare_worker_route": ":zone_id/:id",
"cloudflare_workers_kv_namespace": ":id",
"cloudflare_zone_lockdown": ":zone_id/:id",
Expand Down Expand Up @@ -437,6 +438,16 @@ func runImport() func(cmd *cobra.Command, args []string) {
if err != nil {
log.Fatal(err)
}
case "cloudflare_web_analytics_site":
jsonPayload, _, err := api.ListWebAnalyticsSites(context.Background(), cloudflare.AccountIdentifier(accountID), cloudflare.ListWebAnalyticsSitesParams{})
if err != nil {
log.Fatal(err)
}
m, _ := json.Marshal(jsonPayload)
err = json.Unmarshal(m, &jsonStructData)
if err != nil {
log.Fatal(err)
}
case "cloudflare_workers_kv_namespace":
jsonPayload, _, err := api.ListWorkersKVNamespaces(context.Background(), identifier, cloudflare.ListWorkersKVNamespacesParams{})
if err != nil {
Expand Down
41 changes: 41 additions & 0 deletions testdata/cloudflare/cloudflare_web_analytics_site.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Content-Type:
- application/json
url: https://api.cloudflare.com/client/v4/accounts/f037e56e89293a057740de681ac9abbe/rum/site_info/list?page=1&per_page=10
method: GET
response:
body: |
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"site_tag": "1a091d3b85d76e2384d0e153747c7a84",
"site_token": "b40e25e5fc304ed31ee72bf5370dbcc7",
"created": "2023-08-28T20:08:56.719351Z",
"snippet": "\u003c!-- Cloudflare Web Analytics --\u003e\u003cscript defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{\"token\": \"b40e25e5fc304ed31ee72bf5370dbcc7\"}'\u003e\u003c/script\u003e\u003c!-- End Cloudflare Web Analytics --\u003e",
"auto_install": true,
"ruleset": {
"zone_tag": "0da42c8d2132a9ddaf714f9e7c920711",
"zone_name": "example.com",
"enabled": true,
"id": "81568f25-8f05-4368-98c3-bbd40846d217"
}
}
]
}
headers:
Content-Type:
- application/json
Vary:
- Accept-Encoding
status: 200 OK
code: 200
duration: ""
7 changes: 7 additions & 0 deletions testdata/terraform/cloudflare_web_analytics_site/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
}
}
}
5 changes: 5 additions & 0 deletions testdata/terraform/cloudflare_web_analytics_site/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "cloudflare_web_analytics_site" "terraform_managed_resource" {
account_id = "f037e56e89293a057740de681ac9abbe"
zone_tag = "0da42c8d2132a9ddaf714f9e7c920711"
auto_install = true
}

0 comments on commit e90d773

Please sign in to comment.