github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/gcp/backendServices_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 backendServicesAllowEmptyValues = []string{""}
    28  
    29  var backendServicesAdditionalFields = map[string]interface{}{}
    30  
    31  type BackendServicesGenerator struct {
    32  	GCPService
    33  }
    34  
    35  // Run on backendServicesList and create for each TerraformResource
    36  func (g BackendServicesGenerator) createResources(ctx context.Context, backendServicesList *compute.BackendServicesListCall) []terraformutils.Resource {
    37  	resources := []terraformutils.Resource{}
    38  	if err := backendServicesList.Pages(ctx, func(page *compute.BackendServiceList) error {
    39  		for _, obj := range page.Items {
    40  			resources = append(resources, terraformutils.NewResource(
    41  				obj.Name,
    42  				obj.Name,
    43  				"google_compute_backend_service",
    44  				g.ProviderName,
    45  				map[string]string{
    46  					"name":    obj.Name,
    47  					"project": g.GetArgs()["project"].(string),
    48  				},
    49  				backendServicesAllowEmptyValues,
    50  				backendServicesAdditionalFields,
    51  			))
    52  		}
    53  		return nil
    54  	}); err != nil {
    55  		log.Println(err)
    56  	}
    57  	return resources
    58  }
    59  
    60  // Generate TerraformResources from GCP API,
    61  // from each backendServices create 1 TerraformResource
    62  // Need backendServices name as ID for terraform resource
    63  func (g *BackendServicesGenerator) InitResources() error {
    64  	ctx := context.Background()
    65  	computeService, err := compute.NewService(ctx)
    66  	if err != nil {
    67  		return err
    68  	}
    69  
    70  	backendServicesList := computeService.BackendServices.List(g.GetArgs()["project"].(string))
    71  	g.Resources = g.createResources(ctx, backendServicesList)
    72  
    73  	return nil
    74  
    75  }