github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/authorization_server.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 "context" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 "github.com/okta/okta-sdk-golang/v2/okta" 22 ) 23 24 type AuthorizationServerGenerator struct { 25 OktaService 26 } 27 28 func (g AuthorizationServerGenerator) createResources(authorizationServerList []*okta.AuthorizationServer) []terraformutils.Resource { 29 var resources []terraformutils.Resource 30 for _, authorizationServer := range authorizationServerList { 31 resourceType := "okta_auth_server" 32 if authorizationServer.Name == "default" { 33 resourceType = "okta_auth_server_default" 34 } 35 36 resources = append(resources, terraformutils.NewSimpleResource( 37 authorizationServer.Id, 38 "auth_server_"+authorizationServer.Name, 39 resourceType, 40 "okta", 41 []string{})) 42 } 43 return resources 44 } 45 46 func (g *AuthorizationServerGenerator) InitResources() error { 47 ctx, client, e := g.Client() 48 if e != nil { 49 return e 50 } 51 52 output, err := getAuthorizationServers(ctx, client) 53 if err != nil { 54 return e 55 } 56 57 g.Resources = g.createResources(output) 58 return nil 59 } 60 61 func getAuthorizationServers(ctx context.Context, client *okta.Client) ([]*okta.AuthorizationServer, error) { 62 output, resp, err := client.AuthorizationServer.ListAuthorizationServers(ctx, nil) 63 if err != nil { 64 return nil, err 65 } 66 67 for resp.HasNextPage() { 68 var nextAuthorizationServerSet []*okta.AuthorizationServer 69 resp, _ = resp.Next(ctx, &nextAuthorizationServerSet) 70 output = append(output, nextAuthorizationServerSet...) 71 } 72 73 return output, nil 74 }