Skip to content

Commit c20dce5

Browse files
fix: Clean up ReadTerraformRegistryModule.
* rename the function * remove unnecessary comment * remove unnecessary call to fetch org in test * update new method comment
1 parent a82d7c5 commit c20dce5

File tree

4 files changed

+34
-41
lines changed

4 files changed

+34
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## Enhancements
44

5-
* Add support for proxied Terraform Registry endpoints for reading detailed module information by @paladin-devops [#1057](https://github.com/hashicorp/go-tfe/pull/1057)
65
* Adds `DefaultProject` to `OrganizationUpdateOptions` to support updating an organization's default project. This provides BETA support, which is EXPERIMENTAL, SUBJECT TO CHANGE, and may not be available to all users, by @mkam [#1056](https://github.com/hashicorp/go-tfe/pull/1056)
6+
* Adds `ReadTerraformRegistryModule` to support reading a registry module from Terraform Registry's proxied endpoints by @paladin-devops [#1057](https://github.com/hashicorp/go-tfe/pull/1057)
77

88
## Bug fixes
99

mocks/registry_module_mocks.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

registry_module.go

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ type RegistryModules interface {
4545
// ReadVersion Read a registry module version
4646
ReadVersion(ctx context.Context, moduleID RegistryModuleID, version string) (*RegistryModuleVersion, error)
4747

48-
// ReadRegistry Reads a registry module from the Terraform Registry.
48+
// ReadTerraformRegistryModule Reads a registry module from the Terraform
49+
// Registry, as opposed to Read or ReadVersion which read from the private
50+
// registry of a Terraform organization.
4951
// https://developer.hashicorp.com/terraform/enterprise/api-docs/private-registry/modules#hcp-terraform-registry-implementation
50-
ReadRegistry(ctx context.Context, moduleID RegistryModuleID, version string) (*TerraformRegistryModule, error)
52+
ReadTerraformRegistryModule(ctx context.Context, moduleID RegistryModuleID, version string) (*TerraformRegistryModule, error)
5153

5254
// Delete a registry module
5355
// Warning: This method is deprecated and will be removed from a future version of go-tfe. Use DeleteByName instead.
@@ -76,35 +78,31 @@ type RegistryModules interface {
7678

7779
// TerraformRegistryModule contains data about a module from the Terraform Registry.
7880
type TerraformRegistryModule struct {
79-
ID string `json:"id"`
80-
Owner string `json:"owner"`
81-
Namespace string `json:"namespace"`
82-
Name string `json:"name"`
83-
Version string `json:"version"`
84-
Provider string `json:"provider"`
85-
ProviderLogoURL string `json:"provider_logo_url"`
86-
Description string `json:"description"`
87-
Source string `json:"source"`
88-
Tag string `json:"tag"`
89-
PublishedAt string `json:"published_at"`
90-
Downloads int `json:"downloads"`
91-
Verified bool `json:"verified"`
92-
Root Root `json:"root"`
93-
// Submodules []Submodule `json:"submodules"`
94-
// Examples []Example `json:"examples"`
95-
Providers []string `json:"providers"`
96-
Versions []string `json:"versions"`
97-
// Deprecation *Deprecation `json:"deprecation"`
81+
ID string `json:"id"`
82+
Owner string `json:"owner"`
83+
Namespace string `json:"namespace"`
84+
Name string `json:"name"`
85+
Version string `json:"version"`
86+
Provider string `json:"provider"`
87+
ProviderLogoURL string `json:"provider_logo_url"`
88+
Description string `json:"description"`
89+
Source string `json:"source"`
90+
Tag string `json:"tag"`
91+
PublishedAt string `json:"published_at"`
92+
Downloads int `json:"downloads"`
93+
Verified bool `json:"verified"`
94+
Root Root `json:"root"`
95+
Providers []string `json:"providers"`
96+
Versions []string `json:"versions"`
9897
}
9998

10099
type Root struct {
101-
Path string `json:"path"`
102-
Name string `json:"name"`
103-
Readme string `json:"readme"`
104-
Empty bool `json:"empty"`
105-
Inputs []Input `json:"inputs"`
106-
Outputs []Output `json:"outputs"`
107-
// Dependencies []Dependency `json:"dependencies"`
100+
Path string `json:"path"`
101+
Name string `json:"name"`
102+
Readme string `json:"readme"`
103+
Empty bool `json:"empty"`
104+
Inputs []Input `json:"inputs"`
105+
Outputs []Output `json:"outputs"`
108106
ProviderDependencies []ProviderDependency `json:"provider_dependencies"`
109107
Resources []Resource `json:"resources"`
110108
}
@@ -638,7 +636,7 @@ func (r *registryModules) Read(ctx context.Context, moduleID RegistryModuleID) (
638636
}
639637

640638
// ReadRegistry fetches a registry module from the Terraform Registry.
641-
func (r *registryModules) ReadRegistry(ctx context.Context, moduleID RegistryModuleID, version string) (*TerraformRegistryModule, error) {
639+
func (r *registryModules) ReadTerraformRegistryModule(ctx context.Context, moduleID RegistryModuleID, version string) (*TerraformRegistryModule, error) {
642640
u := fmt.Sprintf(
643641
"https://app.terraform.io/api/registry/v1/modules/%s/%s/%s/%s",
644642
moduleID.Namespace,

registry_module_integration_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,25 +1329,20 @@ func TestRegistryModulesReadRegistry(t *testing.T) {
13291329
ctx := context.Background()
13301330
r := require.New(t)
13311331

1332-
// create an org that will be deleted later. the wskp will live here
13331332
orgTest, orgTestCleanup := createOrganization(t, client)
13341333
defer orgTestCleanup()
13351334

1336-
org, err := client.Organizations.Read(ctx, orgTest.Name)
1337-
r.NoError(err)
1338-
r.NotNil(org)
1339-
13401335
githubIdentifier := os.Getenv("GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER")
13411336
if githubIdentifier == "" {
13421337
t.Skip("Export a valid GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER before running this test")
13431338
}
13441339

1345-
token, cleanupToken := createOAuthToken(t, client, org)
1340+
token, cleanupToken := createOAuthToken(t, client, orgTest)
13461341
defer cleanupToken()
13471342

13481343
rmOpts := RegistryModuleCreateWithVCSConnectionOptions{
13491344
VCSRepo: &RegistryModuleVCSRepoOptions{
1350-
OrganizationName: String(org.Name),
1345+
OrganizationName: String(orgTest.Name),
13511346
Identifier: String(githubIdentifier),
13521347
Tags: Bool(true),
13531348
OAuthTokenID: String(token.ID),
@@ -1370,7 +1365,7 @@ func TestRegistryModulesReadRegistry(t *testing.T) {
13701365
Namespace: rm.Namespace,
13711366
RegistryName: rm.RegistryName,
13721367
}
1373-
tfm, err := client.RegistryModules.ReadRegistry(ctx, rmID, version)
1368+
tfm, err := client.RegistryModules.ReadTerraformRegistryModule(ctx, rmID, version)
13741369
r.NoError(err)
13751370
r.NotNil(tfm)
13761371
r.Equal(fmt.Sprintf("%s/%s/%s/%s", orgTest.Name, rm.Name, rm.Provider, version), tfm.ID)

0 commit comments

Comments
 (0)