Skip to content

Commit 278674c

Browse files
SDKv2 Diff tests for secret list type (#2835)
This adds Diff tests for the SDKv2 bridge for secrets in list types. Part of #2791
1 parent 80add2e commit 278674c

37 files changed

+1982
-3
lines changed

pkg/tests/diff_test/detailed_diff_list_test.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
110110
},
111111
},
112112
}
113-
_ = listBlockSchemaNestedForceNew
114113

115114
maxItemsOneBlockSchema := schema.Resource{
116115
Schema: map[string]*schema.Schema{
@@ -148,7 +147,6 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
148147
},
149148
},
150149
}
151-
_ = maxItemsOneBlockSchemaForceNew
152150

153151
maxItemsOneBlockSchemaNestedForceNew := schema.Resource{
154152
Schema: map[string]*schema.Schema{
@@ -168,7 +166,42 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
168166
},
169167
},
170168
}
171-
_ = maxItemsOneBlockSchemaNestedForceNew
169+
170+
listBlockSchemaSensitive := schema.Resource{
171+
Schema: map[string]*schema.Schema{
172+
"list_block": {
173+
Type: schema.TypeList,
174+
Optional: true,
175+
Sensitive: true,
176+
Elem: &schema.Resource{
177+
Schema: map[string]*schema.Schema{
178+
"nested_prop": {
179+
Type: schema.TypeString,
180+
Optional: true,
181+
},
182+
},
183+
},
184+
},
185+
},
186+
}
187+
188+
listBlockSchemaNestedSensitive := schema.Resource{
189+
Schema: map[string]*schema.Schema{
190+
"list_block": {
191+
Type: schema.TypeList,
192+
Optional: true,
193+
Elem: &schema.Resource{
194+
Schema: map[string]*schema.Schema{
195+
"nested_prop": {
196+
Type: schema.TypeString,
197+
Optional: true,
198+
Sensitive: true,
199+
},
200+
},
201+
},
202+
},
203+
},
204+
}
172205

