github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/app_user_schema.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 AppUserSchemaPropertyGenerator struct {
    23  	OktaService
    24  }
    25  
    26  func (g AppUserSchemaPropertyGenerator) createResources(appUserSchema *okta.UserSchema, appID string) []terraformutils.Resource {
    27  	var resources []terraformutils.Resource
    28  	for index := range appUserSchema.Definitions.Custom.Properties {
    29  		resources = append(resources, terraformutils.NewResource(
    30  			index,
    31  			normalizeResourceName(appID)+"_property_"+normalizeResourceName(index),
    32  			"okta_app_user_schema_property",
    33  			"okta",
    34  			map[string]string{
    35  				"app_id": appID,
    36  				"index":  index,
    37  			},
    38  			[]string{},
    39  			map[string]interface{}{},
    40  		))
    41  	}
    42  
    43  	for index := range appUserSchema.Definitions.Base.Properties {
    44  		resources = append(resources, terraformutils.NewResource(
    45  			index,
    46  			normalizeResourceName(appID)+"_property_"+normalizeResourceName(index),
    47  			"okta_app_user_base_schema_property",
    48  			"okta",
    49  			map[string]string{
    50  				"app_id": appID,
    51  				"index":  index,
    52  			},
    53  			[]string{},
    54  			map[string]interface{}{},
    55  		))
    56  	}
    57  	return resources
    58  }
    59  
    60  func (g *AppUserSchemaPropertyGenerator) InitResources() error {
    61  	var resources []terraformutils.Resource
    62  	ctx, client, e := g.Client()
    63  	if e != nil {
    64  		return e
    65  	}
    66  
    67  	apps, err := getAllApplications(ctx, client)
    68  	if err != nil {
    69  		return err
    70  	}
    71  
    72  	for _, app := range apps {
    73  		appUserSchema, _, err := client.UserSchema.GetApplicationUserSchema(ctx, app.Id)
    74  		if err != nil {
    75  			return err
    76  		}
    77  
    78  		resources = append(resources, g.createResources(appUserSchema, app.Id)...)
    79  	}
    80  	g.Resources = resources
    81  	return nil
    82  }