github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/mikrotik/mikrotik_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 mikrotik
    16  
    17  import (
    18  	"errors"
    19  
    20  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    21  	"github.com/ddelnano/terraform-provider-mikrotik/client"
    22  )
    23  
    24  type MikrotikProvider struct { //nolint
    25  	terraformutils.Provider
    26  	client.Mikrotik
    27  }
    28  
    29  func (p *MikrotikProvider) Init(args []string) error {
    30  	// The mikrotik provider gets its credentials through environment variables
    31  	// and therefore nothing needs to be done here
    32  	return nil
    33  }
    34  
    35  func (p *MikrotikProvider) GetName() string {
    36  	return "mikrotik"
    37  }
    38  
    39  func (p *MikrotikProvider) GetProviderData(arg ...string) map[string]interface{} {
    40  	return map[string]interface{}{
    41  		"provider": map[string]interface{}{
    42  			"mikrotik": map[string]interface{}{
    43  				"host": p.Host,
    44  				"user": p.Username,
    45  			},
    46  		},
    47  	}
    48  }
    49  
    50  func (MikrotikProvider) GetResourceConnections() map[string]map[string][]string {
    51  	return map[string]map[string][]string{}
    52  }
    53  
    54  func (p *MikrotikProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator {
    55  	return map[string]terraformutils.ServiceGenerator{
    56  		"dhcp_lease": &DhcpLeaseGenerator{},
    57  	}
    58  }
    59  
    60  func (p *MikrotikProvider) InitService(serviceName string, verbose bool) error {
    61  	var isSupported bool
    62  	if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported {
    63  		return errors.New("mikrotik: " + serviceName + " not supported service")
    64  	}
    65  	p.Service = p.GetSupportedService()[serviceName]
    66  	p.Service.SetName(serviceName)
    67  	p.Service.SetVerbose(verbose)
    68  	p.Service.SetProviderName(p.GetName())
    69  	p.Service.SetArgs(map[string]interface{}{
    70  		"host":           p.Host,
    71  		"user":           p.Username,
    72  		"password":       p.Password,
    73  		"tls":            p.TLS,
    74  		"ca_certificate": p.CA,
    75  		"insecure":       p.Insecure,
    76  	})
    77  	return nil
    78  }