github.com/GoogleCloudPlatform/terraformer@v0.8.18/cmd/provider_cmd_okta.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 "errors" 18 "os" 19 20 okta_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/okta" 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 "github.com/spf13/cobra" 23 ) 24 25 func newCmdOktaImporter(options ImportOptions) *cobra.Command { 26 cmd := &cobra.Command{ 27 Use: "okta", 28 Short: "Import current State to terraform configuration from okta", 29 Long: "Import current State to terraform configuration from okta", 30 RunE: func(cmd *cobra.Command, args []string) error { 31 token := os.Getenv("OKTA_API_TOKEN") 32 if len(token) == 0 { 33 return errors.New("API Token for Okta must be set through `OKTA_API_TOKEN` env var") 34 } 35 baseURL := os.Getenv("OKTA_BASE_URL") 36 if len(baseURL) == 0 { 37 return errors.New("Base URL for Okta must be set through `OKTA_BASE_URL` env var") 38 } 39 orgName := os.Getenv("OKTA_ORG_NAME") 40 if len(orgName) == 0 { 41 return errors.New("Org Name for Okta must be set through `OKTA_ORG_NAME` env var") 42 } 43 44 provider := newOktaProvider() 45 err := Import(provider, options, []string{orgName, token, baseURL}) 46 if err != nil { 47 return err 48 } 49 return nil 50 }, 51 } 52 cmd.AddCommand(listCmd(newOktaProvider())) 53 baseProviderFlags(cmd.PersistentFlags(), &options, "user", "okta_user=user1:user2:user3") 54 return cmd 55 } 56 57 func newOktaProvider() terraformutils.ProviderGenerator { 58 return &okta_terraforming.OktaProvider{} 59 }