Skip to content

Commit

Permalink
Merge pull request #1003 from hashicorp/list-registry-module-filter
Browse files Browse the repository at this point in the history
Add inclusion of no-code module when listing modules
  • Loading branch information
paladin-devops authored Nov 19, 2024
2 parents 30b05ea + dbaf3b2 commit c278019
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Enhancements

* Add support for listing effective tag bindings for a workspace or project by @brandonc
* Add support for listing no-code modules by @paladin-devops [#1003](https://github.com/hashicorp/go-tfe/pull/1003)

# v1.69.0

Expand Down
2 changes: 1 addition & 1 deletion docs/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
13 changes: 11 additions & 2 deletions registry_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -157,6 +157,8 @@ type RegistryModule struct {

// Relations
Organization *Organization `jsonapi:"relation,organization"`

RegistryNoCodeModule []*RegistryNoCodeModule `jsonapi:"relation,no-code-modules"`
}

// Commit represents a commit
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions registry_module_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
options := RegistryModuleCreateOptions{
Name: String("iam"),
Provider: String("aws"),
NoCode: Bool(true),
RegistryName: PrivateRegistry,
}
rm, err := client.RegistryModules.Create(ctx, orgTest.Name, options)
require.NoError(t, err)

modl, err := client.RegistryModules.List(ctx, orgTest.Name, &RegistryModuleListOptions{
Include: []RegistryModuleListIncludeOpt{
IncludeNoCodeModules,
},
})
require.NoError(t, err)
assert.Len(t, modl.Items, 3)
for _, m := range modl.Items {
if m.ID == rm.ID {
assert.True(t, m.NoCode)
assert.Len(t, m.RegistryNoCodeModule, 1)
}
}
})
}

func TestRegistryModulesCreate(t *testing.T) {
Expand Down

0 comments on commit c278019

Please sign in to comment.