Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inclusion of no-code module when listing modules #1003

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading