github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/user.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 okta 16 17 import ( 18 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 19 "github.com/okta/okta-sdk-golang/v2/okta" 20 ) 21 22 type UserGenerator struct { 23 OktaService 24 } 25 26 func (g UserGenerator) createResources(userList []*okta.User) []terraformutils.Resource { 27 var resources []terraformutils.Resource 28 for _, user := range userList { 29 30 resources = append(resources, terraformutils.NewSimpleResource( 31 user.Id, 32 "user_"+user.Id, 33 "okta_user", 34 "okta", 35 []string{})) 36 } 37 return resources 38 } 39 40 func (g *UserGenerator) InitResources() error { 41 ctx, client, e := g.Client() 42 if e != nil { 43 return e 44 } 45 46 output, resp, err := client.User.ListUsers(ctx, nil) 47 if err != nil { 48 return e 49 } 50 51 for resp.HasNextPage() { 52 var nextUserSet []*okta.User 53 resp, _ = resp.Next(ctx, &nextUserSet) 54 output = append(output, nextUserSet...) 55 } 56 57 g.Resources = g.createResources(output) 58 return nil 59 }