Skip to content

Commit

Permalink
add golint
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeylanzman committed May 2, 2020
1 parent 42780d7 commit 09d8604
Show file tree
Hide file tree
Showing 363 changed files with 1,905 additions and 1,921 deletions.
5 changes: 3 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ run:
# exit code when at least one issue was found, default is 1
issues-exit-code: 1

max-issues-per-linter: 0
max-same-issues: 0
# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
Expand Down Expand Up @@ -64,8 +66,7 @@ linters:
- varcheck
- gofmt
#- gomnd
#- gosec
#- golint
- golint
- goimports
#- gocritic
#- wsl
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Flags:
-p, --path-pattern string {output}/{provider}/ (default "{output}/{provider}/{service}/")
--projects strings
-z, --regions strings europe-west1, (default [global])
-r, --resources strings firewalls,networks or * for all services
-r, --resources strings firewall,networks or * for all services
-s, --state string local or bucket (default "local")
-v, --verbose verbose mode
Expand Down Expand Up @@ -116,7 +116,7 @@ The `plan` command generates a planfile that contains all the resources set to b
The rest of subcommands and parameters are identical to the `import` command.

```
$ terraformer plan google --resources=networks,firewalls --projects=my-project --regions=europe-west1-d
$ terraformer plan google --resources=networks,firewall --projects=my-project --regions=europe-west1-d
(snip)
Saving planfile to generated/google/my-project/terraformer/plan.json
Expand Down Expand Up @@ -247,7 +247,7 @@ List of supported GCP services:
* `dns`
* `google_dns_managed_zone`
* `google_dns_record_set`
* `firewalls`
* `firewall`
* `google_compute_firewall`
* `forwardingRules`
* `google_compute_forwarding_rule`
Expand Down
55 changes: 27 additions & 28 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
"sort"
"strings"

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

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

"github.com/spf13/pflag"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/GoogleCloudPlatform/terraformer/terraform_utils/terraform_output"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/GoogleCloudPlatform/terraformer/terraformutils/terraformoutput"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -75,7 +75,7 @@ func newImportCmd() *cobra.Command {
return cmd
}

func Import(provider terraform_utils.ProviderGenerator, options ImportOptions, args []string) error {
func Import(provider terraformutils.ProviderGenerator, options ImportOptions, args []string) error {
err := provider.Init(args)
if err != nil {
return err
Expand All @@ -84,10 +84,10 @@ func Import(provider terraform_utils.ProviderGenerator, options ImportOptions, a
Provider: provider.GetName(),
Options: options,
Args: args,
ImportedResource: map[string][]terraform_utils.Resource{},
ImportedResource: map[string][]terraformutils.Resource{},
}

if terraformer_string.ContainsString(options.Resources, "*") {
if terraformerstring.ContainsString(options.Resources, "*") {
log.Println("Attempting an import of ALL resources in " + provider.GetName())
options.Resources = providerServices(provider)
}
Expand All @@ -104,15 +104,15 @@ func Import(provider terraform_utils.ProviderGenerator, options ImportOptions, a
return err
}

providerWrapper, err := provider_wrapper.NewProviderWrapper(provider.GetName(), provider.GetConfig(), options.Verbose)
providerWrapper, err := providerwrapper.NewProviderWrapper(provider.GetName(), provider.GetConfig(), options.Verbose)
if err != nil {
return err
}

provider.GetService().PopulateIgnoreKeys(providerWrapper)
provider.GetService().InitialCleanup()

refreshedResources, err := terraform_utils.RefreshResources(provider.GetService().GetResources(), providerWrapper)
refreshedResources, err := terraformutils.RefreshResources(provider.GetService().GetResources(), providerWrapper)
if err != nil {
return err
}
Expand All @@ -139,23 +139,22 @@ func Import(provider terraform_utils.ProviderGenerator, options ImportOptions, a
if options.Plan {
path := Path(options.PathPattern, provider.GetName(), "terraformer", options.PathOutput)
return ExportPlanFile(plan, path, "plan.json")
} else {
return ImportFromPlan(provider, plan)
}
return ImportFromPlan(provider, plan)
}

func ImportFromPlan(provider terraform_utils.ProviderGenerator, plan *ImportPlan) error {
func ImportFromPlan(provider terraformutils.ProviderGenerator, plan *ImportPlan) error {
options := plan.Options
importedResource := plan.ImportedResource
isServicePath := strings.Contains(options.PathPattern, "{service}")

if options.Connect {
log.Println(provider.GetName() + " Connecting.... ")
importedResource = terraform_utils.ConnectServices(importedResource, isServicePath, provider.GetResourceConnections())
importedResource = terraformutils.ConnectServices(importedResource, isServicePath, provider.GetResourceConnections())
}

if !isServicePath {
var compactedResources []terraform_utils.Resource
var compactedResources []terraformutils.Resource
for _, resources := range importedResource {
compactedResources = append(compactedResources, resources...)
}
Expand All @@ -174,30 +173,30 @@ func ImportFromPlan(provider terraform_utils.ProviderGenerator, plan *ImportPlan
return nil
}

func printService(provider terraform_utils.ProviderGenerator, serviceName string, options ImportOptions, resources []terraform_utils.Resource, importedResource map[string][]terraform_utils.Resource) error {
func printService(provider terraformutils.ProviderGenerator, serviceName string, options ImportOptions, resources []terraformutils.Resource, importedResource map[string][]terraformutils.Resource) error {
log.Println(provider.GetName() + " save " + serviceName)
// Print HCL files for Resources
path := Path(options.PathPattern, provider.GetName(), serviceName, options.PathOutput)
err := terraform_output.OutputHclFiles(resources, provider, path, serviceName, options.Compact, options.Output)
err := terraformoutput.OutputHclFiles(resources, provider, path, serviceName, options.Compact, options.Output)
if err != nil {
return err
}
tfStateFile, err := terraform_utils.PrintTfState(resources)
tfStateFile, err := terraformutils.PrintTfState(resources)
if err != nil {
return err
}
// print or upload State file
if options.State == "bucket" {
log.Println(provider.GetName() + " upload tfstate to bucket " + options.Bucket)
bucket := terraform_output.BucketState{
bucket := terraformoutput.BucketState{
Name: options.Bucket,
}
if err := bucket.BucketUpload(path, tfStateFile); err != nil {
return err
}
// create Bucket file
if bucketStateDataFile, err := terraform_utils.Print(bucket.BucketGetTfData(path), map[string]struct{}{}, options.Output); err == nil {
terraform_output.PrintFile(path+"/bucket.tf", bucketStateDataFile)
if bucketStateDataFile, err := terraformutils.Print(bucket.BucketGetTfData(path), map[string]struct{}{}, options.Output); err == nil {
terraformoutput.PrintFile(path+"/bucket.tf", bucketStateDataFile)
}
} else {
if serviceName == "" {
Expand All @@ -216,7 +215,7 @@ func printService(provider terraform_utils.ProviderGenerator, serviceName string
variables["data"] = map[string]map[string]interface{}{}
variables["data"]["terraform_remote_state"] = map[string]interface{}{}
if options.State == "bucket" {
bucket := terraform_output.BucketState{
bucket := terraformoutput.BucketState{
Name: options.Bucket,
}
for k := range provider.GetResourceConnections()[serviceName] {
Expand All @@ -243,11 +242,11 @@ func printService(provider terraform_utils.ProviderGenerator, serviceName string
}
// create variables file
if len(provider.GetResourceConnections()[serviceName]) > 0 && options.Connect && len(variables["data"]["terraform_remote_state"]) > 0 {
variablesFile, err := terraform_utils.Print(variables, map[string]struct{}{"config": {}}, options.Output)
variablesFile, err := terraformutils.Print(variables, map[string]struct{}{"config": {}}, options.Output)
if err != nil {
return err
}
terraform_output.PrintFile(path+"/variables."+terraform_output.GetFileExtension(options.Output), variablesFile)
terraformoutput.PrintFile(path+"/variables."+terraformoutput.GetFileExtension(options.Output), variablesFile)
}
}
} else {
Expand All @@ -256,7 +255,7 @@ func printService(provider terraform_utils.ProviderGenerator, serviceName string
variables["data"] = map[string]map[string]interface{}{}
variables["data"]["terraform_remote_state"] = map[string]interface{}{}
if options.State == "bucket" {
bucket := terraform_output.BucketState{
bucket := terraformoutput.BucketState{
Name: options.Bucket,
}
variables["data"]["terraform_remote_state"]["local"] = map[string]interface{}{
Expand All @@ -273,11 +272,11 @@ func printService(provider terraform_utils.ProviderGenerator, serviceName string
}
// create variables file
if options.Connect {
variablesFile, err := terraform_utils.Print(variables, map[string]struct{}{"config": {}}, options.Output)
variablesFile, err := terraformutils.Print(variables, map[string]struct{}{"config": {}}, options.Output)
if err != nil {
return err
}
terraform_output.PrintFile(path+"/variables."+terraform_output.GetFileExtension(options.Output), variablesFile)
terraformoutput.PrintFile(path+"/variables."+terraformoutput.GetFileExtension(options.Output), variablesFile)
}
}
}
Expand All @@ -292,7 +291,7 @@ func Path(pathPattern, providerName, serviceName, output string) string {
).Replace(pathPattern)
}

func listCmd(provider terraform_utils.ProviderGenerator) *cobra.Command {
func listCmd(provider terraformutils.ProviderGenerator) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List supported resources for " + provider.GetName() + " provider",
Expand All @@ -309,7 +308,7 @@ func listCmd(provider terraform_utils.ProviderGenerator) *cobra.Command {
return cmd
}

func providerServices(provider terraform_utils.ProviderGenerator) []string {
func providerServices(provider terraformutils.ProviderGenerator) []string {
var services []string
for k := range provider.GetSupportedService() {
services = append(services, k)
Expand Down
6 changes: 3 additions & 3 deletions cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"os"
"path/filepath"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/spf13/cobra"
)

Expand All @@ -29,7 +29,7 @@ type ImportPlan struct {
Provider string
Options ImportOptions
Args []string
ImportedResource map[string][]terraform_utils.Resource
ImportedResource map[string][]terraformutils.Resource
}

func newPlanCmd() *cobra.Command {
Expand Down Expand Up @@ -63,7 +63,7 @@ func newCmdPlanImporter(options ImportOptions) *cobra.Command {
return err
}

var provider terraform_utils.ProviderGenerator
var provider terraformutils.ProviderGenerator
if providerGen, ok := providerGenerators()[plan.Provider]; ok {
provider = providerGen()
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/provider_cmd_alicloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"log"

alicloud_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/alicloud"
"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -49,6 +49,6 @@ func newCmdAliCloudImporter(options ImportOptions) *cobra.Command {
return cmd
}

func newAliCloudProvider() terraform_utils.ProviderGenerator {
func newAliCloudProvider() terraformutils.ProviderGenerator {
return &alicloud_terraforming.AliCloudProvider{}
}
16 changes: 7 additions & 9 deletions cmd/provider_cmd_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"log"

awsterraformer "github.com/GoogleCloudPlatform/terraformer/providers/aws"
"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -55,11 +55,10 @@ func newCmdAwsImporter(options ImportOptions) *cobra.Command {
}
}
return nil
} else {
err := importRegionResources(options, options.PathPattern, awsterraformer.NoRegion, false)
if err != nil {
return err
}
}
err := importRegionResources(options, options.PathPattern, awsterraformer.NoRegion, false)
if err != nil {
return err
}
return nil
},
Expand All @@ -85,9 +84,8 @@ func parseGlobalResources(allResources []string) []string {
func importGlobalResources(options ImportOptions) error {
if len(options.Resources) > 0 {
return importRegionResources(options, options.PathPattern, awsterraformer.GlobalRegion, false)
} else {
return nil
}
return nil
}

func parseRegionalResources(allResources []string) []string {
Expand Down Expand Up @@ -118,7 +116,7 @@ func importRegionResources(options ImportOptions, originalPathPattern string, re
return nil
}

func newAWSProvider() terraform_utils.ProviderGenerator {
func newAWSProvider() terraformutils.ProviderGenerator {
return &awsterraformer.AWSProvider{}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/provider_cmd_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package cmd
import (
azure_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/azure"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/spf13/cobra"
)

Expand All @@ -40,6 +40,6 @@ func newCmdAzureImporter(options ImportOptions) *cobra.Command {
return cmd
}

func newAzureProvider() terraform_utils.ProviderGenerator {
func newAzureProvider() terraformutils.ProviderGenerator {
return &azure_terraforming.AzureProvider{}
}
4 changes: 2 additions & 2 deletions cmd/provider_cmd_cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package cmd
import (
cloudflare_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/cloudflare"

"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/spf13/cobra"
)

Expand All @@ -40,6 +40,6 @@ func newCmdCloudflareImporter(options ImportOptions) *cobra.Command {
return cmd
}

func newCloudflareProvider() terraform_utils.ProviderGenerator {
func newCloudflareProvider() terraformutils.ProviderGenerator {
return &cloudflare_terraforming.CloudflareProvider{}
}
4 changes: 2 additions & 2 deletions cmd/provider_cmd_commercetools.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"os"

commercetools_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/commercetools"
"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -70,6 +70,6 @@ func newCmdCommercetoolsImporter(options ImportOptions) *cobra.Command {
return cmd
}

func newCommercetoolsProvider() terraform_utils.ProviderGenerator {
func newCommercetoolsProvider() terraformutils.ProviderGenerator {
return &commercetools_terraforming.CommercetoolsProvider{}
}
4 changes: 2 additions & 2 deletions cmd/provider_cmd_datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package cmd

import (
datadog_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/datadog"
"github.com/GoogleCloudPlatform/terraformer/terraform_utils"
"github.com/GoogleCloudPlatform/terraformer/terraformutils"
"github.com/spf13/cobra"
)

Expand All @@ -41,6 +41,6 @@ func newCmdDatadogImporter(options ImportOptions) *cobra.Command {
return cmd
}

func newDataDogProvider() terraform_utils.ProviderGenerator {
func newDataDogProvider() terraformutils.ProviderGenerator {
return &datadog_terraforming.DatadogProvider{}
}
Loading

0 comments on commit 09d8604

Please sign in to comment.