github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/vultr/vultr_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 vultr
    16  
    17  import (
    18  	"errors"
    19  	"os"
    20  
    21  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    22  )
    23  
    24  type VultrProvider struct { //nolint
    25  	terraformutils.Provider
    26  	apiKey string
    27  }
    28  
    29  func (p *VultrProvider) Init(args []string) error {
    30  	if os.Getenv("VULTR_API_KEY") == "" {
    31  		return errors.New("set VULTR_API_KEY env var")
    32  	}
    33  	p.apiKey = os.Getenv("VULTR_API_KEY")
    34  
    35  	return nil
    36  }
    37  
    38  func (p *VultrProvider) GetName() string {
    39  	return "vultr"
    40  }
    41  
    42  func (p *VultrProvider) GetProviderData(arg ...string) map[string]interface{} {
    43  	return map[string]interface{}{}
    44  }
    45  
    46  func (VultrProvider) GetResourceConnections() map[string]map[string][]string {
    47  	return map[string]map[string][]string{}
    48  }
    49  
    50  func (p *VultrProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator {
    51  	return map[string]terraformutils.ServiceGenerator{
    52  		"bare_metal_server": &BareMetalServerGenerator{},
    53  		"block_storage":     &BlockStorageGenerator{},
    54  		"dns_domain":        &DNSDomainGenerator{},
    55  		"firewall_group":    &FirewallGroupGenerator{},
    56  		"network":           &NetworkGenerator{},
    57  		"reserved_ip":       &ReservedIPGenerator{},
    58  		"server":            &ServerGenerator{},
    59  		"snapshot":          &SnapshotGenerator{},
    60  		"ssh_key":           &SSHKeyGenerator{},
    61  		"startup_script":    &StartupScriptGenerator{},
    62  		"user":              &UserGenerator{},
    63  	}
    64  }
    65  
    66  func (p *VultrProvider) InitService(serviceName string, verbose bool) error {
    67  	var isSupported bool
    68  	if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported {
    69  		return errors.New("vultr: " + serviceName + " not supported service")
    70  	}
    71  	p.Service = p.GetSupportedService()[serviceName]
    72  	p.Service.SetName(serviceName)
    73  	p.Service.SetVerbose(verbose)
    74  	p.Service.SetProviderName(p.GetName())
    75  	p.Service.SetArgs(map[string]interface{}{
    76  		"api_key": p.apiKey,
    77  	})
    78  	return nil
    79  }