Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nits: incorrect condition stmt for options.Excludes #1929

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Shion1305
Copy link

@Shion1305 Shion1305 commented Sep 28, 2024

In cmd/import.go, there is an implementation that checks whether Excludes options is specified.
The default value for options.Excludes is []string{} as you can see here:

terraformer/cmd/import.go

Lines 395 to 410 in a5b4b69

func baseProviderFlags(flag *pflag.FlagSet, options *ImportOptions, sampleRes, sampleFilters string) {
flag.BoolVarP(&options.Connect, "connect", "c", true, "")
flag.BoolVarP(&options.Compact, "compact", "C", false, "")
flag.StringSliceVarP(&options.Resources, "resources", "r", []string{}, sampleRes)
flag.StringSliceVarP(&options.Excludes, "excludes", "x", []string{}, sampleRes)
flag.StringVarP(&options.PathPattern, "path-pattern", "p", DefaultPathPattern, "{output}/{provider}/")
flag.StringVarP(&options.PathOutput, "path-output", "o", DefaultPathOutput, "")
flag.StringVarP(&options.State, "state", "s", DefaultState, "local or bucket")
flag.StringVarP(&options.Bucket, "bucket", "b", "", "gs://terraform-state")
flag.StringSliceVarP(&options.Filter, "filter", "f", []string{}, sampleFilters)
flag.BoolVarP(&options.Verbose, "verbose", "v", false, "")
flag.BoolVarP(&options.NoSort, "no-sort", "S", false, "set to disable sorting of HCL")
flag.StringVarP(&options.Output, "output", "O", "hcl", "output format hcl or json")
flag.IntVarP(&options.RetryCount, "retry-number", "n", 5, "number of retries to perform when refresh fails")
flag.IntVarP(&options.RetrySleepMs, "retry-sleep-ms", "m", 300, "time in ms to sleep between retries")
}

However, the condition statement for checking options.Excludes is if options.Excludes != nil.

if options.Excludes != nil {

As default value for options.Excludes is []string{}, this always results true.

This should be fixed as len(options.Excludes) > 0
This does not cause panic when option.Excludes is false as you can see here

You can see similar implementation here:

if len(options.Resources) > 0 { // don't import anything and potentially override global resources

@github-actions github-actions bot added the Stale label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant