github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/idp_oidc.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 okta 16 17 import ( 18 "context" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 "github.com/okta/okta-sdk-golang/v2/okta" 22 "github.com/okta/okta-sdk-golang/v2/okta/query" 23 ) 24 25 type IdpOIDCGenerator struct { 26 OktaService 27 } 28 29 func (g IdpOIDCGenerator) createResources(idpOIDCList []*okta.IdentityProvider) []terraformutils.Resource { 30 var resources []terraformutils.Resource 31 for _, idp := range idpOIDCList { 32 resources = append(resources, terraformutils.NewSimpleResource( 33 idp.Id, 34 "idp_"+normalizeResourceName(idp.Type+"_"+idp.Name), 35 "okta_idp_oidc", 36 "okta", 37 []string{})) 38 39 } 40 return resources 41 } 42 43 func (g *IdpOIDCGenerator) InitResources() error { 44 ctx, client, err := g.Client() 45 if err != nil { 46 return err 47 } 48 49 identityProviders, err := getIdpOIDC(ctx, client) 50 if err != nil { 51 return err 52 } 53 54 g.Resources = g.createResources(identityProviders) 55 return nil 56 } 57 58 func getIdpOIDC(ctx context.Context, client *okta.Client) ([]*okta.IdentityProvider, error) { 59 qp := &query.Params{Type: "OIDC", Limit: 1} 60 output, resp, err := client.IdentityProvider.ListIdentityProviders(ctx, qp) 61 if err != nil { 62 return nil, err 63 } 64 65 for resp.HasNextPage() { 66 var nextIdpOIDCSet []*okta.IdentityProvider 67 resp, _ = resp.Next(ctx, &nextIdpOIDCSet) 68 output = append(output, nextIdpOIDCSet...) 69 } 70 71 return output, nil 72 }