From 3913c3c5786fb6a1daf04a8f1b7bb333a7865a74 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Mon, 6 Jan 2025 15:51:26 +0100 Subject: [PATCH] ephemeral: add test case for block rendering --- internal/command/jsonformat/plan_test.go | 93 ++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/internal/command/jsonformat/plan_test.go b/internal/command/jsonformat/plan_test.go index 5b5cd1055581..0d3ba3a490f6 100644 --- a/internal/command/jsonformat/plan_test.go +++ b/internal/command/jsonformat/plan_test.go @@ -7464,6 +7464,10 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { "user": cty.String, "write_only_set_password": cty.String, }), + "block": cty.List(cty.Object(map[string]cty.Type{ + "user": cty.String, + "block_set_password": cty.String, + })), })), After: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("i-02ae66f368e8518a9"), @@ -7472,6 +7476,10 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { "user": cty.StringVal("not-secret"), "write_only_set_password": cty.NullVal(cty.String), }), + "block": cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{ + "user": cty.StringVal("this-is-not-secret"), + "block_set_password": cty.NullVal(cty.String), + })}), }), Schema: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -7487,6 +7495,17 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { }, }, }, + BlockTypes: map[string]*configschema.NestedBlock{ + "block": { + Nesting: configschema.NestingList, + Block: configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "user": {Type: cty.String, Optional: true}, + "block_set_password": {Type: cty.String, Optional: true, Sensitive: true, WriteOnly: true}, + }, + }, + }, + }, }, ExpectedOutput: ` # test_instance.example will be created + resource "test_instance" "example" { @@ -7496,6 +7515,11 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { } + id = "i-02ae66f368e8518a9" + write_only = (write-only attribute) + + + block { + + block_set_password = (write-only attribute) + + user = "this-is-not-secret" + } }`, }, "update attribute": { @@ -7508,6 +7532,10 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { "user": cty.StringVal("not-secret"), "write_only_set_password": cty.NullVal(cty.String), }), + "block": cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{ + "user": cty.StringVal("not-so-secret"), + "block_set_password": cty.NullVal(cty.String), + })}), }), After: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("i-02ae66f368e8518a10"), @@ -7516,6 +7544,10 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { "user": cty.StringVal("not-secret"), "write_only_set_password": cty.NullVal(cty.String), }), + "block": cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{ + "user": cty.StringVal("not-so-secret"), + "block_set_password": cty.NullVal(cty.String), + })}), }), Schema: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -7531,11 +7563,24 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { }, }, }, + BlockTypes: map[string]*configschema.NestedBlock{ + "block": { + Nesting: configschema.NestingList, + Block: configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "user": {Type: cty.String, Optional: true}, + "block_set_password": {Type: cty.String, Optional: true, Sensitive: true, WriteOnly: true}, + }, + }, + }, + }, }, ExpectedOutput: ` # test_instance.example will be updated in-place ~ resource "test_instance" "example" { ~ id = "i-02ae66f368e8518a9" -> "i-02ae66f368e8518a10" # (2 unchanged attributes hidden) + + # (1 unchanged block hidden) }`, }, "update - delete block": { @@ -7548,6 +7593,10 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { "user": cty.StringVal("not-secret"), "write_only_set_password": cty.NullVal(cty.String), }), + "block": cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{ + "user": cty.StringVal("not-secret"), + "block_set_password": cty.NullVal(cty.String), + })}), }), After: cty.ObjectVal(map[string]cty.Value{ "id": cty.StringVal("i-02ae66f368e8518a9"), @@ -7556,6 +7605,10 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { "user": cty.String, "write_only_set_password": cty.String, })), + "block": cty.NullVal(cty.List(cty.Object(map[string]cty.Type{ + "user": cty.String, + "block_set_password": cty.String, + }))), }), Schema: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -7571,6 +7624,17 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { }, }, }, + BlockTypes: map[string]*configschema.NestedBlock{ + "block": { + Nesting: configschema.NestingList, + Block: configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "user": {Type: cty.String, Optional: true}, + "block_set_password": {Type: cty.String, Optional: true, Sensitive: true, WriteOnly: true}, + }, + }, + }, + }, }, ExpectedOutput: ` # test_instance.example will be updated in-place ~ resource "test_instance" "example" { @@ -7580,6 +7644,11 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { } -> null id = "i-02ae66f368e8518a9" # (1 unchanged attribute hidden) + + - block { + - block_set_password = (write-only attribute) -> null + - user = "not-secret" -> null + } }`, }, "delete": { @@ -7592,6 +7661,10 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { "user": cty.StringVal("not-secret"), "write_only_set_password": cty.NullVal(cty.String), }), + "block": cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{ + "user": cty.StringVal("not-secret"), + "block_set_password": cty.NullVal(cty.String), + })}), }), After: cty.NullVal(cty.Object(map[string]cty.Type{ "id": cty.String, @@ -7600,6 +7673,10 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { "user": cty.String, "write_only_set_password": cty.String, }), + "block": cty.List(cty.Object(map[string]cty.Type{ + "user": cty.String, + "block_set_password": cty.String, + })), })), Schema: &configschema.Block{ Attributes: map[string]*configschema.Attribute{ @@ -7615,6 +7692,17 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { }, }, }, + BlockTypes: map[string]*configschema.NestedBlock{ + "block": { + Nesting: configschema.NestingList, + Block: configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "user": {Type: cty.String, Optional: true}, + "block_set_password": {Type: cty.String, Optional: true, Sensitive: true, WriteOnly: true}, + }, + }, + }, + }, }, ExpectedOutput: ` # test_instance.example will be destroyed - resource "test_instance" "example" { @@ -7624,6 +7712,11 @@ func TestResourceChange_writeOnlyAttributes(t *testing.T) { } -> null - id = "i-02ae66f368e8518a9" -> null - write_only = (write-only attribute) -> null + + - block { + - block_set_password = (write-only attribute) -> null + - user = "not-secret" -> null + } }`, }, }