Skip to content

Commit fc8ed76

Browse files
ephemeral: render write-only attributes in plan UI
1 parent 8468387 commit fc8ed76

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

internal/command/jsonformat/plan_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7452,6 +7452,94 @@ func TestResourceChange_sensitiveVariable(t *testing.T) {
74527452
runTestCases(t, testCases)
74537453
}
74547454

7455+
func TestResourceChange_writeOnlyAttributes(t *testing.T) {
7456+
testCases := map[string]testCase{
7457+
"write-only attribute create": {
7458+
Action: plans.Create,
7459+
Mode: addrs.ManagedResourceMode,
7460+
Before: cty.NullVal(cty.Object(map[string]cty.Type{
7461+
"id": cty.String,
7462+
"write_only": cty.String,
7463+
"conn_info": cty.Object(map[string]cty.Type{
7464+
"user": cty.String,
7465+
"write_only_set_password": cty.String,
7466+
}),
7467+
})),
7468+
After: cty.ObjectVal(map[string]cty.Value{
7469+
"id": cty.StringVal("i-02ae66f368e8518a9"),
7470+
"write_only": cty.NullVal(cty.String),
7471+
"conn_info": cty.ObjectVal(map[string]cty.Value{
7472+
"user": cty.StringVal("not-secret"),
7473+
"write_only_set_password": cty.NullVal(cty.String),
7474+
}),
7475+
}),
7476+
Schema: &configschema.Block{
7477+
Attributes: map[string]*configschema.Attribute{
7478+
"id": {Type: cty.String, Optional: true, Computed: true},
7479+
"write_only": {Type: cty.String, WriteOnly: true},
7480+
"conn_info": {
7481+
NestedType: &configschema.Object{
7482+
Nesting: configschema.NestingSingle,
7483+
Attributes: map[string]*configschema.Attribute{
7484+
"user": {Type: cty.String, Optional: true},
7485+
"write_only_set_password": {Type: cty.String, Optional: true, Sensitive: true, WriteOnly: true},
7486+
},
7487+
},
7488+
},
7489+
},
7490+
},
7491+
ExpectedOutput: ` # test_instance.example will be created
7492+
+ resource "test_instance" "example" {
7493+
+ conn_info = {
7494+
+ user = "not-secret"
7495+
}
7496+
+ id = "i-02ae66f368e8518a9"
7497+
}`,
7498+
},
7499+
"write-only attribute update": {
7500+
Action: plans.Update,
7501+
Mode: addrs.ManagedResourceMode,
7502+
Before: cty.ObjectVal(map[string]cty.Value{
7503+
"id": cty.StringVal("i-02ae66f368e8518a9"),
7504+
"write_only": cty.NullVal(cty.String),
7505+
"conn_info": cty.ObjectVal(map[string]cty.Value{
7506+
"user": cty.StringVal("not-secret"),
7507+
"write_only_set_password": cty.NullVal(cty.String),
7508+
}),
7509+
}),
7510+
After: cty.ObjectVal(map[string]cty.Value{
7511+
"id": cty.StringVal("i-02ae66f368e8518a9"),
7512+
"write_only": cty.NullVal(cty.String),
7513+
"conn_info": cty.ObjectVal(map[string]cty.Value{
7514+
"user": cty.StringVal("not-secret"),
7515+
"write_only_set_password": cty.NullVal(cty.String),
7516+
}),
7517+
}),
7518+
Schema: &configschema.Block{
7519+
Attributes: map[string]*configschema.Attribute{
7520+
"id": {Type: cty.String, Optional: true, Computed: true},
7521+
"write_only": {Type: cty.String, WriteOnly: true},
7522+
"conn_info": {
7523+
NestedType: &configschema.Object{
7524+
Nesting: configschema.NestingSingle,
7525+
Attributes: map[string]*configschema.Attribute{
7526+
"user": {Type: cty.String, Optional: true},
7527+
"write_only_set_password": {Type: cty.String, Optional: true, Sensitive: true, WriteOnly: true},
7528+
},
7529+
},
7530+
},
7531+
},
7532+
},
7533+
ExpectedOutput: ` # test_instance.example will be updated in-place
7534+
~ resource "test_instance" "example" {
7535+
id = "i-02ae66f368e8518a9"
7536+
# (1 unchanged attribute hidden)
7537+
}`,
7538+
},
7539+
}
7540+
runTestCases(t, testCases)
7541+
}
7542+
74557543
func TestResourceChange_moved(t *testing.T) {
74567544
prevRunAddr := addrs.Resource{
74577545
Mode: addrs.ManagedResourceMode,

0 commit comments

Comments
 (0)