Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pkg/tests/diff_test/detailed_diff_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,28 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
},
}

listBlockSchemaNestedDefault := schema.Resource{
Schema: map[string]*schema.Schema{
"prop": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested_prop": {
Type: schema.TypeString,
Optional: true,
},
"default": {
Type: schema.TypeString,
Optional: true,
Default: "default",
},
},
},
},
},
}

listPairs := []diffSchemaValueMakerPair[[]string]{
{"list attribute", listAttrSchema, listValueMaker},
{"list attribute force new", listAttrSchemaForceNew, listValueMaker},
Expand All @@ -207,6 +229,11 @@ func TestSDKv2DetailedDiffList(t *testing.T) {
{"list block nested force new", listBlockSchemaNestedForceNew, nestedListValueMaker},
{"list block sensitive", listBlockSchemaSensitive, nestedListValueMaker},
{"list block nested sensitive", listBlockSchemaNestedSensitive, nestedListValueMaker},
{"list block nested default", listBlockSchemaNestedDefault, nestedListValueMaker},
{
"list block nested default with default specified in program",
listBlockSchemaNestedDefault, nestedListValueMakerWithDefaultSpecified,
},
}

maxItemsOnePairs := []diffSchemaValueMakerPair[[]string]{
Expand Down
34 changes: 34 additions & 0 deletions pkg/tests/diff_test/detailed_diff_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,37 @@ func TestSDKv2DetailedDiffSetBlockSensitive(t *testing.T) {

runSDKv2TestMatrix(t, diffSchemaValueMakerPairs, setScenarios())
}

func TestSDKv2DetailedDiffSetDefault(t *testing.T) {
t.Parallel()
// Note Default is not valid for set types.

blockSchemaNestedDefault := schema.Resource{
Schema: map[string]*schema.Schema{
"prop": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested_prop": {
Type: schema.TypeString,
Optional: true,
},
"default": {
Type: schema.TypeString,
Optional: true,
Default: "default",
},
},
},
},
},
}

diffSchemaValueMakerPairs := []diffSchemaValueMakerPair[[]string]{
{"block nested default", blockSchemaNestedDefault, nestedListValueMaker},
{"block nested default with default specified in program", blockSchemaNestedDefault, nestedListValueMakerWithDefaultSpecified},
}

runSDKv2TestMatrix(t, diffSchemaValueMakerPairs, setScenarios())
}
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,42 @@
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"

+ prop {
+ default = "default"
+ nested_prop = "val1"
}
}

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]
+ props: [
+ [0]: {
+ default : "default"
+ nestedProp: "val1"
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"props": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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"

~ prop {
~ nested_prop = "val1" -> "val2"
# (1 unchanged attribute 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]
~ props: [
~ [0]: {
~ nestedProp: "val1" => "val2"
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE"}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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"

+ prop {
+ default = "default"
+ nested_prop = "val3"
}

# (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]
~ props: [
+ [2]: {
+ default : "default"
+ nestedProp: "val3"
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"props[2]": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
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"

~ prop {
~ nested_prop = "val2" -> "val1"
# (1 unchanged attribute hidden)
}
~ prop {
~ nested_prop = "val3" -> "val2"
# (1 unchanged attribute hidden)
}
+ prop {
+ default = "default"
+ nested_prop = "val3"
}
}

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]
~ props: [
~ [0]: {
~ nestedProp: "val2" => "val1"
}
~ [1]: {
~ nestedProp: "val3" => "val2"
}
+ [2]: {
+ default : "default"
+ nestedProp: "val3"
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{
"props[0].nestedProp": map[string]interface{}{"kind": "UPDATE"},
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE"},
"props[2]": map[string]interface{}{},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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"

~ prop {
~ nested_prop = "val3" -> "val2"
# (1 unchanged attribute hidden)
}
+ prop {
+ default = "default"
+ nested_prop = "val3"
}

# (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]
~ props: [
~ [1]: {
~ nestedProp: "val3" => "val2"
}
+ [2]: {
+ default : "default"
+ nestedProp: "val3"
}
]
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{
"props[1].nestedProp": map[string]interface{}{"kind": "UPDATE"},
"props[2]": map[string]interface{}{},
},
}
Loading
Loading