From 7002b96fac31cacd0c5b8b451af95b619521f1c7 Mon Sep 17 00:00:00 2001 From: paladin-devops <83741749+paladin-devops@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:28:11 -0500 Subject: [PATCH] feat: Add inclusion of no-code module w/mod list. --- docs/TESTS.md | 2 +- registry_module.go | 13 +++++++++++-- registry_module_integration_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/docs/TESTS.md b/docs/TESTS.md index 282378113..d2830da45 100644 --- a/docs/TESTS.md +++ b/docs/TESTS.md @@ -111,4 +111,4 @@ $ TFE_TOKEN=xyz TFE_HOSTNAME=tfe.local ENABLE_TFE=1 go test ./... -timeout=30m ### Running tests for HCP Terraform features that require paid plans (HashiCorp Employees) -You can use the test helper `upgradeOrganizationSubscription()` to upgrade your test organization to a Business Plan, giving the organization access to all features in HCP Terraform. This method requires `TFE_TOKEN` to be a user token with administrator access in the target test environment. Furthermore, you **can not** have enterprise features enabled (`ENABLE_TFE=1`) in order to use this method since the API call fails against Terraform Enterprise test environments. +You can use the test helper `newSubscriptionUpdater()` to upgrade your test organization to a Business Plan, giving the organization access to all features in HCP Terraform. This method requires `TFE_TOKEN` to be a user token with administrator access in the target test environment. Furthermore, you **can not** have enterprise features enabled (`ENABLE_TFE=1`) in order to use this method since the API call fails against Terraform Enterprise test environments. diff --git a/registry_module.go b/registry_module.go index 67bf1fa12..394c75ed9 100644 --- a/registry_module.go +++ b/registry_module.go @@ -22,7 +22,7 @@ var _ RegistryModules = (*registryModules)(nil) // // TFE API docs: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/private-registry/modules type RegistryModules interface { - // List all the registory modules within an organization + // List all the registry modules within an organization List(ctx context.Context, organization string, options *RegistryModuleListOptions) (*RegistryModuleList, error) // ListCommits List the commits for the registry module @@ -157,6 +157,8 @@ type RegistryModule struct { // Relations Organization *Organization `jsonapi:"relation,organization"` + + RegistryNoCodeModule []*RegistryNoCodeModule `jsonapi:"relation,no-code-modules"` } // Commit represents a commit @@ -202,8 +204,15 @@ type RegistryModuleVersionStatuses struct { // RegistryModuleListOptions represents the options for listing registry modules. type RegistryModuleListOptions struct { ListOptions + + // Include is a list of relations to include. + Include []RegistryModuleListIncludeOpt `url:"include,omitempty"` } +type RegistryModuleListIncludeOpt string + +const IncludeNoCodeModules RegistryModuleListIncludeOpt = "no-code-modules" + // RegistryModuleCreateOptions is used when creating a registry module without a VCS repo type RegistryModuleCreateOptions struct { // Type is a public field utilized by JSON:API to @@ -311,7 +320,7 @@ type RegistryModuleVCSRepoUpdateOptions struct { Tags *bool `json:"tags,omitempty"` } -// List all the registory modules within an organization. +// List all the registry modules within an organization. func (r *registryModules) List(ctx context.Context, organization string, options *RegistryModuleListOptions) (*RegistryModuleList, error) { if !validStringID(&organization) { return nil, ErrInvalidOrg diff --git a/registry_module_integration_test.go b/registry_module_integration_test.go index c33222e01..6cb440343 100644 --- a/registry_module_integration_test.go +++ b/registry_module_integration_test.go @@ -62,6 +62,31 @@ func TestRegistryModulesList(t *testing.T) { assert.NotEmpty(t, modl.Items) assert.Equal(t, 1, modl.CurrentPage) }) + + t.Run("include no-code modules", func(t *testing.T) { + registryModuleTest3, registryModuleTest3Cleanup := createRegistryModule(t, client, orgTest, PrivateRegistry) + defer registryModuleTest3Cleanup() + + newSubscriptionUpdater(orgTest).WithPlusEntitlementPlan().Update(t) + _, noCodeModuleCleanup := createNoCodeRegistryModule(t, client, orgTest.Name, registryModuleTest3, nil) + defer noCodeModuleCleanup() + + modl, err := client.RegistryModules.List(ctx, orgTest.Name, &RegistryModuleListOptions{ + Include: []RegistryModuleListIncludeOpt{ + IncludeNoCodeModules, + }, + }) + require.NoError(t, err) + assert.Len(t, modl.Items, 3) + // only module 3 is no-code, so iterate through the results before + // the test assertion + for _, m := range modl.Items { + if m.ID == registryModuleTest2.ID { + assert.True(t, modl.Items[2].NoCode) + assert.Len(t, modl.Items[2].RegistryNoCodeModule, 1) + } + } + }) } func TestRegistryModulesCreate(t *testing.T) {