Skip to content

Commit

Permalink
SDKv2 Diff tests for secret list type (#2835)
Browse files Browse the repository at this point in the history
This adds Diff tests for the SDKv2 bridge for secrets in list types.

Part of #2791
  • Loading branch information
VenelinMartinov authored Jan 17, 2025
1 parent 80add2e commit 278674c
Show file tree
Hide file tree
Showing 37 changed files with 1,982 additions and 3 deletions.
41 changes: 38 additions & 3 deletions pkg/tests/diff_test/detailed_diff_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
},
},
}
_ = listBlockSchemaNestedForceNew

maxItemsOneBlockSchema := schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -148,7 +147,6 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
},
},
}
_ = maxItemsOneBlockSchemaForceNew

maxItemsOneBlockSchemaNestedForceNew := schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -168,7 +166,42 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
},
},
}
_ = maxItemsOneBlockSchemaNestedForceNew

listBlockSchemaSensitive := schema.Resource{
Schema: map[string]*schema.Schema{
"list_block": {
Type: schema.TypeList,
Optional: true,
Sensitive: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested_prop": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
}

listBlockSchemaNestedSensitive := schema.Resource{
Schema: map[string]*schema.Schema{
"list_block": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested_prop": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
},
},
},
},
},
}

attrList := func(arr *[]string) map[string]cty.Value {
if arr == nil {
Expand Down Expand Up @@ -240,6 +273,8 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
{"list block", listBlockSchema, blockList},
{"list block force new", listBlockSchemaForceNew, blockList},
{"list block nested force new", listBlockSchemaNestedForceNew, blockList},
{"list block sensitive", listBlockSchemaSensitive, blockList},
{"list block nested sensitive", listBlockSchemaNestedSensitive, nestedBlockList},
}

maxItemsOnePairs := []struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tests.testOutput{
initialValue: nil, changeValue: &[]string{},
tfOut: `
No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.
`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
Resources:
2 unchanged
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
tests.testOutput{
initialValue: nil, changeValue: &[]string{
"val1",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

+ list_block {
+ nested_prop = (sensitive value)
}
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
+ listBlocks: [secret]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listBlocks": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
tests.testOutput{
initialValue: &[]string{
"val1",
},
changeValue: &[]string{"val2"},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

~ list_block {
~ nested_prop = (sensitive value)
}
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ listBlocks: [
~ [0]: {
~ nestedProp: [secret] => [secret]
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listBlocks[0].nestedProp": map[string]interface{}{"kind": "UPDATE"}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
tests.testOutput{
initialValue: &[]string{
"val1",
"val2",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

+ list_block {
+ nested_prop = (sensitive value)
}

# (2 unchanged blocks hidden)
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ listBlocks: [
+ [2]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"listBlocks[2]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
tests.testOutput{
initialValue: &[]string{
"val2",
"val3",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

~ list_block {
~ nested_prop = (sensitive value)
}
~ list_block {
~ nested_prop = (sensitive value)
}
+ list_block {
+ nested_prop = (sensitive value)
}
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ listBlocks: [
~ [0]: {
~ nestedProp: [secret] => [secret]
}
~ [1]: {
~ nestedProp: [secret] => [secret]
}
+ [2]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{
"listBlocks[0].nestedProp": map[string]interface{}{"kind": "UPDATE"},
"listBlocks[1].nestedProp": map[string]interface{}{"kind": "UPDATE"},
"listBlocks[2]": map[string]interface{}{},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
tests.testOutput{
initialValue: &[]string{
"val1",
"val3",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

~ list_block {
~ nested_prop = (sensitive value)
}
+ list_block {
+ nested_prop = (sensitive value)
}

# (1 unchanged block hidden)
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ listBlocks: [
~ [1]: {
~ nestedProp: [secret] => [secret]
}
+ [2]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{
"listBlocks[1].nestedProp": map[string]interface{}{"kind": "UPDATE"},
"listBlocks[2]": map[string]interface{}{},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
tests.testOutput{
initialValue: &[]string{
"val1",
"val2",
"val3",
},
changeValue: &[]string{
"val2",
"val1",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# crossprovider_test_res.example will be updated in-place
~ resource "crossprovider_test_res" "example" {
id = "newid"

~ list_block {
~ nested_prop = (sensitive value)
}
~ list_block {
~ nested_prop = (sensitive value)
}
- list_block {
- nested_prop = (sensitive value) -> null
}
}

Plan: 0 to add, 1 to change, 0 to destroy.

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ crossprovider:index/testRes:TestRes: (update)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ listBlocks: [
~ [0]: {
~ nestedProp: [secret] => [secret]
}
~ [1]: {
~ nestedProp: [secret] => [secret]
}
- [2]: [secret]
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{
"listBlocks[0].nestedProp": map[string]interface{}{"kind": "UPDATE"},
"listBlocks[1].nestedProp": map[string]interface{}{"kind": "UPDATE"},
"listBlocks[2]": map[string]interface{}{"kind": "DELETE"},
},
}
Loading

0 comments on commit 278674c

Please sign in to comment.