173206
attrList := func(arr *[]string) map[string]cty.Value {
174207
if arr == nil {
@@ -240,6 +273,8 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
240273
{"list block", listBlockSchema, blockList},
241274
{"list block force new", listBlockSchemaForceNew, blockList},
242275
{"list block nested force new", listBlockSchemaNestedForceNew, blockList},
276+
{"list block sensitive", listBlockSchemaSensitive, blockList},
277+
{"list block nested sensitive", listBlockSchemaNestedSensitive, nestedBlockList},
243278
}
244279

245280
maxItemsOnePairs := []struct {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests.testOutput{
2+
initialValue: nil, changeValue: &[]string{},
3+
tfOut: `
4+
No changes. Your infrastructure matches the configuration.
5+
6+
Terraform has compared your real infrastructure against your configuration
7+
and found no differences, so no changes are needed.
8+
`,
9+
pulumiOut: `Previewing update (test):
10+
pulumi:pulumi:Stack: (same)
11+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
12+
Resources:
13+
2 unchanged
14+
`,
15+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
tests.testOutput{
2+
initialValue: nil, changeValue: &[]string{
3+
"val1",
4+
},
5+
tfOut: `
6+
Terraform used the selected providers to generate the following execution
7+
plan. Resource actions are indicated with the following symbols:
8+
~ update in-place
9+
10+
Terraform will perform the following actions:
11+
12+
# crossprovider_test_res.example will be updated in-place
13+
~ resource "crossprovider_test_res" "example" {
14+
id = "newid"
15+
16+
+ list_block {
17+
+ nested_prop = (sensitive value)
18+
}
19+
}
20+
21+
Plan: 0 to add, 1 to change, 0 to destroy.
22+
23+
`,
24+
pulumiOut: `Previewing update (test):
25+
pulumi:pulumi:Stack: (same)
26+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
27+
~ crossprovider:index/testRes:TestRes: (update)
28+
[id=newid]
29+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
30+
+ listBlocks: [secret]
31+
Resources:
32+
~ 1 to update
33+
1 unchanged
34+
`,
35+
detailedDiff: map[string]interface{}{"listBlocks": map[string]interface{}{}},
36+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
tests.testOutput{
2+
initialValue: &[]string{
3+
"val1",
4+
},
5+
changeValue: &[]string{"val2"},
6+
tfOut: `
7+
Terraform used the selected providers to generate the following execution
8+
plan. Resource actions are indicated with the following symbols:
9+
~ update in-place
10+
11+
Terraform will perform the following actions:
12+
13+
# crossprovider_test_res.example will be updated in-place
14+
~ resource "crossprovider_test_res" "example" {
15+
id = "newid"
16+
17+
~ list_block {
18+
~ nested_prop = (sensitive value)
19+
}
20+
}
21+
22+
Plan: 0 to add, 1 to change, 0 to destroy.
23+
24+
`,
25+
pulumiOut: `Previewing update (test):
26+
pulumi:pulumi:Stack: (same)
27+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
28+
~ crossprovider:index/testRes:TestRes: (update)
29+
[id=newid]
30+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
31+
~ listBlocks: [
32+
~ [0]: {
33+
~ nestedProp: [secret] => [secret]
34+
}
35+
]
36+
Resources:
37+
~ 1 to update
38+
1 unchanged
39+
`,
40+
detailedDiff: map[string]interface{}{"listBlocks[0].nestedProp": map[string]interface{}{"kind": "UPDATE"}},
41+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
tests.testOutput{
2+
initialValue: &[]string{
3+
"val1",
4+
"val2",
5+
},
6+
changeValue: &[]string{
7+
"val1",
8+
"val2",
9+
"val3",
10+
},
11+
tfOut: `
12+
Terraform used the selected providers to generate the following execution
13+
plan. Resource actions are indicated with the following symbols:
14+
~ update in-place
15+
16+
Terraform will perform the following actions:
17+
18+
# crossprovider_test_res.example will be updated in-place
19+
~ resource "crossprovider_test_res" "example" {
20+
id = "newid"
21+
22+
+ list_block {
23+
+ nested_prop = (sensitive value)
24+
}
25+
26+
# (2 unchanged blocks hidden)
27+
}
28+
29+
Plan: 0 to add, 1 to change, 0 to destroy.
30+
31+
`,
32+
pulumiOut: `Previewing update (test):
33+
pulumi:pulumi:Stack: (same)
34+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
35+
~ crossprovider:index/testRes:TestRes: (update)
36+
[id=newid]
37+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
38+
~ listBlocks: [
39+
+ [2]: [secret]
40+
]
41+
Resources:
42+
~ 1 to update
43+
1 unchanged
44+
`,
45+
detailedDiff: map[string]interface{}{"listBlocks[2]": map[string]interface{}{}},
46+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
tests.testOutput{
2+
initialValue: &[]string{
3+
"val2",
4+
"val3",
5+
},
6+
changeValue: &[]string{
7+
"val1",
8+
"val2",
9+
"val3",
10+
},
11+
tfOut: `
12+
Terraform used the selected providers to generate the following execution
13+
plan. Resource actions are indicated with the following symbols:
14+
~ update in-place
15+
16+
Terraform will perform the following actions:
17+
18+
# crossprovider_test_res.example will be updated in-place
19+
~ resource "crossprovider_test_res" "example" {
20+
id = "newid"
21+
22+
~ list_block {
23+
~ nested_prop = (sensitive value)
24+
}
25+
~ list_block {
26+
~ nested_prop = (sensitive value)
27+
}
28+
+ list_block {
29+
+ nested_prop = (sensitive value)
30+
}
31+
}
32+
33+
Plan: 0 to add, 1 to change, 0 to destroy.
34+
35+
`,
36+
pulumiOut: `Previewing update (test):
37+
pulumi:pulumi:Stack: (same)
38+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
39+
~ crossprovider:index/testRes:TestRes: (update)
40+
[id=newid]
41+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
42+
~ listBlocks: [
43+
~ [0]: {
44+
~ nestedProp: [secret] => [secret]
45+
}
46+
~ [1]: {
47+
~ nestedProp: [secret] => [secret]
48+
}
49+
+ [2]: [secret]
50+
]
51+
Resources:
52+
~ 1 to update
53+
1 unchanged
54+
`,
55+
detailedDiff: map[string]interface{}{
56+
"listBlocks[0].nestedProp": map[string]interface{}{"kind": "UPDATE"},
57+
"listBlocks[1].nestedProp": map[string]interface{}{"kind": "UPDATE"},
58+
"listBlocks[2]": map[string]interface{}{},
59+
},
60+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
tests.testOutput{
2+
initialValue: &[]string{
3+
"val1",
4+
"val3",
5+
},
6+
changeValue: &[]string{
7+
"val1",
8+
"val2",
9+
"val3",
10+
},
11+
tfOut: `
12+
Terraform used the selected providers to generate the following execution
13+
plan. Resource actions are indicated with the following symbols:
14+
~ update in-place
15+
16+
Terraform will perform the following actions:
17+
18+
# crossprovider_test_res.example will be updated in-place
19+
~ resource "crossprovider_test_res" "example" {
20+
id = "newid"
21+
22+
~ list_block {
23+
~ nested_prop = (sensitive value)
24+
}
25+
+ list_block {
26+
+ nested_prop = (sensitive value)
27+
}
28+
29+
# (1 unchanged block hidden)
30+
}
31+
32+
Plan: 0 to add, 1 to change, 0 to destroy.
33+
34+
`,
35+
pulumiOut: `Previewing update (test):
36+
pulumi:pulumi:Stack: (same)
37+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
38+
~ crossprovider:index/testRes:TestRes: (update)
39+
[id=newid]
40+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
41+
~ listBlocks: [
42+
~ [1]: {
43+
~ nestedProp: [secret] => [secret]
44+
}
45+
+ [2]: [secret]
46+
]
47+
Resources:
48+
~ 1 to update
49+
1 unchanged
50+
`,
51+
detailedDiff: map[string]interface{}{
52+
"listBlocks[1].nestedProp": map[string]interface{}{"kind": "UPDATE"},
53+
"listBlocks[2]": map[string]interface{}{},
54+
},
55+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
tests.testOutput{
2+
initialValue: &[]string{
3+
"val1",
4+
"val2",
5+
"val3",
6+
},
7+
changeValue: &[]string{
8+
"val2",
9+
"val1",
10+
},
11+
tfOut: `
12+
Terraform used the selected providers to generate the following execution
13+
plan. Resource actions are indicated with the following symbols:
14+
~ update in-place
15+
16+
Terraform will perform the following actions:
17+
18+
# crossprovider_test_res.example will be updated in-place
19+
~ resource "crossprovider_test_res" "example" {
20+
id = "newid"
21+
22+
~ list_block {
23+
~ nested_prop = (sensitive value)
24+
}
25+
~ list_block {
26+
~ nested_prop = (sensitive value)
27+
}
28+
- list_block {
29+
- nested_prop = (sensitive value) -> null
30+
}
31+
}
32+
33+
Plan: 0 to add, 1 to change, 0 to destroy.
34+
35+
`,
36+
pulumiOut: `Previewing update (test):
37+
pulumi:pulumi:Stack: (same)
38+
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
39+
~ crossprovider:index/testRes:TestRes: (update)
40+
[id=newid]
41+
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
42+
~ listBlocks: [
43+
~ [0]: {
44+
~ nestedProp: [secret] => [secret]
45+
}
46+
~ [1]: {
47+
~ nestedProp: [secret] => [secret]
48+
}
49+
- [2]: [secret]
50+
]
51+
Resources:
52+
~ 1 to update
53+
1 unchanged
54+
`,
55+
detailedDiff: map[string]interface{}{
56+
"listBlocks[0].nestedProp": map[string]interface{}{"kind": "UPDATE"},
57+
"listBlocks[1].nestedProp": map[string]interface{}{"kind": "UPDATE"},
58+
"listBlocks[2]": map[string]interface{}{"kind": "DELETE"},
59+
},
60+
}

0 commit comments

Comments
 (0)