github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/xenorchestra/xenorchestra_provider.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 xenorchestra
    16  
    17  import (
    18  	"errors"
    19  	"os"
    20  
    21  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    22  )
    23  
    24  type XenorchestraProvider struct { //nolint
    25  	terraformutils.Provider
    26  	url      string
    27  	user     string
    28  	password string
    29  }
    30  
    31  func (p *XenorchestraProvider) Init(args []string) error {
    32  	if os.Getenv("XOA_URL") == "" {
    33  		return errors.New("set XOA_URL env var")
    34  	}
    35  	p.url = os.Getenv("XOA_URL")
    36  
    37  	if os.Getenv("XOA_USER") == "" {
    38  		return errors.New("set XOA_USER env var")
    39  	}
    40  	p.user = os.Getenv("XOA_USER")
    41  
    42  	if os.Getenv("XOA_PASSWORD") == "" {
    43  		return errors.New("set XOA_PASSWORD env var")
    44  	}
    45  	p.password = os.Getenv("XOA_PASSWORD")
    46  
    47  	return nil
    48  }
    49  
    50  func (p *XenorchestraProvider) GetName() string {
    51  	return "xenorchestra"
    52  }
    53  
    54  func (p *XenorchestraProvider) GetProviderData(arg ...string) map[string]interface{} {
    55  	return map[string]interface{}{
    56  		"provider": map[string]interface{}{
    57  			"xenorchestra": map[string]interface{}{
    58  				"url":      p.url,
    59  				"username": p.user,
    60  				"password": p.password,
    61  			},
    62  		},
    63  	}
    64  }
    65  
    66  func (XenorchestraProvider) GetResourceConnections() map[string]map[string][]string {
    67  	return map[string]map[string][]string{}
    68  }
    69  
    70  func (p *XenorchestraProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator {
    71  	return map[string]terraformutils.ServiceGenerator{
    72  		"acl":          &AclGenerator{},
    73  		"resource_set": &ResourceSetGenerator{},
    74  	}
    75  }
    76  
    77  func (p *XenorchestraProvider) InitService(serviceName string, verbose bool) error {
    78  	var isSupported bool
    79  	if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported {
    80  		return errors.New("xenorchestra: " + serviceName + " not supported service")
    81  	}
    82  	p.Service = p.GetSupportedService()[serviceName]
    83  	p.Service.SetName(serviceName)
    84  	p.Service.SetVerbose(verbose)
    85  	p.Service.SetProviderName(p.GetName())
    86  	p.Service.SetArgs(map[string]interface{}{
    87  		"url":      p.url,
    88  		"username": p.user,
    89  		"password": p.password,
    90  	})
    91  	return nil
    92  }