github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/openstack/openstack_provider.go (about)

     1  // Copyright 2018 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 openstack
    16  
    17  import (
    18  	"os"
    19  
    20  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    21  	"github.com/pkg/errors"
    22  )
    23  
    24  type OpenStackProvider struct { //nolint
    25  	terraformutils.Provider
    26  	region string
    27  }
    28  
    29  func (p OpenStackProvider) GetResourceConnections() map[string]map[string][]string {
    30  	return map[string]map[string][]string{}
    31  }
    32  
    33  func (p OpenStackProvider) GetProviderData(arg ...string) map[string]interface{} {
    34  	return map[string]interface{}{
    35  		"provider": map[string]interface{}{
    36  			"openstack": map[string]interface{}{
    37  				"region": p.region,
    38  			},
    39  		},
    40  	}
    41  }
    42  
    43  // check projectName in env params
    44  func (p *OpenStackProvider) Init(args []string) error {
    45  	p.region = args[0]
    46  	// terraform work with env param OS_REGION_NAME
    47  	err := os.Setenv("OS_REGION_NAME", p.region)
    48  	if err != nil {
    49  		return err
    50  	}
    51  	return nil
    52  }
    53  
    54  func (p *OpenStackProvider) GetName() string {
    55  	return "openstack"
    56  }
    57  
    58  func (p *OpenStackProvider) InitService(serviceName string, verbose bool) error {
    59  	var isSupported bool
    60  	if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported {
    61  		return errors.New("openstack: " + serviceName + " not supported service")
    62  	}
    63  	p.Service = p.GetSupportedService()[serviceName]
    64  	p.Service.SetName(serviceName)
    65  	p.Service.SetVerbose(verbose)
    66  	p.Service.SetProviderName(p.GetName())
    67  	p.Service.SetArgs(map[string]interface{}{
    68  		"region": p.region,
    69  	})
    70  	return nil
    71  }
    72  
    73  // GetOpenStackSupportService return map of support service for OpenStack
    74  func (p *OpenStackProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator {
    75  	return map[string]terraformutils.ServiceGenerator{
    76  		"blockstorage": &BlockStorageGenerator{},
    77  		"compute":      &ComputeGenerator{},
    78  		"networking":   &NetworkingGenerator{},
    79  	}
    80  }