-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from reproio/known_after_apply
support to display `known after apply` in-place update
- Loading branch information
Showing
10 changed files
with
480 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package format | ||
|
||
import ( | ||
tfjson "github.com/hashicorp/terraform-json" | ||
) | ||
|
||
func FormatUnknownChange(change *tfjson.Change) (*tfjson.Change, error) { | ||
if change.Actions.Update() { | ||
for k, v := range change.AfterUnknown.(map[string]interface{}) { | ||
switch v.(type) { | ||
case bool: | ||
change.After.(map[string]interface{})[k] = "(known after apply)" | ||
} | ||
} | ||
} | ||
return change, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package format_json_test | ||
|
||
import ( | ||
tfjson "github.com/hashicorp/terraform-json" | ||
"github.com/reproio/terraform-j2md/internal/format" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestFormatUnknownPlan(t *testing.T) { | ||
type args struct { | ||
old *tfjson.Change | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *tfjson.Change | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "plain string", | ||
args: args{ | ||
old: &tfjson.Change{ | ||
Actions: tfjson.Actions{tfjson.ActionUpdate}, | ||
Before: map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
After: map[string]interface{}{}, | ||
AfterUnknown: map[string]interface{}{ | ||
"foo": true, | ||
}, | ||
}, | ||
}, | ||
want: &tfjson.Change{ | ||
Actions: tfjson.Actions{tfjson.ActionUpdate}, | ||
Before: map[string]interface{}{ | ||
"foo": "bar", | ||
}, | ||
After: map[string]interface{}{ | ||
"foo": "(known after apply)", | ||
}, | ||
AfterUnknown: map[string]interface{}{ | ||
"foo": true, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := format.FormatUnknownChange(tt.args.old) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("FormatJsonPlan() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("FormatJsonPlan() got = \n%v\n, want \n%v", got.After, tt.want.After) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
### 1 to add, 1 to change, 1 to destroy, 0 to replace. | ||
- add | ||
- random_id.test2 | ||
- change | ||
- env_variable.test | ||
- destroy | ||
- random_id.test | ||
<details><summary>Change details</summary> | ||
|
||
````````diff | ||
# env_variable.test will be updated in-place | ||
@@ -1,6 +1,6 @@ | ||
{ | ||
"id": "07ec30c9d869e0f6392f", | ||
- "name": "07ec30c9d869e0f6392f", | ||
+ "name": "(known after apply)", | ||
"value": "REDACTED_SENSITIVE" | ||
} | ||
|
||
```````` | ||
|
||
````````diff | ||
# random_id.test will be destroyed | ||
@@ -1,11 +1,2 @@ | ||
-{ | ||
- "b64_std": "B+wwydhp4PY5Lw==", | ||
- "b64_url": "B-wwydhp4PY5Lw", | ||
- "byte_length": 10, | ||
- "dec": "37413512560416367458607", | ||
- "hex": "07ec30c9d869e0f6392f", | ||
- "id": "B-wwydhp4PY5Lw", | ||
- "keepers": null, | ||
- "prefix": null | ||
-} | ||
+null | ||
|
||
```````` | ||
|
||
````````diff | ||
# random_id.test2 will be created | ||
@@ -1,2 +1,6 @@ | ||
-null | ||
+{ | ||
+ "byte_length": 10, | ||
+ "keepers": null, | ||
+ "prefix": null | ||
+} | ||
|
||
```````` | ||
|
||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
terraform { | ||
required_providers { | ||
env = { | ||
source = "tchupp/env" | ||
version = "0.0.2" | ||
} | ||
} | ||
} | ||
|
||
provider "env" { | ||
# Configuration options | ||
} | ||
|
||
resource "env_variable" "test" { | ||
name = random_id.test2.hex | ||
} | ||
|
||
#resource "random_id" "test" { | ||
# byte_length = 10 | ||
#} | ||
|
||
resource "random_id" "test2" { | ||
byte_length = 10 | ||
} |
Oops, something went wrong.