github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/heroku/app_config_association.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  	"fmt"
    20  	"log"
    21  
    22  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    23  	heroku "github.com/heroku/heroku-go/v5"
    24  )
    25  
    26  type AppConfigAssociationGenerator struct {
    27  	HerokuService
    28  }
    29  
    30  func (g AppConfigAssociationGenerator) createResources(svc *heroku.Service, appList []heroku.App) []terraformutils.Resource {
    31  	var resources []terraformutils.Resource
    32  	for _, app := range appList {
    33  		output, err := svc.ConfigVarInfoForApp(context.TODO(), app.ID)
    34  		if err != nil {
    35  			log.Println(err)
    36  		}
    37  		resources = append(resources, terraformutils.NewResource(
    38  			fmt.Sprintf("%s-config-association", app.Name),
    39  			fmt.Sprintf("%s-config-association", app.Name),
    40  			"heroku_app_config_association",
    41  			"heroku",
    42  			map[string]string{
    43  				"app_id": app.ID,
    44  			},
    45  			[]string{},
    46  			map[string]interface{}{
    47  				// since Heroku does not distinguish between non-sensitive and sensitive config variables, set output to vars
    48  				"vars":           output,
    49  				"sensitive_vars": map[string]interface{}{},
    50  			}))
    51  	}
    52  	return resources
    53  }
    54  
    55  func (g *AppConfigAssociationGenerator) InitResources() error {
    56  	svc := g.generateService()
    57  	output, err := svc.AppList(context.TODO(), &heroku.ListRange{Field: "id"})
    58  	if err != nil {
    59  		return err
    60  	}
    61  	g.Resources = g.createResources(svc, output)
    62  	return nil
    63  }