github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/xenorchestra/resource_sets.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  package xenorchestra
    15  
    16  import (
    17  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    18  	"github.com/ddelnano/terraform-provider-xenorchestra/client"
    19  )
    20  
    21  type ResourceSetGenerator struct {
    22  	XenorchestraService
    23  }
    24  
    25  func (g ResourceSetGenerator) createResources(acls []client.ResourceSet) []terraformutils.Resource {
    26  	var resources []terraformutils.Resource
    27  	for _, acl := range acls {
    28  		resourceName := acl.Id
    29  		resources = append(resources, terraformutils.NewSimpleResource(
    30  			acl.Id,
    31  			resourceName,
    32  			"xenorchestra_resource_set",
    33  			"xenorchestra",
    34  			[]string{}))
    35  	}
    36  	return resources
    37  }
    38  
    39  func (g *ResourceSetGenerator) InitResources() error {
    40  	client := g.generateClient()
    41  	acls, err := client.GetResourceSets()
    42  
    43  	if err != nil {
    44  		return err
    45  	}
    46  	g.Resources = g.createResources(acls)
    47  	return nil
    48  }