github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/cloudflare/page_rule.go (about) 1 // Copyright 2020 The Terraformer Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cloudflare 16 17 import ( 18 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 19 cf "github.com/cloudflare/cloudflare-go" 20 ) 21 22 type PageRulesGenerator struct { 23 CloudflareService 24 } 25 26 func (g *PageRulesGenerator) createPageRules(api *cf.API, zoneID string) ([]terraformutils.Resource, error) { 27 var resources []terraformutils.Resource 28 pageRules, err := api.ListPageRules(zoneID) 29 if err != nil { 30 return resources, err 31 } 32 33 for _, pageRule := range pageRules { 34 resources = append(resources, terraformutils.NewResource( 35 pageRule.ID, 36 pageRule.ID, 37 "cloudflare_page_rule", 38 "cloudflare", 39 map[string]string{ 40 "zone_id": zoneID, 41 }, 42 []string{}, 43 map[string]interface{}{}, 44 )) 45 } 46 47 return resources, nil 48 } 49 50 func (g *PageRulesGenerator) InitResources() error { 51 api, err := g.initializeAPI() 52 if err != nil { 53 return err 54 } 55 56 zones, err := api.ListZones() 57 if err != nil { 58 return err 59 } 60 61 for _, zone := range zones { 62 resources, err := g.createPageRules(api, zone.ID) 63 if err != nil { 64 return err 65 } 66 g.Resources = append(g.Resources, resources...) 67 } 68 69 return nil 70 }