From aed202d8965b6629f041a9d457f95d8c77b8216e Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 12 May 2022 22:18:09 +0100 Subject: [PATCH 1/2] Switch to the new minimal terraform-registry-address API --- go.mod | 4 +- go.sum | 9 ++- internal/decoder/path_reader.go | 2 +- .../handlers/did_change_watched_files_test.go | 2 +- .../execute_command_module_providers_test.go | 16 +++-- internal/registry/registry.go | 16 ++--- internal/registry/registry_test.go | 4 +- internal/schemas/preload_schemas.go | 9 +-- internal/state/installed_providers_test.go | 25 ++++--- internal/state/module.go | 2 +- internal/state/module_test.go | 16 ++--- internal/state/provider_schema.go | 30 ++++++++- internal/state/provider_schema_test.go | 66 +++++++++---------- internal/state/registry_modules.go | 6 +- internal/state/registry_modules_test.go | 4 +- internal/state/state.go | 2 +- internal/telemetry/telemetry.go | 4 +- internal/terraform/datadir/module_types.go | 4 +- internal/terraform/module/module_ops.go | 6 +- internal/terraform/module/module_ops_test.go | 6 +- 20 files changed, 128 insertions(+), 105 deletions(-) diff --git a/go.mod b/go.mod index 08df15a29..0c5363909 100644 --- a/go.mod +++ b/go.mod @@ -18,8 +18,8 @@ require ( github.com/hashicorp/hcl/v2 v2.13.0 github.com/hashicorp/terraform-exec v0.17.0 github.com/hashicorp/terraform-json v0.14.0 - github.com/hashicorp/terraform-registry-address v0.0.0-20220422093245-eb7bcc2ff473 - github.com/hashicorp/terraform-schema v0.0.0-20220617163605-9aece33a9bbb + github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c + github.com/hashicorp/terraform-schema v0.0.0-20220623144511-7930e05d32f8 github.com/kylelemons/godebug v1.1.0 // indirect github.com/mh-cbon/go-fmt-fail v0.0.0-20160815164508-67765b3fbcb5 github.com/mitchellh/cli v1.1.4 diff --git a/go.sum b/go.sum index 2ad062376..85f63f4c2 100644 --- a/go.sum +++ b/go.sum @@ -331,7 +331,6 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T github.com/hashicorp/hcl-lang v0.0.0-20220421093840-480fdfd2ecb5 h1:A18R+0Emk5YuXo22u44wxwHAnNHLDK6NHxXl2CIQGlU= github.com/hashicorp/hcl-lang v0.0.0-20220421093840-480fdfd2ecb5/go.mod h1:oQgcOV8OizFyZfZh3FbQSsQtvtTv8hD23MLAxfn3E+E= github.com/hashicorp/hcl/v2 v2.11.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= -github.com/hashicorp/hcl/v2 v2.12.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg= github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= @@ -343,10 +342,10 @@ github.com/hashicorp/terraform-exec v0.17.0 h1:fbhFnrn9QLN2jt+TDDBfLmdZyW3w1d5Kc github.com/hashicorp/terraform-exec v0.17.0/go.mod h1:P6V5KRHsLIu0vMlaKBgSbF+ADUXZhcE2n/wGX66Bcf0= github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e17dKDpqV7s= github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= -github.com/hashicorp/terraform-registry-address v0.0.0-20220422093245-eb7bcc2ff473 h1:Vp3YMcnM+TvVMV5TplAhGeuzz3A0562AywL32y71y3Y= -github.com/hashicorp/terraform-registry-address v0.0.0-20220422093245-eb7bcc2ff473/go.mod h1:bdLC+qQlJIBHKbCMA6GipcuaKjmjcvZlnVdpU583z3Y= -github.com/hashicorp/terraform-schema v0.0.0-20220617163605-9aece33a9bbb h1:ZVpBMZlvIwHzFfSfNCspuH5WG8p5N8fn1Rjqayoxbmc= -github.com/hashicorp/terraform-schema v0.0.0-20220617163605-9aece33a9bbb/go.mod h1:zphXkRtXhZ1vC60ytqhUBSnKDyYHBaV321zNgYuLKxs= +github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg= +github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI= +github.com/hashicorp/terraform-schema v0.0.0-20220623144511-7930e05d32f8 h1:Smd1F42NuW2MCrS9MaolywhWnCPBosYa/JSniOusDiw= +github.com/hashicorp/terraform-schema v0.0.0-20220623144511-7930e05d32f8/go.mod h1:d1/gzOC/dLDNRI0lmhRPEtZoQl/9eaRjDGSb/GnliPo= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= diff --git a/internal/decoder/path_reader.go b/internal/decoder/path_reader.go index 049d21c8d..bff7c0218 100644 --- a/internal/decoder/path_reader.go +++ b/internal/decoder/path_reader.go @@ -19,7 +19,7 @@ type ModuleReader interface { List() ([]*state.Module, error) ModuleCalls(modPath string) (tfmod.ModuleCalls, error) LocalModuleMeta(modPath string) (*tfmod.Meta, error) - RegistryModuleMeta(addr tfaddr.ModuleSourceRegistry, cons version.Constraints) (*registry.ModuleData, error) + RegistryModuleMeta(addr tfaddr.Module, cons version.Constraints) (*registry.ModuleData, error) } type PathReader struct { diff --git a/internal/langserver/handlers/did_change_watched_files_test.go b/internal/langserver/handlers/did_change_watched_files_test.go index 288c8070f..1bc51d8ae 100644 --- a/internal/langserver/handlers/did_change_watched_files_test.go +++ b/internal/langserver/handlers/did_change_watched_files_test.go @@ -780,7 +780,7 @@ func TestLangServer_DidChangeWatchedFiles_pluginChange(t *testing.T) { ReqParams: "{}", }) - addr := tfaddr.MustParseRawProviderSourceString("-/test") + addr := tfaddr.MustParseProviderSource("-/test") vc := version.MustConstraints(version.NewConstraint(">= 1.0")) _, err = ss.ProviderSchemas.ProviderSchema(testHandle.Path(), addr, vc) diff --git a/internal/langserver/handlers/execute_command_module_providers_test.go b/internal/langserver/handlers/execute_command_module_providers_test.go index 6df86c24a..1e81284b4 100644 --- a/internal/langserver/handlers/execute_command_module_providers_test.go +++ b/internal/langserver/handlers/execute_command_module_providers_test.go @@ -79,12 +79,12 @@ func TestLangServer_workspaceExecuteCommand_moduleProviders_basic(t *testing.T) Path: modDir, CoreRequirements: testConstraint(t, "~> 0.15"), ProviderRequirements: map[tfaddr.Provider]version.Constraints{ - tfaddr.NewDefaultProvider("aws"): testConstraint(t, "1.2.3"), - tfaddr.NewDefaultProvider("google"): testConstraint(t, ">= 2.0.0"), + newDefaultProvider("aws"): testConstraint(t, "1.2.3"), + newDefaultProvider("google"): testConstraint(t, ">= 2.0.0"), }, ProviderReferences: map[tfmod.ProviderRef]tfaddr.Provider{ - {LocalName: "aws"}: tfaddr.NewDefaultProvider("aws"), - {LocalName: "google"}: tfaddr.NewDefaultProvider("google"), + {LocalName: "aws"}: newDefaultProvider("aws"), + {LocalName: "google"}: newDefaultProvider("google"), }, } @@ -94,8 +94,8 @@ func TestLangServer_workspaceExecuteCommand_moduleProviders_basic(t *testing.T) } pVersions := map[tfaddr.Provider]*version.Version{ - tfaddr.NewDefaultProvider("aws"): version.Must(version.NewVersion("1.2.3")), - tfaddr.NewDefaultProvider("google"): version.Must(version.NewVersion("2.5.5")), + newDefaultProvider("aws"): version.Must(version.NewVersion("1.2.3")), + newDefaultProvider("google"): version.Must(version.NewVersion("2.5.5")), } err = s.Modules.UpdateInstalledProviders(modDir, pVersions) if err != nil { @@ -159,6 +159,10 @@ func TestLangServer_workspaceExecuteCommand_moduleProviders_basic(t *testing.T) }`) } +func newDefaultProvider(name string) tfaddr.Provider { + return tfaddr.NewProvider(tfaddr.DefaultProviderRegistryHost, "hashicorp", name) +} + func testConstraint(t *testing.T, v string) version.Constraints { constraints, err := version.NewConstraint(v) if err != nil { diff --git a/internal/registry/registry.go b/internal/registry/registry.go index d98e66fc0..6c8cded41 100644 --- a/internal/registry/registry.go +++ b/internal/registry/registry.go @@ -29,7 +29,7 @@ func NewClient() Client { } } -func (c Client) GetModuleData(addr tfaddr.ModuleSourceRegistry, cons version.Constraints) (*ModuleResponse, error) { +func (c Client) GetModuleData(addr tfaddr.Module, cons version.Constraints) (*ModuleResponse, error) { var response ModuleResponse v, err := c.GetMatchingModuleVersion(addr, cons) @@ -41,9 +41,9 @@ func (c Client) GetModuleData(addr tfaddr.ModuleSourceRegistry, cons version.Con client.Timeout = defaultTimeout url := fmt.Sprintf("%s/v1/modules/%s/%s/%s/%s", c.BaseURL, - addr.PackageAddr.Namespace, - addr.PackageAddr.Name, - addr.PackageAddr.TargetSystem, + addr.Package.Namespace, + addr.Package.Name, + addr.Package.TargetSystem, v.String()) resp, err := client.Get(url) if err != nil { @@ -67,11 +67,11 @@ func (c Client) GetModuleData(addr tfaddr.ModuleSourceRegistry, cons version.Con return &response, nil } -func (c Client) GetMatchingModuleVersion(addr tfaddr.ModuleSourceRegistry, con version.Constraints) (*version.Version, error) { +func (c Client) GetMatchingModuleVersion(addr tfaddr.Module, con version.Constraints) (*version.Version, error) { url := fmt.Sprintf("%s/v1/modules/%s/%s/%s/versions", c.BaseURL, - addr.PackageAddr.Namespace, - addr.PackageAddr.Name, - addr.PackageAddr.TargetSystem) + addr.Package.Namespace, + addr.Package.Name, + addr.Package.TargetSystem) client := cleanhttp.DefaultClient() client.Timeout = defaultTimeout diff --git a/internal/registry/registry_test.go b/internal/registry/registry_test.go index ccd4a790e..794d74196 100644 --- a/internal/registry/registry_test.go +++ b/internal/registry/registry_test.go @@ -12,7 +12,7 @@ import ( ) func TestGetModuleData(t *testing.T) { - addr, err := tfaddr.ParseRawModuleSourceRegistry("puppetlabs/deployment/ec") + addr, err := tfaddr.ParseModuleSource("puppetlabs/deployment/ec") if err != nil { t.Fatal(err) } @@ -120,7 +120,7 @@ func TestGetModuleData(t *testing.T) { } func TestGetMatchingModuleVersion(t *testing.T) { - addr, err := tfaddr.ParseRawModuleSourceRegistry("puppetlabs/deployment/ec") + addr, err := tfaddr.ParseModuleSource("puppetlabs/deployment/ec") if err != nil { t.Fatal(err) } diff --git a/internal/schemas/preload_schemas.go b/internal/schemas/preload_schemas.go index 153d12341..80b0f9642 100644 --- a/internal/schemas/preload_schemas.go +++ b/internal/schemas/preload_schemas.go @@ -15,18 +15,15 @@ func PreloadSchemasToStore(pss *state.ProviderSchemaStore) error { for rawAddr, pJsonSchema := range pOut.Schemas { pv := vOut.Providers[rawAddr] - pAddr, err := tfaddr.ParseRawProviderSourceString(rawAddr) + pAddr, err := tfaddr.ParseProviderSource(rawAddr) if err != nil { // skip unparsable address continue } // Given that we use Terraform >0.12 for the generation // this should never happen - if pAddr.IsLegacy() { - iAddr, err := tfaddr.ParseAndInferProviderSourceString(rawAddr) - if err == nil { - pAddr = iAddr - } + if pAddr.IsLegacy() || !pAddr.HasKnownNamespace() { + pAddr.Hostname = "hashicorp" } pSchema := tfschema.ProviderSchemaFromJson(pJsonSchema, pAddr) diff --git a/internal/state/installed_providers_test.go b/internal/state/installed_providers_test.go index ecd18c230..68078e363 100644 --- a/internal/state/installed_providers_test.go +++ b/internal/state/installed_providers_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/hashicorp/go-version" - tfaddr "github.com/hashicorp/terraform-registry-address" ) func TestInstalledProviders(t *testing.T) { @@ -20,48 +19,48 @@ func TestInstalledProviders(t *testing.T) { }, { InstalledProviders{ - tfaddr.NewBuiltInProvider("terraform"): version.Must(version.NewVersion("1.0")), + NewBuiltInProvider("terraform"): version.Must(version.NewVersion("1.0")), }, InstalledProviders{ - tfaddr.NewBuiltInProvider("terraform"): version.Must(version.NewVersion("1.0")), + NewBuiltInProvider("terraform"): version.Must(version.NewVersion("1.0")), }, true, }, { InstalledProviders{ - tfaddr.NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), + NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), }, InstalledProviders{ - tfaddr.NewDefaultProvider("bar"): version.Must(version.NewVersion("1.0")), + NewDefaultProvider("bar"): version.Must(version.NewVersion("1.0")), }, false, }, { InstalledProviders{ - tfaddr.NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), + NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), }, InstalledProviders{ - tfaddr.NewDefaultProvider("foo"): version.Must(version.NewVersion("1.1")), + NewDefaultProvider("foo"): version.Must(version.NewVersion("1.1")), }, false, }, { InstalledProviders{ - tfaddr.NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), - tfaddr.NewDefaultProvider("bar"): version.Must(version.NewVersion("1.0")), + NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), + NewDefaultProvider("bar"): version.Must(version.NewVersion("1.0")), }, InstalledProviders{ - tfaddr.NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), + NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), }, false, }, { InstalledProviders{ - tfaddr.NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), + NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), }, InstalledProviders{ - tfaddr.NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), - tfaddr.NewDefaultProvider("bar"): version.Must(version.NewVersion("1.0")), + NewDefaultProvider("foo"): version.Must(version.NewVersion("1.0")), + NewDefaultProvider("bar"): version.Must(version.NewVersion("1.0")), }, false, }, diff --git a/internal/state/module.go b/internal/state/module.go index 3a96254c7..7b5be0ec6 100644 --- a/internal/state/module.go +++ b/internal/state/module.go @@ -370,7 +370,7 @@ func (s *ModuleStore) LocalModuleMeta(modPath string) (*tfmod.Meta, error) { }, nil } -func (s *ModuleStore) RegistryModuleMeta(addr tfaddr.ModuleSourceRegistry, cons version.Constraints) (*registry.ModuleData, error) { +func (s *ModuleStore) RegistryModuleMeta(addr tfaddr.Module, cons version.Constraints) (*registry.ModuleData, error) { txn := s.db.Txn(false) it, err := txn.Get(registryModuleTableName, "source_addr", addr) diff --git a/internal/state/module_test.go b/internal/state/module_test.go index 45ec50726..cf674b725 100644 --- a/internal/state/module_test.go +++ b/internal/state/module_test.go @@ -241,12 +241,12 @@ func TestModuleStore_UpdateMetadata(t *testing.T) { Path: tmpDir, CoreRequirements: testConstraint(t, "~> 0.15"), ProviderRequirements: map[tfaddr.Provider]version.Constraints{ - tfaddr.NewDefaultProvider("aws"): testConstraint(t, "1.2.3"), - tfaddr.NewDefaultProvider("google"): testConstraint(t, ">= 2.0.0"), + NewDefaultProvider("aws"): testConstraint(t, "1.2.3"), + NewDefaultProvider("google"): testConstraint(t, ">= 2.0.0"), }, ProviderReferences: map[tfmod.ProviderRef]tfaddr.Provider{ - {LocalName: "aws"}: tfaddr.NewDefaultProvider("aws"), - {LocalName: "google"}: tfaddr.NewDefaultProvider("google"), + {LocalName: "aws"}: NewDefaultProvider("aws"), + {LocalName: "google"}: NewDefaultProvider("google"), }, } @@ -270,12 +270,12 @@ func TestModuleStore_UpdateMetadata(t *testing.T) { Meta: ModuleMetadata{ CoreRequirements: testConstraint(t, "~> 0.15"), ProviderRequirements: map[tfaddr.Provider]version.Constraints{ - tfaddr.NewDefaultProvider("aws"): testConstraint(t, "1.2.3"), - tfaddr.NewDefaultProvider("google"): testConstraint(t, ">= 2.0.0"), + NewDefaultProvider("aws"): testConstraint(t, "1.2.3"), + NewDefaultProvider("google"): testConstraint(t, ">= 2.0.0"), }, ProviderReferences: map[tfmod.ProviderRef]tfaddr.Provider{ - {LocalName: "aws"}: tfaddr.NewDefaultProvider("aws"), - {LocalName: "google"}: tfaddr.NewDefaultProvider("google"), + {LocalName: "aws"}: NewDefaultProvider("aws"), + {LocalName: "google"}: NewDefaultProvider("google"), }, }, MetaState: operation.OpStateLoaded, diff --git a/internal/state/provider_schema.go b/internal/state/provider_schema.go index 475f0c715..07712cbad 100644 --- a/internal/state/provider_schema.go +++ b/internal/state/provider_schema.go @@ -214,14 +214,14 @@ func (s *ProviderSchemaStore) ProviderSchema(modPath string, addr tfaddr.Provide } } - if len(schemas) == 0 && addr.Equals(tfaddr.NewDefaultProvider("terraform")) { + if len(schemas) == 0 && addr.Equals(NewDefaultProvider("terraform")) { // assume that hashicorp/terraform is just the builtin provider - return s.ProviderSchema(modPath, tfaddr.NewBuiltInProvider("terraform"), vc) + return s.ProviderSchema(modPath, NewBuiltInProvider("terraform"), vc) } if len(schemas) == 0 && addr.IsLegacy() { if addr.Type == "terraform" { - return s.ProviderSchema(modPath, tfaddr.NewBuiltInProvider("terraform"), vc) + return s.ProviderSchema(modPath, NewBuiltInProvider("terraform"), vc) } // Schema may be missing e.g. because Terraform 0.12 @@ -275,6 +275,30 @@ func (s *ProviderSchemaStore) ProviderSchema(modPath string, addr tfaddr.Provide type ModuleLookupFunc func(string) (*Module, error) +func NewDefaultProvider(name string) tfaddr.Provider { + return tfaddr.Provider{ + Type: tfaddr.MustParseProviderPart(name), + Namespace: "hashicorp", + Hostname: tfaddr.DefaultProviderRegistryHost, + } +} + +func NewBuiltInProvider(name string) tfaddr.Provider { + return tfaddr.Provider{ + Type: tfaddr.MustParseProviderPart(name), + Namespace: tfaddr.BuiltInProviderNamespace, + Hostname: tfaddr.BuiltInProviderHost, + } +} + +func NewLegacyProvider(name string) tfaddr.Provider { + return tfaddr.Provider{ + Type: tfaddr.MustParseProviderPart(name), + Namespace: tfaddr.LegacyProviderNamespace, + Hostname: tfaddr.DefaultProviderRegistryHost, + } +} + type sortableSchemas struct { schemas []*ProviderSchema lookupModule ModuleLookupFunc diff --git a/internal/state/provider_schema_test.go b/internal/state/provider_schema_test.go index c299bb4bb..f1ec9adf8 100644 --- a/internal/state/provider_schema_test.go +++ b/internal/state/provider_schema_test.go @@ -20,7 +20,7 @@ func TestStateStore_AddPreloadedSchema_duplicate(t *testing.T) { } addr := tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", } @@ -58,7 +58,7 @@ func TestStateStore_IncompleteSchema_legacyLookup(t *testing.T) { } addr := tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", } @@ -76,7 +76,7 @@ func TestStateStore_IncompleteSchema_legacyLookup(t *testing.T) { t.Fatal(err) } - _, err = s.ProviderSchemas.ProviderSchema(modPath, tfaddr.NewLegacyProvider("aws"), testConstraint(t, ">= 1.0")) + _, err = s.ProviderSchemas.ProviderSchema(modPath, NewLegacyProvider("aws"), testConstraint(t, ">= 1.0")) if err == nil { t.Fatal("expected error when requesting incomplete schema") } @@ -92,7 +92,7 @@ func TestStateStore_IncompleteSchema_legacyLookup(t *testing.T) { t.Fatal(err) } - ps, err := s.ProviderSchemas.ProviderSchema(modPath, tfaddr.NewLegacyProvider("aws"), testConstraint(t, ">= 1.0")) + ps, err := s.ProviderSchemas.ProviderSchema(modPath, NewLegacyProvider("aws"), testConstraint(t, ">= 1.0")) if err != nil { t.Fatal(err) } @@ -109,7 +109,7 @@ func TestStateStore_AddLocalSchema_duplicate(t *testing.T) { modPath := t.TempDir() addr := tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", } @@ -159,7 +159,7 @@ func TestStateStore_AddLocalSchema_duplicateWithVersion(t *testing.T) { } addr := tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", } @@ -273,7 +273,7 @@ func TestStateStore_AddLocalSchema_versionFirst(t *testing.T) { } addr := tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", } @@ -346,7 +346,7 @@ func TestStateStore_ProviderSchema_localHasPriority(t *testing.T) { schemas := []*ProviderSchema{ { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "blah", }, @@ -360,7 +360,7 @@ func TestStateStore_ProviderSchema_localHasPriority(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", }, @@ -374,7 +374,7 @@ func TestStateStore_ProviderSchema_localHasPriority(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", }, @@ -390,7 +390,7 @@ func TestStateStore_ProviderSchema_localHasPriority(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", }, @@ -404,7 +404,7 @@ func TestStateStore_ProviderSchema_localHasPriority(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", }, @@ -423,7 +423,7 @@ func TestStateStore_ProviderSchema_localHasPriority(t *testing.T) { } ps, err := s.ProviderSchemas.ProviderSchema(modPath, - tfaddr.MustParseRawProviderSourceString("hashicorp/aws"), + tfaddr.NewProvider(tfaddr.DefaultProviderRegistryHost, "hashicorp", "aws"), testConstraint(t, "1.0.0"), ) if err != nil { @@ -454,7 +454,7 @@ func TestStateStore_ProviderSchema_legacyAddress_exactMatch(t *testing.T) { schemas := []*ProviderSchema{ { - tfaddr.NewLegacyProvider("aws"), + NewLegacyProvider("aws"), testVersion(t, "2.0.0"), LocalSchemaSource{ModulePath: modPath}, &tfschema.ProviderSchema{ @@ -464,7 +464,7 @@ func TestStateStore_ProviderSchema_legacyAddress_exactMatch(t *testing.T) { }, }, { - tfaddr.NewDefaultProvider("aws"), + NewDefaultProvider("aws"), testVersion(t, "2.5.0"), PreloadedSchemaSource{}, &tfschema.ProviderSchema{ @@ -480,7 +480,7 @@ func TestStateStore_ProviderSchema_legacyAddress_exactMatch(t *testing.T) { } ps, err := s.ProviderSchemas.ProviderSchema(modPath, - tfaddr.NewLegacyProvider("aws"), + NewLegacyProvider("aws"), testConstraint(t, "2.0.0"), ) if err != nil { @@ -522,7 +522,7 @@ func TestStateStore_ProviderSchema_legacyAddress_looseMatch(t *testing.T) { schemas := []*ProviderSchema{ { - tfaddr.NewDefaultProvider("aws"), + NewDefaultProvider("aws"), testVersion(t, "2.5.0"), PreloadedSchemaSource{}, &tfschema.ProviderSchema{ @@ -532,7 +532,7 @@ func TestStateStore_ProviderSchema_legacyAddress_looseMatch(t *testing.T) { }, }, { - tfaddr.NewProvider(tfaddr.DefaultRegistryHost, "grafana", "grafana"), + tfaddr.NewProvider(tfaddr.DefaultProviderRegistryHost, "grafana", "grafana"), testVersion(t, "1.0.0"), PreloadedSchemaSource{}, &tfschema.ProviderSchema{ @@ -548,7 +548,7 @@ func TestStateStore_ProviderSchema_legacyAddress_looseMatch(t *testing.T) { } ps, err := s.ProviderSchemas.ProviderSchema(modPath, - tfaddr.NewLegacyProvider("grafana"), + NewLegacyProvider("grafana"), testConstraint(t, "1.0.0"), ) if err != nil { @@ -579,7 +579,7 @@ func TestStateStore_ProviderSchema_terraformProvider(t *testing.T) { schemas := []*ProviderSchema{ { - tfaddr.NewBuiltInProvider("terraform"), + NewBuiltInProvider("terraform"), testVersion(t, "1.0.0"), PreloadedSchemaSource{}, &tfschema.ProviderSchema{ @@ -595,7 +595,7 @@ func TestStateStore_ProviderSchema_terraformProvider(t *testing.T) { } ps, err := s.ProviderSchemas.ProviderSchema(modPath, - tfaddr.NewLegacyProvider("terraform"), + NewLegacyProvider("terraform"), testConstraint(t, "1.0.0"), ) if err != nil { @@ -612,7 +612,7 @@ func TestStateStore_ProviderSchema_terraformProvider(t *testing.T) { } ps, err = s.ProviderSchemas.ProviderSchema(modPath, - tfaddr.NewDefaultProvider("terraform"), + NewDefaultProvider("terraform"), testConstraint(t, "1.0.0"), ) if err != nil { @@ -654,7 +654,7 @@ func TestStateStore_ListSchemas(t *testing.T) { localSchemas := []*ProviderSchema{ { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "blah", }, @@ -668,7 +668,7 @@ func TestStateStore_ListSchemas(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws-local", }, @@ -682,7 +682,7 @@ func TestStateStore_ListSchemas(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws-local", }, @@ -696,7 +696,7 @@ func TestStateStore_ListSchemas(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws-local", }, @@ -723,7 +723,7 @@ func TestStateStore_ListSchemas(t *testing.T) { expectedSchemas := []*ProviderSchema{ { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws-local", }, @@ -746,7 +746,7 @@ func TestStateStore_ListSchemas(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws-local", }, @@ -769,7 +769,7 @@ func TestStateStore_ListSchemas(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws-local", }, @@ -792,7 +792,7 @@ func TestStateStore_ListSchemas(t *testing.T) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "blah", }, @@ -829,7 +829,7 @@ func BenchmarkProviderSchema(b *testing.B) { schemas := []*ProviderSchema{ { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "blah", }, @@ -843,7 +843,7 @@ func BenchmarkProviderSchema(b *testing.B) { }, { tfaddr.Provider{ - Hostname: tfaddr.DefaultRegistryHost, + Hostname: tfaddr.DefaultProviderRegistryHost, Namespace: "hashicorp", Type: "aws", }, @@ -866,7 +866,7 @@ func BenchmarkProviderSchema(b *testing.B) { }, } for n := 0; n < b.N; n++ { - foundPs, err := s.ProviderSchemas.ProviderSchema("/test", tfaddr.NewDefaultProvider("aws"), testConstraint(b, "0.9.0")) + foundPs, err := s.ProviderSchemas.ProviderSchema("/test", NewDefaultProvider("aws"), testConstraint(b, "0.9.0")) if err != nil { b.Fatal(err) } diff --git a/internal/state/registry_modules.go b/internal/state/registry_modules.go index 10eda578f..f67d5e1b5 100644 --- a/internal/state/registry_modules.go +++ b/internal/state/registry_modules.go @@ -9,13 +9,13 @@ import ( ) type RegistryModuleData struct { - Source tfaddr.ModuleSourceRegistry + Source tfaddr.Module Version *version.Version Inputs []registry.Input Outputs []registry.Output } -func (s *RegistryModuleStore) Exists(sourceAddr tfaddr.ModuleSourceRegistry, constraint version.Constraints) (bool, error) { +func (s *RegistryModuleStore) Exists(sourceAddr tfaddr.Module, constraint version.Constraints) (bool, error) { txn := s.db.Txn(false) iter, err := txn.Get(s.tableName, "source_addr", sourceAddr) @@ -33,7 +33,7 @@ func (s *RegistryModuleStore) Exists(sourceAddr tfaddr.ModuleSourceRegistry, con return false, nil } -func (s *RegistryModuleStore) Cache(sourceAddr tfaddr.ModuleSourceRegistry, modVer *version.Version, +func (s *RegistryModuleStore) Cache(sourceAddr tfaddr.Module, modVer *version.Version, inputs []registry.Input, outputs []registry.Output) error { txn := s.db.Txn(true) diff --git a/internal/state/registry_modules_test.go b/internal/state/registry_modules_test.go index 52ae6a6ef..4d862d918 100644 --- a/internal/state/registry_modules_test.go +++ b/internal/state/registry_modules_test.go @@ -18,7 +18,7 @@ func TestStateStore_cache_metadata(t *testing.T) { t.Fatal(err) } - source, err := tfaddr.ParseRawModuleSourceRegistry("terraform-aws-modules/eks/aws") + source, err := tfaddr.ParseModuleSource("terraform-aws-modules/eks/aws") if err != nil { t.Fatal(err) } @@ -72,7 +72,7 @@ func TestModule_DeclaredModuleMeta(t *testing.T) { t.Fatal(err) } - source, err := tfaddr.ParseRawModuleSourceRegistry("terraform-aws-modules/eks/aws") + source, err := tfaddr.ParseModuleSource("terraform-aws-modules/eks/aws") if err != nil { t.Fatal(err) } diff --git a/internal/state/state.go b/internal/state/state.go index 0d69ce2f2..0815f0972 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -238,7 +238,7 @@ type ModuleReader interface { type ModuleCallReader interface { ModuleCalls(modPath string) (tfmod.ModuleCalls, error) LocalModuleMeta(modPath string) (*tfmod.Meta, error) - RegistryModuleMeta(addr tfaddr.ModuleSourceRegistry, cons version.Constraints) (*registry.ModuleData, error) + RegistryModuleMeta(addr tfaddr.Module, cons version.Constraints) (*registry.ModuleData, error) } type ProviderSchemaStore struct { diff --git a/internal/telemetry/telemetry.go b/internal/telemetry/telemetry.go index cdaf4eac7..3d01d3a81 100644 --- a/internal/telemetry/telemetry.go +++ b/internal/telemetry/telemetry.go @@ -37,10 +37,10 @@ func (t *Telemetry) SendEvent(ctx context.Context, name string, properties map[s } func IsPublicProvider(addr tfaddr.Provider) bool { - if addr.Hostname == tfaddr.DefaultRegistryHost { + if addr.Hostname == tfaddr.DefaultProviderRegistryHost { return true } - if addr.IsDefault() || addr.IsLegacy() || addr.IsBuiltIn() { + if addr.IsLegacy() || addr.IsBuiltIn() { return true } return false diff --git a/internal/terraform/datadir/module_types.go b/internal/terraform/datadir/module_types.go index 7693741c6..1511d6d8b 100644 --- a/internal/terraform/datadir/module_types.go +++ b/internal/terraform/datadir/module_types.go @@ -29,8 +29,8 @@ var moduleSourceLocalPrefixes = []string{ func (r *ModuleRecord) GetModuleType() ModuleType { // Example: terraform-aws-modules/ec2-instance/aws // Example: registry.terraform.io/terraform-aws-modules/vpc/aws - moduleSourceRegistry, err := tfaddr.ParseRawModuleSourceRegistry(r.SourceAddr) - if err == nil && moduleSourceRegistry.PackageAddr.Host == "registry.terraform.io" { + moduleSourceRegistry, err := tfaddr.ParseModuleSource(r.SourceAddr) + if err == nil && moduleSourceRegistry.Package.Host == "registry.terraform.io" { return TFREGISTRY } diff --git a/internal/terraform/module/module_ops.go b/internal/terraform/module/module_ops.go index 42754fd29..4920c5eab 100644 --- a/internal/terraform/module/module_ops.go +++ b/internal/terraform/module/module_ops.go @@ -92,7 +92,7 @@ func providerVersions(pv map[string]*version.Version) map[tfaddr.Provider]*versi m := make(map[tfaddr.Provider]*version.Version, 0) for rawAddr, v := range pv { - pAddr, err := tfaddr.ParseRawProviderSourceString(rawAddr) + pAddr, err := tfaddr.ParseProviderSource(rawAddr) if err != nil { // skip unparsable address continue @@ -133,7 +133,7 @@ func ObtainSchema(ctx context.Context, modStore *state.ModuleStore, schemaStore installedProviders := make(map[tfaddr.Provider]*version.Version, 0) for rawAddr, pJsonSchema := range ps.Schemas { - pAddr, err := tfaddr.ParseRawProviderSourceString(rawAddr) + pAddr, err := tfaddr.ParseProviderSource(rawAddr) if err != nil { // skip unparsable address continue @@ -365,7 +365,7 @@ func GetModuleDataFromRegistry(ctx context.Context, regClient registry.Client, m var errs *multierror.Error for _, declaredModule := range calls.Declared { - sourceAddr, ok := declaredModule.SourceAddr.(tfaddr.ModuleSourceRegistry) + sourceAddr, ok := declaredModule.SourceAddr.(tfaddr.Module) if !ok { // skip any modules which do not come from the Registry continue diff --git a/internal/terraform/module/module_ops_test.go b/internal/terraform/module/module_ops_test.go index 3079d66aa..4867a38d6 100644 --- a/internal/terraform/module/module_ops_test.go +++ b/internal/terraform/module/module_ops_test.go @@ -70,7 +70,7 @@ func TestGetModuleDataFromRegistry_singleModule(t *testing.T) { t.Fatal(err) } - addr, err := tfaddr.ParseRawModuleSourceRegistry("puppetlabs/deployment/ec") + addr, err := tfaddr.ParseModuleSource("puppetlabs/deployment/ec") if err != nil { t.Fatal(err) } @@ -149,7 +149,7 @@ func TestGetModuleDataFromRegistry_moduleNotFound(t *testing.T) { // Verify that 2nd module is still cached even if // obtaining data for the other one errored out - addr, err := tfaddr.ParseRawModuleSourceRegistry("puppetlabs/deployment/ec") + addr, err := tfaddr.ParseModuleSource("puppetlabs/deployment/ec") if err != nil { t.Fatal(err) } @@ -230,7 +230,7 @@ func TestGetModuleDataFromRegistry_apiTimeout(t *testing.T) { // Verify that 2nd module is still cached even if // obtaining data for the other one timed out - addr, err := tfaddr.ParseRawModuleSourceRegistry("puppetlabs/deployment/ec") + addr, err := tfaddr.ParseModuleSource("puppetlabs/deployment/ec") if err != nil { t.Fatal(err) } From 5f25cce5a4f3b31a2c04135e5022929ad2698df9 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 27 Jun 2022 18:38:53 +0100 Subject: [PATCH 2/2] bump tfschema to latest rev on main --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 0c5363909..3c42f1893 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/hashicorp/terraform-exec v0.17.0 github.com/hashicorp/terraform-json v0.14.0 github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c - github.com/hashicorp/terraform-schema v0.0.0-20220623144511-7930e05d32f8 + github.com/hashicorp/terraform-schema v0.0.0-20220627173216-dbeca9813054 github.com/kylelemons/godebug v1.1.0 // indirect github.com/mh-cbon/go-fmt-fail v0.0.0-20160815164508-67765b3fbcb5 github.com/mitchellh/cli v1.1.4 diff --git a/go.sum b/go.sum index 85f63f4c2..04f3a1f53 100644 --- a/go.sum +++ b/go.sum @@ -344,8 +344,8 @@ github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg= github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI= -github.com/hashicorp/terraform-schema v0.0.0-20220623144511-7930e05d32f8 h1:Smd1F42NuW2MCrS9MaolywhWnCPBosYa/JSniOusDiw= -github.com/hashicorp/terraform-schema v0.0.0-20220623144511-7930e05d32f8/go.mod h1:d1/gzOC/dLDNRI0lmhRPEtZoQl/9eaRjDGSb/GnliPo= +github.com/hashicorp/terraform-schema v0.0.0-20220627173216-dbeca9813054 h1:r+44Mn0GM19W6tIh9MRNoju0saM+QzksrHf9owbfrtI= +github.com/hashicorp/terraform-schema v0.0.0-20220627173216-dbeca9813054/go.mod h1:d1/gzOC/dLDNRI0lmhRPEtZoQl/9eaRjDGSb/GnliPo= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=