github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/authorization_server_policy.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 AuthorizationServerPolicyGenerator struct { 23 OktaService 24 } 25 26 func (g AuthorizationServerPolicyGenerator) createResources(authorizationServerPolicyList []*okta.AuthorizationServerPolicy, authorizationServerID string, authorizationServerName string) []terraformutils.Resource { 27 var resources []terraformutils.Resource 28 29 for _, authorizationServerPolicy := range authorizationServerPolicyList { 30 resources = append(resources, terraformutils.NewResource( 31 authorizationServerPolicy.Id, 32 normalizeResourceName("auth_server_"+authorizationServerName+"_policy_"+authorizationServerPolicy.Name), 33 "okta_auth_server_policy", 34 "okta", 35 map[string]string{ 36 "auth_server_id": authorizationServerID, 37 }, 38 []string{}, 39 map[string]interface{}{}, 40 )) 41 } 42 return resources 43 } 44 45 func (g *AuthorizationServerPolicyGenerator) InitResources() error { 46 var resources []terraformutils.Resource 47 ctx, client, e := g.Client() 48 if e != nil { 49 return e 50 } 51 52 authorizationServers, err := getAuthorizationServers(ctx, client) 53 if err != nil { 54 return err 55 } 56 57 for _, authorizationServer := range authorizationServers { 58 output, _, err := client.AuthorizationServer.ListAuthorizationServerPolicies(ctx, authorizationServer.Id) 59 if err != nil { 60 return err 61 } 62 63 resources = append(resources, g.createResources(output, authorizationServer.Id, authorizationServer.Name)...) 64 } 65 66 g.Resources = resources 67 return nil 68 }