Skip to content

nits: incorrect condition stmt for options.Excludes#1929

Merged
sergeylanzman merged 1 commit intoGoogleCloudPlatform:masterfrom
Shion1305:shion/excludes-condition-fix
Mar 26, 2025
Merged

nits: incorrect condition stmt for options.Excludes#1929
sergeylanzman merged 1 commit intoGoogleCloudPlatform:masterfrom
Shion1305:shion/excludes-condition-fix

Conversation

@Shion1305
Copy link
Contributor

@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

@sergeylanzman sergeylanzman enabled auto-merge (squash) March 26, 2025 21:29
@sergeylanzman sergeylanzman merged commit 930ce5b into GoogleCloudPlatform:master Mar 26, 2025
1 of 3 checks passed
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.

2 participants