github.com/GoogleCloudPlatform/terraformer@v0.8.18/cmd/provider_cmd_gitlab.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 package cmd 15 16 import ( 17 "log" 18 "strings" 19 20 gitLab_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/gitlab" 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 "github.com/spf13/cobra" 23 ) 24 25 func newCmdGitLabImporter(options ImportOptions) *cobra.Command { 26 token := "" 27 baseURL := "" 28 groups := []string{} 29 cmd := &cobra.Command{ 30 Use: "gitlab", 31 Short: "Import current state to Terraform configuration from GitLab", 32 Long: "Import current state to Terraform configuration from GitLab", 33 RunE: func(cmd *cobra.Command, args []string) error { 34 originalPathPattern := options.PathPattern 35 for _, group := range groups { 36 provider := newGitLabProvider() 37 options.PathPattern = originalPathPattern 38 options.PathPattern = strings.ReplaceAll(options.PathPattern, "{provider}", "{provider}/"+group) 39 log.Println(provider.GetName() + " importing group " + group) 40 err := Import(provider, options, []string{group, token, baseURL}) 41 if err != nil { 42 return err 43 } 44 } 45 return nil 46 }, 47 } 48 cmd.AddCommand(listCmd(newGitLabProvider())) 49 baseProviderFlags(cmd.PersistentFlags(), &options, "repository", "repository=id1:id2:id4") 50 cmd.PersistentFlags().StringVarP(&token, "token", "t", "", "YOUR_GITLAB_TOKEN or env param GITLAB_TOKEN") 51 cmd.PersistentFlags().StringSliceVarP(&groups, "group", "", []string{}, "paths to groups") 52 cmd.PersistentFlags().StringVarP(&baseURL, "base-url", "", "", "") 53 return cmd 54 } 55 56 func newGitLabProvider() terraformutils.ProviderGenerator { 57 return &gitLab_terraforming.GitLabProvider{} 58 }