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

Optionally send json outputs when creating state versions #452

Merged
merged 7 commits into from Jul 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -3,8 +3,8 @@
## Enhancements
* Adds `RetryServerErrors` field to the `Config` object by @sebasslash [#439](https://github.com/hashicorp/go-tfe/pull/439)
* Adds support for the GPG Keys API by @sebasslash [#429](https://github.com/hashicorp/go-tfe/pull/429)
* [beta] Renames the optional StateVersion field `ExtState` to `JSONState` and changes to string for base64 encoding by @annawinkler [#444](https://github.com/hashicorp/go-tfe/pull/444)
* Add support for new `WorkspaceLimit` Admin setting for organizations [#425](https://github.com/hashicorp/go-tfe/pull/425)
* [beta] Renames the optional StateVersion field `ExtState` to `JSONStateOutputs` and changes the purpose and type by @annawinkler [#444](https://github.com/hashicorp/go-tfe/pull/444) and @brandoncroft [#452](https://github.com/hashicorp/go-tfe/pull/452)

# v1.3.0

Expand Down
31 changes: 18 additions & 13 deletions configuration_version_integration_test.go
Expand Up @@ -7,10 +7,12 @@ import (
"bytes"
"context"
"encoding/json"
"github.com/hashicorp/go-slug"
"errors"
"testing"
"time"

"github.com/hashicorp/go-slug"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -155,22 +157,25 @@ func TestConfigurationVersionsReadWithOptions(t *testing.T) {
wTest, wTestCleanup := createWorkspaceWithVCS(t, client, orgTest, WorkspaceCreateOptions{QueueAllRuns: Bool(true)})
defer wTestCleanup()

// Hack: Wait for TFC to ingress the configuration and queue a run
time.Sleep(3 * time.Second)
w, err := retry(func() (interface{}, error) {
w, err := client.Workspaces.ReadByIDWithOptions(ctx, wTest.ID, &WorkspaceReadOptions{
Include: []WSIncludeOpt{WSCurrentRunConfigVer},
})

w, err := client.Workspaces.ReadByIDWithOptions(ctx, wTest.ID, &WorkspaceReadOptions{
Include: []WSIncludeOpt{WSCurrentRunConfigVer},
})
if err != nil {
return nil, err
}

if err != nil {
require.NoError(t, err)
}
if w.CurrentRun == nil {
return nil, errors.New("A run was expected to be found on this workspace as a test pre-condition")
}

if w.CurrentRun == nil {
t.Fatal("A run was expected to be found on this workspace as a test pre-condition")
}
return w, nil
})

require.NoError(t, err)

cv := w.CurrentRun.ConfigurationVersion
cv := w.(*Workspace).CurrentRun.ConfigurationVersion

t.Run("when the configuration version exists", func(t *testing.T) {
options := &ConfigurationVersionReadOptions{
Expand Down
11 changes: 9 additions & 2 deletions oauth_client_integration_test.go
Expand Up @@ -5,6 +5,7 @@ package tfe

import (
"context"
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -247,8 +248,14 @@ func TestOAuthClientsDelete(t *testing.T) {
err := client.OAuthClients.Delete(ctx, ocTest.ID)
require.NoError(t, err)

// Try loading the OAuth client - it should fail.
_, err = client.OAuthClients.Read(ctx, ocTest.ID)
_, err = retry(func() (interface{}, error) {
c, err := client.OAuthClients.Read(ctx, ocTest.ID)
if err != ErrResourceNotFound {
return nil, fmt.Errorf("expected %s, but err was %s", ErrResourceNotFound, err)
}
return c, err
})

assert.Equal(t, err, ErrResourceNotFound)
})

Expand Down
8 changes: 4 additions & 4 deletions state_version.go
Expand Up @@ -139,13 +139,13 @@ type StateVersionCreateOptions struct {
// Optional: Specifies the run to associate the state with.
Run *Run `jsonapi:"relation,run,omitempty"`

// Optional: The external, json representation of state data, base64 encoded.
// https://www.terraform.io/internals/json-format#state-representation
// Supplying this state representation can provide more details to the platform
// Optional: The external, json representation of state outputs, base64 encoded. Supplying this field
// will provide more detailed output type information to TFE.
// For more information on the contents of this field: https://www.terraform.io/internals/json-format#values-representation
// about the current terraform state.
//
// **Note**: This field is in BETA, subject to change and not widely available yet.
JSONState *string `jsonapi:"attr,json-state,omitempty"`
JSONStateOutputs *string `jsonapi:"attr,json-state-outputs,omitempty"`
}

// List all the state versions for a given workspace.
Expand Down
14 changes: 8 additions & 6 deletions state_version_integration_test.go
Expand Up @@ -121,7 +121,7 @@ func TestStateVersionsCreate(t *testing.T) {
t.Fatal(err)
}

jsonState, err := ioutil.ReadFile("test-fixtures/ext-state-version/state.json")
jsonStateOutputs, err := ioutil.ReadFile("test-fixtures/json-state-outputs/everything.json")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -169,11 +169,11 @@ func TestStateVersionsCreate(t *testing.T) {
}

sv, err := client.StateVersions.Create(ctx, wTest.ID, StateVersionCreateOptions{
Lineage: String("741c4949-60b9-5bb1-5bf8-b14f4bb14af3"),
MD5: String(fmt.Sprintf("%x", md5.Sum(state))),
Serial: Int64(1),
State: String(base64.StdEncoding.EncodeToString(state)),
JSONState: String(base64.StdEncoding.EncodeToString(jsonState)),
Lineage: String("741c4949-60b9-5bb1-5bf8-b14f4bb14af3"),
MD5: String(fmt.Sprintf("%x", md5.Sum(state))),
Serial: Int64(1),
State: String(base64.StdEncoding.EncodeToString(state)),
JSONStateOutputs: String(base64.StdEncoding.EncodeToString(jsonStateOutputs)),
})
require.NoError(t, err)

Expand All @@ -186,6 +186,8 @@ func TestStateVersionsCreate(t *testing.T) {
t.Fatal(err)
}

// TODO: check state outputs for the ones we sent in JSONStateOutputs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this TODO be resolved?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not until the API changes are merged.


for _, item := range []*StateVersion{
sv,
refreshed,
Expand Down
163 changes: 0 additions & 163 deletions test-fixtures/ext-state-version/state.json

This file was deleted.