Skip to content

Commit

Permalink
SDKv2 detailed diff set tests for replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Dec 11, 2024
1 parent 99da8d3 commit e34124f
Show file tree
Hide file tree
Showing 81 changed files with 1,769 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/tests/detailed_diff_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,24 @@ func TestDetailedDiffSetCrossTest(t *testing.T) {
}

blockSchemaForceNew := schema.Resource{
Schema: map[string]*schema.Schema{
"test": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
}

blockSchemaNestedForceNew := schema.Resource{
Schema: map[string]*schema.Schema{
"test": {
Type: schema.TypeSet,
Expand Down Expand Up @@ -880,7 +898,8 @@ func TestDetailedDiffSetCrossTest(t *testing.T) {
{"attribute no force new", attributeSchema, attrList},
{"attribute force new", attributeSchemaForceNew, attrList},
{"block no force new", blockSchema, nestedAttrList},
{"block force new", blockSchemaForceNew, nestedAttrList},
{"block top level force new", blockSchemaForceNew, nestedAttrList},
{"block nested force new", blockSchemaNestedForceNew, nestedAttrList},
}

scenarios := []struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
tests.testOutput{
initialValue: &[]string{},
changeValue: &[]string{"value"},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+/- create replacement and then destroy

Terraform will perform the following actions:

# crossprovider_test_res.example must be replaced
+/- resource "crossprovider_test_res" "example" {
~ id = "newid" -> (known after apply)

+ test { # forces replacement
+ nested = "value"
}
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
+-crossprovider:index/testRes:TestRes: (replace)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
+ tests: [
+ [0]: {
+ nested : "value"
}
]
Resources:
+-1 to replace
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests": map[string]interface{}{"kind": "ADD_REPLACE"}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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:
+/- create replacement and then destroy

Terraform will perform the following actions:

# crossprovider_test_res.example must be replaced
+/- resource "crossprovider_test_res" "example" {
~ id = "newid" -> (known after apply)

+ test { # forces replacement
+ nested = "val3"
}

# (2 unchanged blocks hidden)
}

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

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

Terraform will perform the following actions:

# crossprovider_test_res.example must be replaced
+/- resource "crossprovider_test_res" "example" {
~ id = "newid" -> (known after apply)

+ test { # forces replacement
+ nested = "val1"
}

# (2 unchanged blocks hidden)
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
+-crossprovider:index/testRes:TestRes: (replace)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ tests: [
+ [2]: {
+ nested : "val1"
}
]
Resources:
+-1 to replace
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests[2]": map[string]interface{}{"kind": "ADD_REPLACE"}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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:
+/- create replacement and then destroy

Terraform will perform the following actions:

# crossprovider_test_res.example must be replaced
+/- resource "crossprovider_test_res" "example" {
~ id = "newid" -> (known after apply)

+ test { # forces replacement
+ nested = "val1"
}

# (2 unchanged blocks hidden)
}

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

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

Terraform will perform the following actions:

# crossprovider_test_res.example must be replaced
+/- resource "crossprovider_test_res" "example" {
~ id = "newid" -> (known after apply)

+ test { # forces replacement
+ nested = "val2"
}

# (2 unchanged blocks hidden)
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
+-crossprovider:index/testRes:TestRes: (replace)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ tests: [
+ [0]: {
+ nested : "val2"
}
]
Resources:
+-1 to replace
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests[0]": map[string]interface{}{"kind": "ADD_REPLACE"}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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:
+/- create replacement and then destroy

Terraform will perform the following actions:

# crossprovider_test_res.example must be replaced
+/- resource "crossprovider_test_res" "example" {
~ id = "newid" -> (known after apply)

+ test { # forces replacement
+ nested = "val2"
}

# (2 unchanged blocks hidden)
}

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

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

Terraform will perform the following actions:

# crossprovider_test_res.example must be replaced
+/- resource "crossprovider_test_res" "example" {
~ id = "newid" -> (known after apply)

+ test { # forces replacement
+ nested = "val3"
}

# (2 unchanged blocks hidden)
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
+-crossprovider:index/testRes:TestRes: (replace)
[id=newid]
[urn=urn:pulumi:test::project::crossprovider:index/testRes:TestRes::example]
~ tests: [
+ [1]: {
+ nested : "val3"
}
]
Resources:
+-1 to replace
1 unchanged
`,
detailedDiff: map[string]interface{}{"tests[1]": map[string]interface{}{"kind": "ADD_REPLACE"}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tests.testOutput{
initialValue: &[]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
`,
}
Loading

0 comments on commit e34124f

Please sign in to comment.