github.com/GoogleCloudPlatform/terraformer@v0.8.18/cmd/provider_cmd_panos.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 cmd 16 17 import ( 18 "log" 19 "reflect" 20 "strings" 21 22 panos_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/panos" 23 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 24 "github.com/spf13/cobra" 25 ) 26 27 func newCmdPanosImporter(options ImportOptions) *cobra.Command { 28 vsys := []string{} 29 cmd := &cobra.Command{ 30 Use: "panos", 31 Short: "Import current state to Terraform configuration from a PAN-OS", 32 Long: "Import current state to Terraform configuration from a PAN-OS", 33 RunE: func(cmd *cobra.Command, args []string) error { 34 var t interface{} 35 36 if len(vsys) == 0 { 37 var err error 38 39 vsys, t, err = panos_terraforming.GetVsysList() 40 if err != nil { 41 return err 42 } 43 } else { 44 c, err := panos_terraforming.Initialize() 45 if err != nil { 46 return err 47 } 48 49 t = reflect.TypeOf(c) 50 } 51 52 resources := panos_terraforming.FilterCallableResources(t, options.Resources) 53 options.Resources = resources 54 55 originalPathPattern := options.PathPattern 56 for _, v := range vsys { 57 provider := newPanosProvider() 58 log.Println(provider.GetName() + " importing VSYS " + v) 59 options.PathPattern = originalPathPattern 60 options.PathPattern = strings.ReplaceAll(options.PathPattern, "{provider}", "{provider}/"+v) 61 62 err := Import(provider, options, []string{v}) 63 if err != nil { 64 return err 65 } 66 } 67 68 return nil 69 }, 70 } 71 72 cmd.AddCommand(listCmd(newPanosProvider())) 73 baseProviderFlags(cmd.PersistentFlags(), &options, "firewall_device_config,firewall_networking,firewall_objects,firewall_policy", "") 74 cmd.PersistentFlags().StringSliceVarP(&vsys, "vsys", "", []string{}, "") 75 76 return cmd 77 } 78 79 func newPanosProvider() terraformutils.ProviderGenerator { 80 81 return &panos_terraforming.PanosProvider{} 82 }