github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/gcp/interconnectAttachments_gen.go (about) 1 // Copyright 2018 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 // AUTO-GENERATED CODE. DO NOT EDIT. 16 package gcp 17 18 import ( 19 "context" 20 "log" 21 22 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 23 24 "google.golang.org/api/compute/v1" 25 ) 26 27 var interconnectAttachmentsAllowEmptyValues = []string{""} 28 29 var interconnectAttachmentsAdditionalFields = map[string]interface{}{} 30 31 type InterconnectAttachmentsGenerator struct { 32 GCPService 33 } 34 35 // Run on interconnectAttachmentsList and create for each TerraformResource 36 func (g InterconnectAttachmentsGenerator) createResources(ctx context.Context, interconnectAttachmentsList *compute.InterconnectAttachmentsListCall) []terraformutils.Resource { 37 resources := []terraformutils.Resource{} 38 if err := interconnectAttachmentsList.Pages(ctx, func(page *compute.InterconnectAttachmentList) error { 39 for _, obj := range page.Items { 40 resources = append(resources, terraformutils.NewResource( 41 obj.Name, 42 obj.Name, 43 "google_compute_interconnect_attachment", 44 g.ProviderName, 45 map[string]string{ 46 "name": obj.Name, 47 "project": g.GetArgs()["project"].(string), 48 "region": g.GetArgs()["region"].(compute.Region).Name, 49 }, 50 interconnectAttachmentsAllowEmptyValues, 51 interconnectAttachmentsAdditionalFields, 52 )) 53 } 54 return nil 55 }); err != nil { 56 log.Println(err) 57 } 58 return resources 59 } 60 61 // Generate TerraformResources from GCP API, 62 // from each interconnectAttachments create 1 TerraformResource 63 // Need interconnectAttachments name as ID for terraform resource 64 func (g *InterconnectAttachmentsGenerator) InitResources() error { 65 ctx := context.Background() 66 computeService, err := compute.NewService(ctx) 67 if err != nil { 68 return err 69 } 70 71 interconnectAttachmentsList := computeService.InterconnectAttachments.List(g.GetArgs()["project"].(string), g.GetArgs()["region"].(compute.Region).Name) 72 g.Resources = g.createResources(ctx, interconnectAttachmentsList) 73 74 return nil 75 76 }