github.com/GoogleCloudPlatform/terraformer@v0.8.18/cmd/provider_cmd_tencentcloud.go (about)

     1  // Copyright 2021 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  
    20  	tencentcloud_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/tencentcloud"
    21  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    22  	"github.com/spf13/cobra"
    23  )
    24  
    25  func newCmdTencentCloudImporter(options ImportOptions) *cobra.Command {
    26  	cmd := &cobra.Command{
    27  		Use:   "tencentcloud",
    28  		Short: "Import current state to Terraform configuration from Tencent Cloud",
    29  		Long:  "Import current state to Terraform configuration from Tencent Cloud",
    30  		RunE: func(cmd *cobra.Command, args []string) error {
    31  			originalPathPattern := options.PathPattern
    32  			for _, region := range options.Regions {
    33  				provider := newTencentCloudProvider()
    34  				options.PathPattern = originalPathPattern
    35  				options.PathPattern += region + "/"
    36  				log.Println(provider.GetName() + " importing region " + region)
    37  				err := Import(provider, options, []string{region})
    38  				if err != nil {
    39  					return err
    40  				}
    41  			}
    42  			return nil
    43  		},
    44  	}
    45  	cmd.AddCommand(listCmd(newTencentCloudProvider()))
    46  	baseProviderFlags(cmd.PersistentFlags(), &options, "cvm,vpc,cdn", "tencentcloud_vpc=id1:id2:id3")
    47  	cmd.PersistentFlags().StringSliceVarP(&options.Regions, "regions", "", []string{}, "ap-guangzhou")
    48  	return cmd
    49  }
    50  
    51  func newTencentCloudProvider() terraformutils.ProviderGenerator {
    52  	return &tencentcloud_terraforming.TencentCloudProvider{}
    53  }