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
102 changes: 101 additions & 1 deletion pkg/tests/diff_test/detailed_diff_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

func setScenarios() []diffScenario[[]string] {
func oneElementScenarios() []diffScenario[[]string] {
return []diffScenario[[]string]{
{"unchanged non-empty", &[]string{"value"}, &[]string{"value"}},
{"unchanged empty", &[]string{}, &[]string{}},
Expand All @@ -23,7 +23,12 @@ func setScenarios() []diffScenario[[]string] {

{"added", &[]string{}, &[]string{"value"}},
{"removed", &[]string{"value"}, &[]string{}},
}
}

func setScenarios() []diffScenario[[]string] {
scenarios := oneElementScenarios()
multiElementScenarios := []diffScenario[[]string]{
{"removed front", &[]string{"val1", "val2", "val3"}, &[]string{"val2", "val3"}},
{"removed front unordered", &[]string{"val2", "val3", "val1"}, &[]string{"val3", "val1"}},
{"removed middle", &[]string{"val1", "val2", "val3"}, &[]string{"val1", "val3"}},
Expand Down Expand Up @@ -61,6 +66,8 @@ func setScenarios() []diffScenario[[]string] {
{"two added and two removed shuffled, no overlaps", &[]string{"val1", "val2", "val3", "val4"}, &[]string{"val5", "val6", "val1", "val2"}},
{"two added and two removed shuffled, with duplicates", &[]string{"val1", "val2", "val3", "val4"}, &[]string{"val1", "val5", "val6", "val2", "val1", "val2"}},
}

return append(scenarios, multiElementScenarios...)
}

func TestSDKv2DetailedDiffSetAttribute(t *testing.T) {
Expand Down Expand Up @@ -580,3 +587,96 @@ func TestSDKv2DetailedDiffSetDefault(t *testing.T) {

runSDKv2TestMatrix(t, diffSchemaValueMakerPairs, setScenarios())
}

func TestSDKv2DetailedDiffSetMaxItemsOne(t *testing.T) {
t.Parallel()

maxItemsOneAttrSchema := schema.Resource{
Schema: map[string]*schema.Schema{
"prop": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}

maxItemsOneAttrSchemaForceNew := schema.Resource{
Schema: map[string]*schema.Schema{
"prop": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}

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

maxItemsOneBlockSchemaForceNew := schema.Resource{
Schema: map[string]*schema.Schema{
"prop": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested_prop": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
}

maxItemsOneBlockSchemaNestedForceNew := schema.Resource{
Schema: map[string]*schema.Schema{
"prop": {
Type: schema.TypeSet,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nested_prop": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
},
},
},
}

diffSchemaValueMakerPairs := []diffSchemaValueMakerPair[[]string]{
{"max items one attribute", maxItemsOneAttrSchema, listValueMaker},
{"max items one attribute force new", maxItemsOneAttrSchemaForceNew, listValueMaker},
{"max items one block", maxItemsOneBlockSchema, nestedListValueMaker},
{"max items one block force new", maxItemsOneBlockSchemaForceNew, nestedListValueMaker},
{"max items one block nested force new", maxItemsOneBlockSchemaNestedForceNew, nestedListValueMaker},
}

runSDKv2TestMatrix(t, diffSchemaValueMakerPairs, oneElementScenarios())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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:
~ 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 = [
+ "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]
+ prop: "value"
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests.testOutput{
initialValue: &[]string{},
changeValue: nil,
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,37 @@
tests.testOutput{
initialValue: &[]string{
"value",
},
changeValue: &[]string{"value1"},
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 = [
- "value",
+ "value1",
]
}

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]
~ prop: "value" => "value1"
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "UPDATE"}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
tests.testOutput{
initialValue: &[]string{
"value",
},
changeValue: nil,
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 = [
- "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]
- prop: "value"
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "DELETE"}},
}
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,35 @@
tests.testOutput{
initialValue: nil, changeValue: &[]string{
"value",
},
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 = [
+ "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]
+ prop: "value"
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
tests.testOutput{
initialValue: &[]string{
"value",
},
changeValue: &[]string{},
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 = [
- "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]
- prop: "value"
Resources:
~ 1 to update
1 unchanged
`,
detailedDiff: map[string]interface{}{"prop": map[string]interface{}{"kind": "DELETE"}},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tests.testOutput{
initialValue: &[]string{},
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,18 @@
tests.testOutput{
initialValue: &[]string{
"value",
},
changeValue: &[]string{"value"},
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,15 @@
tests.testOutput{
initialValue: nil, changeValue: nil,
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
Loading