Skip to content

Commit

Permalink
Merge branch 'main' into TF-9651-update-varsets-enforced-field-to-pri…
Browse files Browse the repository at this point in the history
…ority-field
  • Loading branch information
rberecka authored Oct 24, 2023
2 parents 3cc0097 + 9784638 commit 4f4bd53
Show file tree
Hide file tree
Showing 15 changed files with 822 additions and 20 deletions.
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
# UNRELEASED
<!-- Add CHANGELOG entry to this section for any PR awaiting the next release -->
<!-- Please also include if this is a Bug Fix, Enhancement, or Feature -->

# v.1.37.0

## Features
* Add the tags attribute to VCSRepo to be used with registry modules by @hashimoon [#793](https://github.com/hashicorp/go-tfe/pull/793)

# v.1.36.0

## Features
* Added BETA support for private module registry test variables by @aaabdelgany [#787](https://github.com/hashicorp/go-tfe/pull/787)

## Bug Fixes
* Fix incorrect attribute type for `RegistryModule.VCSRepo.Tags` by @hashimoon [#789](https://github.com/hashicorp/go-tfe/pull/789)
* Fix nil dereference panic within `StateVersions` `upload` after not handling certain state version create errors by @brandonc [#792](https://github.com/hashicorp/go-tfe/pull/792)

# v.1.35.0

## Features
* Added BETA support for private module registry tests by @hashimoon [#781](https://github.com/hashicorp/go-tfe/pull/781)

## Enhancements
* Added BETA support for including `priority` attribute to variable_set on create and update by @Netra2104 [#778](https://github.com/hashicorp/go-tfe/pull/778)
* Removed beta flags for `PolicySetProjects` and `PolicySetWorkspaceExclusions` by @Netra2104 [#770](https://github.com/hashicorp/go-tfe/pull/770)

# v1.34.0

## Features
* Added support for the new Terraform Test Runs API by @liamcervante [#755](https://github.com/hashicorp/go-tfe/pull/755)

Expand Down
6 changes: 3 additions & 3 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ var (

ErrRequiredAgentPoolID = errors.New("'agent' execution mode requires an agent pool ID to be specified")

ErrRequiredAgentMode = errors.New("specifying an agent pool ID requires 'agent' execution mode")

ErrRequiredCategory = errors.New("category is required")
ErrRequiredAgentMode = errors.New("specifying an agent pool ID requires 'agent' execution mode")
ErrRequiredBranchWhenTestsEnabled = errors.New("VCS branch is required when enabling tests")
ErrRequiredCategory = errors.New("category is required")

ErrRequiredDestinationType = errors.New("destination type is required")

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d
github.com/stretchr/testify v1.8.4
golang.org/x/sync v0.3.0
golang.org/x/sync v0.4.0
golang.org/x/time v0.3.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
47 changes: 47 additions & 0 deletions helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,44 @@ func createTestRun(t *testing.T, client *Client, rm *RegistryModule, variables .
}
}

func createTestVariable(t *testing.T, client *Client, rm *RegistryModule) (*Variable, func()) {
var rmCleanup func()

if rm == nil {
rm, rmCleanup = createBranchBasedRegistryModule(t, client, nil)
}
rmID := RegistryModuleID{
Organization: rm.Organization.Name,
Name: rm.Name,
Provider: rm.Provider,
Namespace: rm.Namespace,
RegistryName: rm.RegistryName,
}

ctx := context.Background()
v, err := client.TestVariables.Create(ctx, rmID, VariableCreateOptions{
Key: String(randomKeyValue(t)),
Value: String(randomStringWithoutSpecialChar(t)),
Category: Category(CategoryEnv),
Description: String(randomStringWithoutSpecialChar(t)),
})
if err != nil {
t.Fatal(err)
}

return v, func() {
if err := client.TestVariables.Delete(ctx, rmID, v.ID); err != nil {
t.Errorf("Error destroying variable! WARNING: Dangling resources\n"+
"may exist! The full error is shown below.\n\n"+
"Variable: %s\nError: %s", v.Key, err)
}

if rmCleanup != nil {
rmCleanup()
}
}
}

// helper to wait until a test run has reached a certain status
func waitUntilTestRunStatus(t *testing.T, client *Client, rm RegistryModuleID, tr *TestRun, desiredStatus TestRunStatus, timeoutSeconds int) {
ctx := context.Background()
Expand Down Expand Up @@ -2605,6 +2643,15 @@ func randomStringWithoutSpecialChar(t *testing.T) string {
return uuidWithoutHyphens
}

func randomKeyValue(t *testing.T) string {
v, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}
uuidWithoutHyphens := strings.ReplaceAll(v, "-", "")
return "t" + uuidWithoutHyphens
}

func containsProject(pl []*Project, str string) bool {
for _, p := range pl {
if p.Name == str {
Expand Down
1 change: 1 addition & 0 deletions organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Organization struct {
TrialExpiresAt time.Time `jsonapi:"attr,trial-expires-at,iso8601"`
TwoFactorConformant bool `jsonapi:"attr,two-factor-conformant"`
SendPassingStatusesForUntriggeredSpeculativePlans bool `jsonapi:"attr,send-passing-statuses-for-untriggered-speculative-plans"`
RemainingTestableCount int `jsonapi:"attr,remaining-testable-count"`
// Note: This will be false for TFE versions older than v202211, where the setting was introduced.
// On those TFE versions, safe delete does not exist, so ALL deletes will be force deletes.
AllowForceDeleteWorkspaces bool `jsonapi:"attr,allow-force-delete-workspaces"`
Expand Down
1 change: 1 addition & 0 deletions organization_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func TestOrganizationsRead(t *testing.T) {
assert.NotEmpty(t, org.CreatedAt)
// By default accounts are in the free tier and are not in a trial
assert.Empty(t, org.TrialExpiresAt)
assert.Equal(t, org.RemainingTestableCount, 5)
})
})

Expand Down
66 changes: 54 additions & 12 deletions registry_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ const (
RegistryModuleVersionStatusOk RegistryModuleVersionStatus = "ok"
)

type PublishingMechanism string

const (
PublishingMechanismBranch PublishingMechanism = "branch"
PublishingMechanismTag PublishingMechanism = "git_tag"
)

// RegistryModuleID represents the set of IDs that identify a RegistryModule
type RegistryModuleID struct {
// The organization the module belongs to, see RegistryModule.Organization.Name
Expand Down Expand Up @@ -124,18 +131,20 @@ type CommitList struct {

// RegistryModule represents a registry module
type RegistryModule struct {
ID string `jsonapi:"primary,registry-modules"`
Name string `jsonapi:"attr,name"`
Provider string `jsonapi:"attr,provider"`
RegistryName RegistryName `jsonapi:"attr,registry-name"`
Namespace string `jsonapi:"attr,namespace"`
NoCode bool `jsonapi:"attr,no-code"`
Permissions *RegistryModulePermissions `jsonapi:"attr,permissions"`
Status RegistryModuleStatus `jsonapi:"attr,status"`
VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"`
VersionStatuses []RegistryModuleVersionStatuses `jsonapi:"attr,version-statuses"`
CreatedAt string `jsonapi:"attr,created-at"`
UpdatedAt string `jsonapi:"attr,updated-at"`
ID string `jsonapi:"primary,registry-modules"`
Name string `jsonapi:"attr,name"`
Provider string `jsonapi:"attr,provider"`
RegistryName RegistryName `jsonapi:"attr,registry-name"`
Namespace string `jsonapi:"attr,namespace"`
NoCode bool `jsonapi:"attr,no-code"`
Permissions *RegistryModulePermissions `jsonapi:"attr,permissions"`
PublishingMechanism PublishingMechanism `jsonapi:"attr,publishing-mechanism"`
Status RegistryModuleStatus `jsonapi:"attr,status"`
TestConfig *TestConfig `jsonapi:"attr,test-config"`
VCSRepo *VCSRepo `jsonapi:"attr,vcs-repo"`
VersionStatuses []RegistryModuleVersionStatuses `jsonapi:"attr,version-statuses"`
CreatedAt string `jsonapi:"attr,created-at"`
UpdatedAt string `jsonapi:"attr,updated-at"`

// Relations
Organization *Organization `jsonapi:"relation,organization"`
Expand Down Expand Up @@ -239,6 +248,10 @@ type RegistryModuleCreateWithVCSConnectionOptions struct {
//
// **Note: This field is still in BETA and subject to change.**
InitialVersion *string `jsonapi:"attr,initial-version,omitempty"`

// Optional: Flag to enable tests for the module
// **Note: This field is still in BETA and subject to change.**
TestConfig *RegistryModuleTestConfigOptions `jsonapi:"attr,test-config,omitempty"`
}

// RegistryModuleCreateVersionOptions is used when updating a registry module
Expand All @@ -252,6 +265,16 @@ type RegistryModuleUpdateOptions struct {
// Optional: Flag to enable no-code provisioning for the whole module.
// **Note: This field is still in BETA and subject to change.**
NoCode *bool `jsonapi:"attr,no-code,omitempty"`

// Optional: Flag to enable tests for the module
// **Note: This field is still in BETA and subject to change.**
TestConfig *RegistryModuleTestConfigOptions `jsonapi:"attr,test-config,omitempty"`

VCSRepo *RegistryModuleVCSRepoUpdateOptions `jsonapi:"attr,vcs-repo,omitempty"`
}

type RegistryModuleTestConfigOptions struct {
TestsEnabled *bool `jsonapi:"attr,tests-enabled,omitempty"`
}

type RegistryModuleVCSRepoOptions struct {
Expand All @@ -268,6 +291,16 @@ type RegistryModuleVCSRepoOptions struct {
Branch *string `json:"branch,omitempty"`
}

type RegistryModuleVCSRepoUpdateOptions struct {
// The Branch and Tag fields are used to determine
// the PublishingMechanism for a RegistryModule that has a VCS a connection.
// When a value for Branch is provided, the Tags field is removed on the server
// When a value for Tags is provided, the Branch field is removed on the server
// **Note: This field is still in BETA and subject to change.**
Branch *string `json:"branch,omitempty"`
Tags *bool `json:"tags,omitempty"`
}

// List all the registory modules within an organization.
func (r *registryModules) List(ctx context.Context, organization string, options *RegistryModuleListOptions) (*RegistryModuleList, error) {
if !validStringID(&organization) {
Expand Down Expand Up @@ -696,6 +729,15 @@ func (o RegistryModuleCreateWithVCSConnectionOptions) valid() error {
if o.VCSRepo == nil {
return ErrRequiredVCSRepo
}

if o.TestConfig != nil && o.TestConfig.TestsEnabled != nil {
if *o.TestConfig.TestsEnabled {
if !validString(o.VCSRepo.Branch) {
return ErrRequiredBranchWhenTestsEnabled
}
}
}

return o.VCSRepo.valid()
}

Expand Down
Loading

0 comments on commit 4f4bd53

Please sign in to comment.