github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/heroku/account_feature.go (about)

     1  // Copyright 2019 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 heroku
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    21  	heroku "github.com/heroku/heroku-go/v5"
    22  )
    23  
    24  type AccountFeatureGenerator struct {
    25  	HerokuService
    26  }
    27  
    28  func (g AccountFeatureGenerator) createResources(accountFeatureList []heroku.AccountFeature) []terraformutils.Resource {
    29  	var resources []terraformutils.Resource
    30  	for _, accountFeature := range accountFeatureList {
    31  		resources = append(resources, terraformutils.NewResource(
    32  			accountFeature.ID,
    33  			accountFeature.Name,
    34  			"heroku_account_feature",
    35  			"heroku",
    36  			map[string]string{"name": accountFeature.Name},
    37  			[]string{},
    38  			map[string]interface{}{}))
    39  	}
    40  	return resources
    41  }
    42  
    43  func (g *AccountFeatureGenerator) InitResources() error {
    44  	svc := g.generateService()
    45  	output, err := svc.AccountFeatureList(context.TODO(), &heroku.ListRange{Field: "id"})
    46  	if err != nil {
    47  		return err
    48  	}
    49  	g.Resources = g.createResources(output)
    50  	return nil
    51  }