Skip to content

Commit

Permalink
feat: optionally send json outputs when creating state versions
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonc committed Jul 5, 2022
1 parent 52e03e5 commit 10c6e3f
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 173 deletions.
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.
// https://www.terraform.io/internals/json-format#values-representation (the contents of the
// "outputs" attribute) Supplying detailed outputs will provide more details to the platform
// 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

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.

113 changes: 113 additions & 0 deletions test-fixtures/json-state-outputs/everything.json
@@ -0,0 +1,113 @@
{
"a-decimal": {
"sensitive": false,
"value": 1000.1,
"type": "number"
},
"a-false-bool": {
"sensitive": false,
"value": false,
"type": "bool"
},
"a-list": {
"sensitive": false,
"value": [
"example",
"1001",
"1000.1"
],
"type": [
"list",
"string"
]
},
"a-long-string": {
"sensitive": false,
"value": "The private integer of the main server instance is where you want to go when you have the most fun in every Terraform instance you can see in the world that you live in except for dogs because they don't run servers in the same place that humans do.",
"type": "string"
},
"a-object": {
"sensitive": false,
"value": {
"bar": 1000.1,
"example": 1001
},
"type": [
"object",
{
"bar": "number",
"example": "number"
}
]
},
"a-sensitive-value": {
"sensitive": true,
"value": "hopefully you cannot see me",
"type": "string"
},
"a-string": {
"sensitive": false,
"value": "example string",
"type": "string"
},
"a-true-bool": {
"sensitive": false,
"value": true,
"type": "bool"
},
"a-tuple": {
"sensitive": false,
"value": [
1,
"example"
],
"type": [
"tuple",
[
"number",
"string"
]
]
},
"an-int": {
"sensitive": false,
"value": 1001,
"type": "number"
},
"escapes": {
"sensitive": false,
"value": "line 1\nline 2\n\\\\\\\\\n",
"type": "string"
},
"myoutput": {
"sensitive": false,
"value": {
"nesting1": {
"nesting2": {
"nesting3": "4263891374290101092"
}
}
},
"type": [
"object",
{
"nesting1": [
"object",
{
"nesting2": [
"object",
{
"nesting3": "string"
}
]
}
]
}
]
},
"random": {
"sensitive": false,
"value": "8b3086889a9ef7a5",
"type": "string"
}
}

0 comments on commit 10c6e3f

Please sign in to comment.