github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/octopusdeploy/octopusdeploy_provider.go (about)

     1  package octopusdeploy
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  
     7  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
     8  	"github.com/zclconf/go-cty/cty"
     9  )
    10  
    11  type OctopusDeployProvider struct { //nolint
    12  	terraformutils.Provider
    13  	address string
    14  	apiKey  string
    15  }
    16  
    17  func (p *OctopusDeployProvider) Init(args []string) error {
    18  	if args[0] != "" {
    19  		p.address = args[0]
    20  	} else {
    21  		if address := os.Getenv("OCTOPUS_CLI_SERVER"); address != "" {
    22  			p.address = address
    23  		} else {
    24  			return errors.New("server requirement")
    25  		}
    26  	}
    27  
    28  	if args[1] != "" {
    29  		p.apiKey = args[1]
    30  	} else {
    31  		if apiKey := os.Getenv("OCTOPUS_CLI_API_KEY"); apiKey != "" {
    32  			p.apiKey = apiKey
    33  		} else {
    34  			return errors.New("api-key requirement")
    35  		}
    36  	}
    37  
    38  	return nil
    39  }
    40  
    41  func (p *OctopusDeployProvider) GetName() string {
    42  	return "octopusdeploy"
    43  }
    44  
    45  func (p *OctopusDeployProvider) GetProviderData(arg ...string) map[string]interface{} {
    46  	return map[string]interface{}{
    47  		"provider": map[string]interface{}{
    48  			"octopusdeploy": map[string]interface{}{
    49  				"address": p.address,
    50  			},
    51  		},
    52  	}
    53  }
    54  
    55  func (OctopusDeployProvider) GetResourceConnections() map[string]map[string][]string {
    56  	return map[string]map[string][]string{}
    57  }
    58  
    59  func (p *OctopusDeployProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator {
    60  	return map[string]terraformutils.ServiceGenerator{
    61  		"accounts": &GenericGenerator{APIService: "accounts"},
    62  		// "channels":      &GenericGenerator{APIService: "channels"},
    63  		"certificates":        &GenericGenerator{APIService: "certificates"},
    64  		"environments":        &GenericGenerator{APIService: "environments"},
    65  		"feeds":               &GenericGenerator{APIService: "feeds"},
    66  		"libraryvariablesets": &GenericGenerator{APIService: "libraryvariablesets"},
    67  		"lifecycles":          &GenericGenerator{APIService: "lifecycles"},
    68  		"projects":            &GenericGenerator{APIService: "projects"},
    69  		"projectgroups":       &GenericGenerator{APIService: "projectgroups"},
    70  		"projecttriggers":     &GenericGenerator{APIService: "projecttriggers"},
    71  		"tagsets":             &GenericGenerator{APIService: "tagsets"},
    72  		// "variables":           &GenericGenerator{APIService: "variables"},
    73  	}
    74  }
    75  
    76  func (p *OctopusDeployProvider) InitService(serviceName string, verbose bool) error {
    77  	var isSupported bool
    78  	if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported {
    79  		return errors.New("octopusdeploy: " + serviceName + " not supported service")
    80  	}
    81  	p.Service = p.GetSupportedService()[serviceName]
    82  	p.Service.SetName(serviceName)
    83  	p.Service.SetVerbose(verbose)
    84  	p.Service.SetProviderName(p.GetName())
    85  	p.Service.SetArgs(map[string]interface{}{
    86  		"apikey":  p.apiKey,
    87  		"address": p.address,
    88  	})
    89  
    90  	return nil
    91  }
    92  
    93  // GetConfig return map of provider config for OctopusDeployProvider
    94  func (p *OctopusDeployProvider) GetConfig() cty.Value {
    95  	return cty.ObjectVal(map[string]cty.Value{
    96  		"apikey":  cty.StringVal(p.apiKey),
    97  		"address": cty.StringVal(p.address),
    98  	})
    99  }
   100  
   101  func (p *OctopusDeployProvider) GetBasicConfig() cty.Value {
   102  	return p.GetConfig()
   103  }