Skip to content

Commit

Permalink
Merge pull request #746 from hashicorp/TF-7651-go-tfe-add-provisional…
Browse files Browse the repository at this point in the history
…-attribute-for-configuration-versions

Add provisional for ConfigurationVersions; Add current-configuration-version to Workspaces
  • Loading branch information
brandonc authored Aug 4, 2023
2 parents 9a03826 + c456f6f commit 6f876e4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Added BETA method `AddProjects` and `RemoveProjects` for attaching/detaching policy set to projects by @Netra2104 [#735](https://github.com/hashicorp/go-tfe/pull/735)
* Added BETA support for adding and updating custom permissions to `TeamProjectAccesses`. A `TeamProjectAccessType` of `"custom"` can set various permissions applied at
the project level to the project itself (`TeamProjectAccessProjectPermissionsOptions`) and all of the workspaces in a project (`TeamProjectAccessWorkspacePermissionsOptions`) by @rberecka [#745](https://github.com/hashicorp/go-tfe/pull/745)
* Added BETA field `Provisional` to `ConfigurationVersions` by @brandonc [#746](https://github.com/hashicorp/go-tfe/pull/746)

# v1.30.0

Expand Down
5 changes: 5 additions & 0 deletions configuration_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type ConfigurationVersion struct {
ErrorMessage string `jsonapi:"attr,error-message"`
Source ConfigurationSource `jsonapi:"attr,source"`
Speculative bool `jsonapi:"attr,speculative"`
Provisional bool `jsonapi:"attr,provisional"`
Status ConfigurationStatus `jsonapi:"attr,status"`
StatusTimestamps *CVStatusTimestamps `jsonapi:"attr,status-timestamps"`
UploadURL string `jsonapi:"attr,upload-url"`
Expand Down Expand Up @@ -154,6 +155,10 @@ type ConfigurationVersionCreateOptions struct {

// Optional: When true, this configuration version can only be used for planning.
Speculative *bool `jsonapi:"attr,speculative,omitempty"`

// Optional: When true, does not become the workspace's current configuration until
// a run referencing it is ultimately applied.
Provisional *bool `jsonapi:"attr,provisional,omitempty"`
}

// IngressAttributes include commit information associated with configuration versions sourced from VCS.
Expand Down
27 changes: 27 additions & 0 deletions configuration_version_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,29 @@ func TestConfigurationVersionsCreate(t *testing.T) {
assert.Nil(t, cv)
assert.EqualError(t, err, ErrInvalidWorkspaceID.Error())
})

t.Run("provisional", func(t *testing.T) {
skipUnlessBeta(t)

cv, err := client.ConfigurationVersions.Create(ctx,
wTest.ID,
ConfigurationVersionCreateOptions{
Provisional: Bool(true),
},
)

require.NoError(t, err)
assert.True(t, cv.Provisional)

ws, err := client.Workspaces.ReadByID(ctx, wTest.ID)
require.NoError(t, err)

// Depends on "with valid options"
require.NotNil(t, ws.CurrentConfigurationVersion)

// Provisional configuration version is not the current one
assert.NotEqual(t, ws.CurrentConfigurationVersion.ID, cv.ID)
})
}

func TestConfigurationVersionsRead(t *testing.T) {
Expand Down Expand Up @@ -372,6 +395,8 @@ func TestConfigurationVersions_Unmarshal(t *testing.T) {
"finished-at": "2020-03-16T23:15:59+00:00",
"started-at": "2019-03-16T23:23:59+00:00",
},
"speculative": true,
"provisional": true,
},
},
}
Expand All @@ -396,4 +421,6 @@ func TestConfigurationVersions_Unmarshal(t *testing.T) {
assert.Equal(t, cv.Status, ConfigurationUploaded)
assert.Equal(t, cv.StatusTimestamps.FinishedAt, finishedParsedTime)
assert.Equal(t, cv.StatusTimestamps.StartedAt, startedParsedTime)
assert.Equal(t, cv.Provisional, true)
assert.Equal(t, cv.Speculative, true)
}
19 changes: 10 additions & 9 deletions workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,15 @@ type Workspace struct {
TagNames []string `jsonapi:"attr,tag-names"`

// Relations
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
CurrentRun *Run `jsonapi:"relation,current-run"`
CurrentStateVersion *StateVersion `jsonapi:"relation,current-state-version"`
Organization *Organization `jsonapi:"relation,organization"`
SSHKey *SSHKey `jsonapi:"relation,ssh-key"`
Outputs []*WorkspaceOutputs `jsonapi:"relation,outputs"`
Project *Project `jsonapi:"relation,project"`
Tags []*Tag `jsonapi:"relation,tags"`
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
CurrentRun *Run `jsonapi:"relation,current-run"`
CurrentStateVersion *StateVersion `jsonapi:"relation,current-state-version"`
Organization *Organization `jsonapi:"relation,organization"`
SSHKey *SSHKey `jsonapi:"relation,ssh-key"`
Outputs []*WorkspaceOutputs `jsonapi:"relation,outputs"`
Project *Project `jsonapi:"relation,project"`
Tags []*Tag `jsonapi:"relation,tags"`
CurrentConfigurationVersion *ConfigurationVersion `jsonapi:"relation,current-configuration-version,omitempty"`

// Links
Links map[string]interface{} `jsonapi:"links,omitempty"`
Expand Down Expand Up @@ -379,7 +380,7 @@ type WorkspaceCreateOptions struct {
Tags []*Tag `jsonapi:"relation,tags,omitempty"`

// Associated Project with the workspace. If not provided, default project
// of the organization will be assigned to the workspace
// of the organization will be assigned to the workspace.
Project *Project `jsonapi:"relation,project,omitempty"`
}

Expand Down

0 comments on commit 6f876e4

Please sign in to comment.