github.com/GoogleCloudPlatform/terraformer@v0.8.18/cmd/provider_cmd_yandex.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 cmd 16 17 import ( 18 "log" 19 "strings" 20 21 yandex_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/yandex" 22 23 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 24 "github.com/spf13/cobra" 25 ) 26 27 func newCmdYandexImporter(options ImportOptions) *cobra.Command { 28 cmd := &cobra.Command{ 29 Use: "yandex", 30 Short: "Import current state to Terraform configuration from Yandex Cloud", 31 Long: "Import current state to Terraform configuration from Yandex Cloud", 32 RunE: func(cmd *cobra.Command, args []string) error { 33 34 originalPathPattern := options.PathPattern 35 // iterate over provided folder_ids 36 for _, folderID := range options.Projects { 37 provider := newYandexProvider() 38 options.PathPattern = originalPathPattern 39 options.PathPattern = strings.ReplaceAll(options.PathPattern, "{provider}/{service}", "{provider}/"+folderID+"/{service}") 40 log.Println(provider.GetName() + " importing folder id " + folderID) 41 err := Import(provider, options, []string{folderID}) 42 if err != nil { 43 return err 44 } 45 } 46 return nil 47 }, 48 } 49 50 cmd.AddCommand(listCmd(newYandexProvider())) 51 baseProviderFlags(cmd.PersistentFlags(), &options, "instance,disk", "") 52 cmd.Flags().StringSliceVarP(&options.Projects, "folder_ids", "", []string{}, "folder_id_1,folder_id_2") 53 _ = cmd.MarkFlagRequired("folder_ids") 54 return cmd 55 } 56 57 func newYandexProvider() terraformutils.ProviderGenerator { 58 return &yandex_terraforming.YandexProvider{} 59 }