github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/ibm/ibm_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 ibm 16 17 import ( 18 "errors" 19 "os" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 ) 23 24 const DefaultRegion = "us-south" 25 const NoRegion = "" 26 27 type IBMProvider struct { //nolint 28 terraformutils.Provider 29 ResourceGroup string 30 Region string 31 CIS string 32 } 33 34 func (p *IBMProvider) Init(args []string) error { 35 p.ResourceGroup = args[0] 36 p.Region = args[1] 37 p.CIS = args[2] 38 39 var err error 40 if p.Region != DefaultRegion && p.Region != NoRegion { 41 err = os.Setenv("IC_REGION", p.Region) 42 } else { 43 p.Region = DefaultRegion 44 err = os.Setenv("IC_REGION", DefaultRegion) 45 } 46 if err != nil { 47 return err 48 } 49 return nil 50 } 51 52 func (p *IBMProvider) GetName() string { 53 return "ibm" 54 } 55 56 func (p *IBMProvider) GetProviderData(arg ...string) map[string]interface{} { 57 return map[string]interface{}{ 58 "provider": map[string]interface{}{ 59 "ibm": map[string]interface{}{ 60 "region": p.Region, 61 }, 62 }, 63 } 64 } 65 66 func (IBMProvider) GetResourceConnections() map[string]map[string][]string { 67 return map[string]map[string][]string{} 68 } 69 70 func (p *IBMProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 71 return map[string]terraformutils.ServiceGenerator{ 72 "ibm_kp": &KPGenerator{}, 73 "ibm_container_vpc_cluster": &VPCClusterGenerator{}, 74 "ibm_container_cluster": &ContainerClusterGenerator{}, 75 "ibm_cos": &COSGenerator{}, 76 "ibm_database_elasticsearch": &DatabaseElasticSearchGenerator{}, 77 "ibm_database_etcd": &DatabaseETCDGenerator{}, 78 "ibm_database_mongo": &DatabaseMongoGenerator{}, 79 "ibm_database_postgresql": &DatabasePostgresqlGenerator{}, 80 "ibm_database_rabbitmq": &DatabaseRabbitMQGenerator{}, 81 "ibm_database_redis": &DatabaseRedisGenerator{}, 82 "ibm_iam": &IAMGenerator{}, 83 "ibm_is_instance_group": &InstanceGroupGenerator{}, 84 "ibm_is_vpc": &VPCGenerator{}, 85 "ibm_is_subnet": &SubnetGenerator{}, 86 "ibm_is_instance": &InstanceGenerator{}, 87 "ibm_is_security_group": &SecurityGroupGenerator{}, 88 "ibm_cis": &CISGenerator{}, 89 "ibm_is_network_acl": &NetworkACLGenerator{}, 90 "ibm_is_public_gateway": &PublicGatewayGenerator{}, 91 "ibm_is_volume": &VolumeGenerator{}, 92 "ibm_is_vpn_gateway": &VPNGatewayGenerator{}, 93 "ibm_is_lb": &LBGenerator{}, 94 "ibm_is_ssh_key": &SSHKeyGenerator{}, 95 "ibm_is_floating_ip": &FloatingIPGenerator{}, 96 "ibm_is_image": &ImageGenerator{}, 97 "ibm_is_ipsec_policy": &IpsecGenerator{}, 98 "ibm_is_ike_policy": &IkeGenerator{}, 99 "ibm_is_flow_log": &FlowLogGenerator{}, 100 "ibm_is_instance_template": &InstanceTemplateGenerator{}, 101 "ibm_function": &CloudFunctionGenerator{}, 102 "ibm_private_dns": &privateDNSTemplateGenerator{}, 103 "ibm_certificate_manager": &CMGenerator{}, 104 "ibm_direct_link": &DLGenerator{}, 105 "ibm_transit_gateway": &TGGenerator{}, 106 "ibm_vpe_gateway": &VPEGenerator{}, 107 "ibm_satellite": &SatelliteGenerator{}, 108 } 109 } 110 111 func (p *IBMProvider) InitService(serviceName string, verbose bool) error { 112 var isSupported bool 113 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 114 return errors.New("IBM: " + serviceName + " not supported service") 115 } 116 p.Service = p.GetSupportedService()[serviceName] 117 p.Service.SetName(serviceName) 118 p.Service.SetVerbose(verbose) 119 p.Service.SetProviderName(p.GetName()) 120 121 p.Service.SetArgs(map[string]interface{}{ 122 "resource_group": p.ResourceGroup, 123 "region": p.Region, 124 "cis": p.CIS, 125 }) 126 return nil 127 }