Skip to content

Commit

Permalink
add refresh and replace attributes for runs (#218)
Browse files Browse the repository at this point in the history
* Add is-refresh to Runs

* change name to refresh

* add refresh-only to runs

* add replace-addrs to runs

* clarify test wording

* clarify all the wording

* skip refresh-only test for now

Co-authored-by: Omar Ismail <[email protected]>
  • Loading branch information
radditude and omarismail authored May 18, 2021
1 parent a47b063 commit 7104d5b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
16 changes: 16 additions & 0 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ type Run struct {
Message string `jsonapi:"attr,message"`
Permissions *RunPermissions `jsonapi:"attr,permissions"`
PositionInQueue int `jsonapi:"attr,position-in-queue"`
Refresh bool `jsonapi:"attr,refresh"`
RefreshOnly bool `jsonapi:"attr,refresh-only"`
ReplaceAddrs []string `jsonapi:"attr,replace-addrs,omitempty"`
Source RunSource `jsonapi:"attr,source"`
Status RunStatus `jsonapi:"attr,status"`
StatusTimestamps *RunStatusTimestamps `jsonapi:"attr,status-timestamps"`
Expand Down Expand Up @@ -186,6 +189,14 @@ type RunCreateOptions struct {
// provisioned resources.
IsDestroy *bool `jsonapi:"attr,is-destroy,omitempty"`

// Refresh determines if the run should
// update the state prior to checking for differences
Refresh *bool `jsonapi:"attr,refresh,omitempty"`

// RefreshOnly determines whether the run should ignore config changes
// and refresh the state only
RefreshOnly *bool `jsonapi:"attr,refresh-only,omitempty"`

// Specifies the message to be associated with this run.
Message *string `jsonapi:"attr,message,omitempty"`

Expand All @@ -209,6 +220,11 @@ type RunCreateOptions struct {
// of routine workflow and Terraform will emit warnings reminding about
// this whenever this property is set.
TargetAddrs []string `jsonapi:"attr,target-addrs,omitempty"`

// If non-empty, requests that Terraform create a plan that replaces
// (destroys and then re-creates) the objects specified by the given
// resource addresses.
ReplaceAddrs []string `jsonapi:"attr,replace-addrs,omitempty"`
}

func (o RunCreateOptions) valid() error {
Expand Down
34 changes: 31 additions & 3 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ func TestRunsCreate(t *testing.T) {
assert.Equal(t, cvTest.ID, r.ConfigurationVersion.ID)
})

t.Run("refresh defaults to true if not set as a create option", func(t *testing.T) {
options := RunCreateOptions{
Workspace: wTest,
}

r, err := client.Runs.Create(ctx, options)
require.NoError(t, err)
assert.Equal(t, true, r.Refresh)
})

t.Run("with refresh-only requested", func(t *testing.T) {
// TODO: remove this skip after the release of Terraform 0.15.4
t.Skip("Skipping this test until -refresh-only is released in the Terraform CLI")

options := RunCreateOptions{
Workspace: wTest,
RefreshOnly: Bool(true),
}

r, err := client.Runs.Create(ctx, options)
require.NoError(t, err)
assert.Equal(t, true, r.RefreshOnly)
})

t.Run("without a workspace", func(t *testing.T) {
r, err := client.Runs.Create(ctx, RunCreateOptions{})
assert.Nil(t, r)
Expand All @@ -120,14 +144,18 @@ func TestRunsCreate(t *testing.T) {

t.Run("with additional attributes", func(t *testing.T) {
options := RunCreateOptions{
Message: String("yo"),
Workspace: wTest,
TargetAddrs: []string{"null_resource.example"},
Message: String("yo"),
Workspace: wTest,
Refresh: Bool(false),
ReplaceAddrs: []string{"null_resource.example"},
TargetAddrs: []string{"null_resource.example"},
}

r, err := client.Runs.Create(ctx, options)
require.NoError(t, err)
assert.Equal(t, *options.Message, r.Message)
assert.Equal(t, *options.Refresh, r.Refresh)
assert.Equal(t, options.ReplaceAddrs, r.ReplaceAddrs)
assert.Equal(t, options.TargetAddrs, r.TargetAddrs)
})
}
Expand Down

0 comments on commit 7104d5b

Please sign in to comment.