github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/linode/stackscript.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 linode 16 17 import ( 18 "context" 19 "strconv" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 "github.com/linode/linodego" 23 ) 24 25 type StackScriptGenerator struct { 26 LinodeService 27 } 28 29 func (g StackScriptGenerator) createResources(stackscriptList []linodego.Stackscript) []terraformutils.Resource { 30 var resources []terraformutils.Resource 31 for _, stackscript := range stackscriptList { 32 // Avoid importing all community stackscripts 33 if !stackscript.IsPublic { 34 resources = append(resources, terraformutils.NewSimpleResource( 35 strconv.Itoa(stackscript.ID), 36 strconv.Itoa(stackscript.ID), 37 "linode_stackscript", 38 "linode", 39 []string{})) 40 } 41 } 42 return resources 43 } 44 45 func (g *StackScriptGenerator) InitResources() error { 46 client := g.generateClient() 47 output, err := client.ListStackscripts(context.Background(), nil) 48 if err != nil { 49 return err 50 } 51 g.Resources = g.createResources(output) 52 return nil 53 }