Skip to content

Commit

Permalink
add google-beta provider support
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeylanzman committed Dec 2, 2020
1 parent b0e1299 commit e37cb3d
Show file tree
Hide file tree
Showing 75 changed files with 262 additions and 159 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --con
terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --filter=compute_firewall=rule1:rule2:rule3 --regions=europe-west1 --projects=aaa,fff
```

For google-beta provider:

```
terraformer import google --resources=gcs,forwardingRules,httpHealthChecks --regions=europe-west4 --projects=aaa --provider-type beta
```

List of supported GCP services:

* `addresses`
Expand Down
3 changes: 2 additions & 1 deletion cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ package cmd

import (
"fmt"
"github.com/GoogleCloudPlatform/terraformer/terraformutils/terraformerstring"
"io/ioutil"
"log"
"os"
"sort"
"strings"

"github.com/GoogleCloudPlatform/terraformer/terraformutils/terraformerstring"

"github.com/GoogleCloudPlatform/terraformer/terraformutils/providerwrapper"

"github.com/spf13/pflag"
Expand Down
4 changes: 3 additions & 1 deletion cmd/provider_cmd_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

func newCmdGoogleImporter(options ImportOptions) *cobra.Command {
providerType := ""
cmd := &cobra.Command{
Use: "google",
Short: "Import current state to Terraform configuration from Google Cloud",
Expand All @@ -35,7 +36,7 @@ func newCmdGoogleImporter(options ImportOptions) *cobra.Command {
options.PathPattern = originalPathPattern
options.PathPattern = strings.ReplaceAll(options.PathPattern, "{provider}/{service}", "{provider}/"+project+"/{service}/"+region)
log.Println(provider.GetName() + " importing project " + project + " region " + region)
err := Import(provider, options, []string{region, project})
err := Import(provider, options, []string{region, project, providerType})
if err != nil {
return err
}
Expand All @@ -48,6 +49,7 @@ func newCmdGoogleImporter(options ImportOptions) *cobra.Command {
baseProviderFlags(cmd.PersistentFlags(), &options, "firewalls,networks", "compute_firewall=id1:id2:id4")
cmd.PersistentFlags().StringSliceVarP(&options.Regions, "regions", "z", []string{"global"}, "europe-west1,")
cmd.PersistentFlags().StringSliceVarP(&options.Projects, "projects", "", []string{}, "")
cmd.PersistentFlags().StringVarP(&providerType, "provider-type", "", "", "beta")
_ = cmd.MarkPersistentFlagRequired("projects")
return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/addresses_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g AddressesGenerator) createResources(ctx context.Context, addressesList *
obj.Name,
obj.Name,
"google_compute_address",
"google",
g.ProviderName,
map[string]string{
"name": obj.Name,
"project": g.GetArgs()["project"].(string),
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/autoscalers_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (g AutoscalersGenerator) createResources(ctx context.Context, autoscalersLi
zone+"/"+obj.Name,
zone+"/"+obj.Name,
"google_compute_autoscaler",
"google",
g.ProviderName,
map[string]string{
"name": obj.Name,
"project": g.GetArgs()["project"].(string),
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/backendBuckets_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g BackendBucketsGenerator) createResources(ctx context.Context, backendBuc
obj.Name,
obj.Name,
"google_compute_backend_bucket",
"google",
g.ProviderName,
map[string]string{
"name": obj.Name,
"project": g.GetArgs()["project"].(string),
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/backendServices_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g BackendServicesGenerator) createResources(ctx context.Context, backendSe
obj.Name,
obj.Name,
"google_compute_backend_service",
"google",
g.ProviderName,
map[string]string{
"name": obj.Name,
"project": g.GetArgs()["project"].(string),
Expand Down
4 changes: 2 additions & 2 deletions providers/gcp/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (g BigQueryGenerator) createDatasets(ctx context.Context, dataSetsList *big
dataset.Id,
name,
"google_bigquery_dataset",
"google",
g.ProviderName,
map[string]string{
"project": g.GetArgs()["project"].(string),
"dataset_id": ID,
Expand Down Expand Up @@ -74,7 +74,7 @@ func (g *BigQueryGenerator) createResourcesTables(ctx context.Context, datasetID
table.Id,
name,
"google_bigquery_table",
"google",
g.ProviderName,
map[string]string{
"project": g.GetArgs()["project"].(string),
"table_id": ID,
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/cloudFunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (g CloudFunctionsGenerator) createResources(ctx context.Context, functionsL
g.GetArgs()["project"].(string)+"/"+g.GetArgs()["region"].(compute.Region).Name+"/"+name,
g.GetArgs()["region"].(compute.Region).Name+"_"+name,
"google_cloudfunctions_function",
"google",
g.ProviderName,
cloudFunctionsAllowEmptyValues,
))
}
Expand Down
6 changes: 3 additions & 3 deletions providers/gcp/clouddns.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (g CloudDNSGenerator) createZonesResources(ctx context.Context, svc *dns.Se
zone.Name,
zone.Name,
"google_dns_managed_zone",
"google",
g.ProviderName,
map[string]string{
"name": zone.Name,
"project": project,
Expand All @@ -61,7 +61,7 @@ func (g CloudDNSGenerator) createZonesResources(ctx context.Context, svc *dns.Se
}
return resources
}
func (CloudDNSGenerator) createRecordsResources(ctx context.Context, svc *dns.Service, project, zoneName string) []terraformutils.Resource {
func (g CloudDNSGenerator) createRecordsResources(ctx context.Context, svc *dns.Service, project, zoneName string) []terraformutils.Resource {
resources := []terraformutils.Resource{}
managedRecordsListCall := svc.ResourceRecordSets.List(project, zoneName)
err := managedRecordsListCall.Pages(ctx, func(listDNS *dns.ResourceRecordSetsListResponse) error {
Expand All @@ -70,7 +70,7 @@ func (CloudDNSGenerator) createRecordsResources(ctx context.Context, svc *dns.Se
fmt.Sprintf("%s/%s/%s", zoneName, record.Name, record.Type),
zoneName+"_"+strings.TrimSuffix(record.Name+"-"+record.Type, "."),
"google_dns_record_set",
"google",
g.ProviderName,
map[string]string{
"name": record.Name,
"managed_zone": zoneName,
Expand Down
4 changes: 2 additions & 2 deletions providers/gcp/cloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (g *CloudSQLGenerator) loadDBInstances(svc *sqladmin.Service, project strin
dbInstance.Name,
dbInstance.Name,
"google_sql_database_instance",
"google",
g.ProviderName,
map[string]string{
"project": project,
"name": dbInstance.Name,
Expand All @@ -67,7 +67,7 @@ func (g *CloudSQLGenerator) loadDBs(svc *sqladmin.Service, instanceName, project
instanceName+":"+db.Name,
instanceName+"-"+db.Name,
"google_sql_database",
"google",
g.ProviderName,
map[string]string{
"instance": instanceName,
"project": project,
Expand Down
100 changes: 50 additions & 50 deletions providers/gcp/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,54 +22,54 @@ import (
// Map of supported GCP compute service with code generate
var ComputeServices = map[string]terraformutils.ServiceGenerator{

"addresses": &AddressesGenerator{},
"autoscalers": &AutoscalersGenerator{},
"backendBuckets": &BackendBucketsGenerator{},
"backendServices": &BackendServicesGenerator{},
"disks": &DisksGenerator{},
"externalVpnGateways": &ExternalVpnGatewaysGenerator{},
"firewall": &FirewallGenerator{},
"forwardingRules": &ForwardingRulesGenerator{},
"globalAddresses": &GlobalAddressesGenerator{},
"globalForwardingRules": &GlobalForwardingRulesGenerator{},
"healthChecks": &HealthChecksGenerator{},
"httpHealthChecks": &HttpHealthChecksGenerator{},
"httpsHealthChecks": &HttpsHealthChecksGenerator{},
"images": &ImagesGenerator{},
"instanceGroupManagers": &InstanceGroupManagersGenerator{},
"instanceGroups": &InstanceGroupsGenerator{},
"instanceTemplates": &InstanceTemplatesGenerator{},
"interconnectAttachments": &InterconnectAttachmentsGenerator{},
"networkEndpointGroups": &NetworkEndpointGroupsGenerator{},
"networks": &NetworksGenerator{},
"nodeGroups": &NodeGroupsGenerator{},
"nodeTemplates": &NodeTemplatesGenerator{},
"packetMirrorings": &PacketMirroringsGenerator{},
"regionAutoscalers": &RegionAutoscalersGenerator{},
"regionBackendServices": &RegionBackendServicesGenerator{},
"regionDisks": &RegionDisksGenerator{},
"regionHealthChecks": &RegionHealthChecksGenerator{},
"regionInstanceGroupManagers": &RegionInstanceGroupManagersGenerator{},
"regionInstanceGroups": &RegionInstanceGroupsGenerator{},
"regionSslCertificates": &RegionSslCertificatesGenerator{},
"regionTargetHttpProxies": &RegionTargetHttpProxiesGenerator{},
"regionTargetHttpsProxies": &RegionTargetHttpsProxiesGenerator{},
"regionUrlMaps": &RegionUrlMapsGenerator{},
"reservations": &ReservationsGenerator{},
"resourcePolicies": &ResourcePoliciesGenerator{},
"routers": &RoutersGenerator{},
"routes": &RoutesGenerator{},
"securityPolicies": &SecurityPoliciesGenerator{},
"sslCertificates": &SslCertificatesGenerator{},
"sslPolicies": &SslPoliciesGenerator{},
"subnetworks": &SubnetworksGenerator{},
"targetHttpProxies": &TargetHttpProxiesGenerator{},
"targetHttpsProxies": &TargetHttpsProxiesGenerator{},
"targetInstances": &TargetInstancesGenerator{},
"targetPools": &TargetPoolsGenerator{},
"targetSslProxies": &TargetSslProxiesGenerator{},
"targetTcpProxies": &TargetTcpProxiesGenerator{},
"targetVpnGateways": &TargetVpnGatewaysGenerator{},
"urlMaps": &UrlMapsGenerator{},
"vpnTunnels": &VpnTunnelsGenerator{},
"addresses": &GCPFacade{service: &AddressesGenerator{}},
"autoscalers": &GCPFacade{service: &AutoscalersGenerator{}},
"backendBuckets": &GCPFacade{service: &BackendBucketsGenerator{}},
"backendServices": &GCPFacade{service: &BackendServicesGenerator{}},
"disks": &GCPFacade{service: &DisksGenerator{}},
"externalVpnGateways": &GCPFacade{service: &ExternalVpnGatewaysGenerator{}},
"firewall": &GCPFacade{service: &FirewallGenerator{}},
"forwardingRules": &GCPFacade{service: &ForwardingRulesGenerator{}},
"globalAddresses": &GCPFacade{service: &GlobalAddressesGenerator{}},
"globalForwardingRules": &GCPFacade{service: &GlobalForwardingRulesGenerator{}},
"healthChecks": &GCPFacade{service: &HealthChecksGenerator{}},
"httpHealthChecks": &GCPFacade{service: &HttpHealthChecksGenerator{}},
"httpsHealthChecks": &GCPFacade{service: &HttpsHealthChecksGenerator{}},
"images": &GCPFacade{service: &ImagesGenerator{}},
"instanceGroupManagers": &GCPFacade{service: &InstanceGroupManagersGenerator{}},
"instanceGroups": &GCPFacade{service: &InstanceGroupsGenerator{}},
"instanceTemplates": &GCPFacade{service: &InstanceTemplatesGenerator{}},
"interconnectAttachments": &GCPFacade{service: &InterconnectAttachmentsGenerator{}},
"networkEndpointGroups": &GCPFacade{service: &NetworkEndpointGroupsGenerator{}},
"networks": &GCPFacade{service: &NetworksGenerator{}},
"nodeGroups": &GCPFacade{service: &NodeGroupsGenerator{}},
"nodeTemplates": &GCPFacade{service: &NodeTemplatesGenerator{}},
"packetMirrorings": &GCPFacade{service: &PacketMirroringsGenerator{}},
"regionAutoscalers": &GCPFacade{service: &RegionAutoscalersGenerator{}},
"regionBackendServices": &GCPFacade{service: &RegionBackendServicesGenerator{}},
"regionDisks": &GCPFacade{service: &RegionDisksGenerator{}},
"regionHealthChecks": &GCPFacade{service: &RegionHealthChecksGenerator{}},
"regionInstanceGroupManagers": &GCPFacade{service: &RegionInstanceGroupManagersGenerator{}},
"regionInstanceGroups": &GCPFacade{service: &RegionInstanceGroupsGenerator{}},
"regionSslCertificates": &GCPFacade{service: &RegionSslCertificatesGenerator{}},
"regionTargetHttpProxies": &GCPFacade{service: &RegionTargetHttpProxiesGenerator{}},
"regionTargetHttpsProxies": &GCPFacade{service: &RegionTargetHttpsProxiesGenerator{}},
"regionUrlMaps": &GCPFacade{service: &RegionUrlMapsGenerator{}},
"reservations": &GCPFacade{service: &ReservationsGenerator{}},
"resourcePolicies": &GCPFacade{service: &ResourcePoliciesGenerator{}},
"routers": &GCPFacade{service: &RoutersGenerator{}},
"routes": &GCPFacade{service: &RoutesGenerator{}},
"securityPolicies": &GCPFacade{service: &SecurityPoliciesGenerator{}},
"sslCertificates": &GCPFacade{service: &SslCertificatesGenerator{}},
"sslPolicies": &GCPFacade{service: &SslPoliciesGenerator{}},
"subnetworks": &GCPFacade{service: &SubnetworksGenerator{}},
"targetHttpProxies": &GCPFacade{service: &TargetHttpProxiesGenerator{}},
"targetHttpsProxies": &GCPFacade{service: &TargetHttpsProxiesGenerator{}},
"targetInstances": &GCPFacade{service: &TargetInstancesGenerator{}},
"targetPools": &GCPFacade{service: &TargetPoolsGenerator{}},
"targetSslProxies": &GCPFacade{service: &TargetSslProxiesGenerator{}},
"targetTcpProxies": &GCPFacade{service: &TargetTcpProxiesGenerator{}},
"targetVpnGateways": &GCPFacade{service: &TargetVpnGatewaysGenerator{}},
"urlMaps": &GCPFacade{service: &UrlMapsGenerator{}},
"vpnTunnels": &GCPFacade{service: &VpnTunnelsGenerator{}},
}
4 changes: 2 additions & 2 deletions providers/gcp/dataproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g DataprocGenerator) createClusterResources(ctx context.Context, clusterLi
cluster.ClusterName,
cluster.ClusterName,
"google_dataproc_cluster",
"google",
g.ProviderName,
map[string]string{
"name": cluster.ClusterName,
"project": g.GetArgs()["project"].(string),
Expand Down Expand Up @@ -70,7 +70,7 @@ func (g DataprocGenerator) createJobResources(jobList *dataproc.ProjectsRegionsJ
job.Reference.JobId,
job.Reference.JobId,
"google_dataproc_job",
"google",
g.ProviderName,
map[string]string{
"project": g.GetArgs()["project"].(string),
"region": g.GetArgs()["region"].(compute.Region).Name,
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/disks_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (g DisksGenerator) createResources(ctx context.Context, disksList *compute.
zone+"/"+obj.Name,
zone+"/"+obj.Name,
"google_compute_disk",
"google",
g.ProviderName,
map[string]string{
"name": obj.Name,
"project": g.GetArgs()["project"].(string),
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/externalVpnGateways_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g ExternalVpnGatewaysGenerator) createResources(ctx context.Context, exter
obj.Name,
obj.Name,
"google_compute_external_vpn_gateway",
"google",
g.ProviderName,
map[string]string{
"name": obj.Name,
"project": g.GetArgs()["project"].(string),
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/firewall_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g FirewallGenerator) createResources(ctx context.Context, firewallList *co
obj.Name,
obj.Name,
"google_compute_firewall",
"google",
g.ProviderName,
map[string]string{
"name": obj.Name,
"project": g.GetArgs()["project"].(string),
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/forwardingRules_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g ForwardingRulesGenerator) createResources(ctx context.Context, forwardin
obj.Name,
obj.Name,
"google_compute_forwarding_rule",
"google",
g.ProviderName,
map[string]string{
"name": obj.Name,
"project": g.GetArgs()["project"].(string),
Expand Down
4 changes: 2 additions & 2 deletions providers/gcp/gcp_compute_code_generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (g {{.titleResourceName}}Generator) createResources(ctx context.Context, {{
{{ if .idWithZone }}zone+"/"+obj.Name,{{else}}obj.Name,{{end}}
{{ if .idWithZone }}zone+"/"+obj.Name,{{else}}obj.Name,{{end}}
"{{.terraformName}}",
"google",
g.ProviderName,
map[string]string{
"name": obj.Name,
"project": g.GetArgs()["project"].(string),
Expand Down Expand Up @@ -145,7 +145,7 @@ import (
// Map of supported GCP compute service with code generate
var ComputeServices = map[string]terraformutils.ServiceGenerator{
{{ range $key, $value := .services }}
"{{$key}}": &{{title $key}}Generator{},{{ end }}
"{{$key}}": &GCPFacade{service: &{{title $key}}Generator{}},{{ end }}
}
Expand Down
Loading

0 comments on commit e37cb3d

Please sign in to comment.