gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.09k stars 981 forks source link

Fixing registry host discovery (Terragrunt Provider Cache) #3432

Closed levkohimins closed 1 month ago

levkohimins commented 1 month ago

Description

Fixes #3421.

TODOs

Read the Gruntwork contribution guidelines.

Release Notes (draft)

Added / Removed / Updated [X].

Migration Guide

yhakbar commented 1 month ago

@levkohimins , take note of the strict lint results:

cli/provider_cache.go:149: Function 'TerraformCommandHook' is too long (67 > 60) (funlen)
func (cache *ProviderCache) TerraformCommandHook(ctx context.Context, opts *options.TerragruntOptions, args cli.Args) (*util.CmdOutput, error) {
pkg/cli/args.go:39:55: Comment should end in a period (godot)
// Second returns the first argument or a blank string
                                                      ^
terraform/cache/handlers/provider.go:111:56: Comment should end in a period (godot)
// DiscoveryURL implements ProviderHandler.DiscoveryURL
                                                       ^
pkg/cli/args.go:120: line is 166 characters (lll)
// SubCommandName returns the second value if it starts without a dash `-`, otherwise that means the args do not consist a subcommand and an empty string is returned.
terraform/cache/handlers/provider.go:36: line is 180 characters (lll)
// DiscoveryURL looks for the first handler that can handle the given `registryName`, which is determined by the include and exclude settings in the `.terraformrc` CLI config file.
terraform/cache/handlers/provider.go:76: line is 155 characters (lll)
        // We use [xsync.MapOf](https://github.com/puzpuzpuz/xsync?tab=readme-ov-file#map) instead of standard `sync.Map` since it's faster and has generic types.
terraform/cache/handlers/provider.go:80: line is 127 characters (lll)
func NewCommonProviderHandler(providerService *services.ProviderService, includes, excludes *[]string) *CommonProviderHandler {
terraform/cache/handlers/provider.go:124: line is 139 characters (lll)
                handler.providerService.Logger().Debugf("Unable to discover %q registry URLs, reason: %q, use default URLs: %s", registryName, err, urls)
terraform/cache/handlers/provider_direct.go:58: line is 148 characters (lll)
// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/private-registry/provider-versions-platforms#get-all-versions-for-a-single-provider
terraform/cache/handlers/provider_direct.go:84: line is 134 characters (lll)
                Path:   path.Join(apiURLs.ProvidersV1, provider.Namespace, provider.Name, provider.Version, "download", provider.OS, provider.Arch),
terraform/cache/handlers/provider_direct.go:128: line is 126 characters (lll)
                        Path:   filepath.Join(apiURLs.ProvidersV1, provider.RegistryName, provider.Namespace, provider.Name, provider.DownloadURL),
terraform/cache/controllers/provider.go:52: line is 128 characters (lll)
        controller.GET("/:cache_request_id/:registry_name/:namespace/:name/:version/download/:os/:arch", controller.getPlatformsAction)
terraform/cache/server.go:63: line is 180 characters (lll)
// DiscoveryURL looks for the first handler that can handle the given `registryName`, which is determined by the include and exclude settings in the `.terraformrc` CLI config file.
shell/context.go:22: line is 123 characters (lll)
type RunShellCommandFunc func(ctx context.Context, opts *options.TerragruntOptions, args cli.Args) (*util.CmdOutput, error)
terraform/cache/handlers/provider.go:34:6: exported: exported type ProviderHandlers should have comment or be unexported (revive)
type ProviderHandlers []ProviderHandler
     ^
terraform/cache/handlers/provider.go:43:11: error returned from interface method should be wrapped: sig: func (github.com/gruntwork-io/terragrunt/terraform/cache/handlers.ProviderHandler).DiscoveryURL(ctx context.Context, registryName string) (*github.com/gruntwork-io/terragrunt/terraform/cache/handlers.RegistryURLs, error) (wrapcheck)
                        return handler.DiscoveryURL(ctx, registryName)
                               ^
terraform/cache/server.go:66:9: error returned from external package is unwrapped: sig: func (github.com/gruntwork-io/terragrunt/terraform/cache/handlers.ProviderHandlers).DiscoveryURL(ctx context.Context, registryName string) (*github.com/gruntwork-io/terragrunt/terraform/cache/handlers.RegistryURLs, error) (wrapcheck)
        return server.providerHandlers.DiscoveryURL(ctx, registryName)
               ^
cli/provider_cache.go:259:11: error returned from external package is unwrapped: sig: func (*github.com/gruntwork-io/terragrunt/terraform/cache.Server).DiscoveryURL(ctx context.Context, registryName string) (*github.com/gruntwork-io/terragrunt/terraform/cache/handlers.RegistryURLs, error) (wrapcheck)
                        return err

If possible, we should revisit the contents of this PR with another PR to address the findings either by:

  1. Fixing the issue.
  2. Adding an explicit ignore.
levkohimins commented 1 month ago

If possible, we should revisit the contents of this PR with another PR to address the findings either by:

  1. Fixing the issue.
  2. Adding an explicit ignore.

I fixed everything and I will try to fix it in the future as well.

levkohimins commented 1 month ago

Resolved in v0.67.12 release.