github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/group_rule.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 GroupRuleGenerator struct {
    23  	OktaService
    24  }
    25  
    26  func (g GroupRuleGenerator) createResources(groupRuleList []*okta.GroupRule) []terraformutils.Resource {
    27  	var resources []terraformutils.Resource
    28  	for _, groupRule := range groupRuleList {
    29  
    30  		resources = append(resources, terraformutils.NewSimpleResource(
    31  			groupRule.Id,
    32  			"grouprule_"+groupRule.Name,
    33  			"okta_group_rule",
    34  			"okta",
    35  			[]string{}))
    36  	}
    37  	return resources
    38  }
    39  
    40  func (g *GroupRuleGenerator) InitResources() error {
    41  	ctx, client, e := g.Client()
    42  	if e != nil {
    43  		return e
    44  	}
    45  
    46  	output, resp, err := client.Group.ListGroupRules(ctx, nil)
    47  	if err != nil {
    48  		return e
    49  	}
    50  
    51  	for resp.HasNextPage() {
    52  		var nextGroupRuleSet []*okta.GroupRule
    53  		resp, _ = resp.Next(ctx, &nextGroupRuleSet)
    54  		output = append(output, nextGroupRuleSet...)
    55  	}
    56  
    57  	g.Resources = g.createResources(output)
    58  	return nil
    59  }