github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/commercetools/state.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 package commercetools 16 17 import ( 18 "context" 19 20 "github.com/GoogleCloudPlatform/terraformer/providers/commercetools/connectivity" 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 "github.com/labd/commercetools-go-sdk/commercetools" 23 ) 24 25 type StateGenerator struct { 26 CommercetoolsService 27 } 28 29 // InitResources generates Terraform Resources from Commercetools API 30 func (g *StateGenerator) InitResources() error { 31 cfg := connectivity.Config{ 32 ClientID: g.GetArgs()["client_id"].(string), 33 ClientSecret: g.GetArgs()["client_secret"].(string), 34 ClientScope: g.GetArgs()["client_scope"].(string), 35 TokenURL: g.GetArgs()["token_url"].(string) + "/oauth/token", 36 BaseURL: g.GetArgs()["base_url"].(string), 37 } 38 39 client := cfg.NewClient() 40 41 states, err := client.StateQuery(context.Background(), &commercetools.QueryInput{}) 42 if err != nil { 43 return err 44 } 45 for _, state := range states.Results { 46 g.Resources = append(g.Resources, terraformutils.NewResource( 47 state.ID, 48 state.Key, 49 "commercetools_state", 50 "commercetools", 51 map[string]string{}, 52 []string{}, 53 map[string]interface{}{}, 54 )) 55 } 56 return nil 57 }