github.com/GoogleCloudPlatform/terraformer@v0.8.18/tests/github/main.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 main 16 17 import ( 18 "log" 19 "os" 20 "os/exec" 21 "sort" 22 23 "github.com/GoogleCloudPlatform/terraformer/cmd" 24 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 25 26 github_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/github" 27 ) 28 29 const command = "terraform init && terraform plan" 30 31 func main() { 32 organization := "" 33 token := os.Getenv("GITHUB_TOKEN") 34 services := []string{} 35 provider := &github_terraforming.GithubProvider{} 36 for service := range provider.GetSupportedService() { 37 services = append(services, service) 38 } 39 sort.Strings(services) 40 provider = &github_terraforming.GithubProvider{ 41 Provider: terraformutils.Provider{}, 42 } 43 err := cmd.Import(provider, cmd.ImportOptions{ 44 Resources: services, 45 PathPattern: cmd.DefaultPathPattern, 46 PathOutput: cmd.DefaultPathOutput, 47 State: "local", 48 Connect: true, 49 }, []string{organization, token}) 50 if err != nil { 51 log.Println(err) 52 os.Exit(1) 53 } 54 rootPath, _ := os.Getwd() 55 for _, serviceName := range services { 56 currentPath := cmd.Path(cmd.DefaultPathPattern, provider.GetName(), serviceName, cmd.DefaultPathOutput) 57 if err := os.Chdir(currentPath); err != nil { 58 log.Println(err) 59 os.Exit(1) 60 } 61 cmd := exec.Command("sh", "-c", command) 62 cmd.Stdout = os.Stdout 63 cmd.Stderr = os.Stderr 64 err = cmd.Run() 65 if err != nil { 66 log.Println(err) 67 os.Exit(1) 68 } 69 err := os.Chdir(rootPath) 70 if err != nil { 71 log.Println(err) 72 } 73 } 74 }