mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 08:51:02 -06:00
test that computed maps are applied correctly
Verify that a computed map which is not correctly marked as unknown in the plan is still applied correctly.
This commit is contained in:
parent
3d46c04e28
commit
0f883b118a
@ -23,6 +23,16 @@ func testResourceMap() *schema.Resource {
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
"map_values": {
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
"computed_map": {
|
||||
Type: schema.TypeMap,
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -35,15 +45,20 @@ func testResourceMapCreate(d *schema.ResourceData, meta interface{}) error {
|
||||
}
|
||||
|
||||
d.SetId("testId")
|
||||
return nil
|
||||
return testResourceMapRead(d, meta)
|
||||
}
|
||||
|
||||
func testResourceMapRead(d *schema.ResourceData, meta interface{}) error {
|
||||
var computedMap map[string]interface{}
|
||||
if v, ok := d.GetOk("map_values"); ok {
|
||||
computedMap = v.(map[string]interface{})
|
||||
}
|
||||
d.Set("computed_map", computedMap)
|
||||
return nil
|
||||
}
|
||||
|
||||
func testResourceMapUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
return nil
|
||||
return testResourceMapRead(d, meta)
|
||||
}
|
||||
|
||||
func testResourceMapDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
|
@ -30,3 +30,80 @@ resource "test_resource_map" "foobar" {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestResourceMap_computedMap(t *testing.T) {
|
||||
resource.UnitTest(t, resource.TestCase{
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckResourceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: `
|
||||
resource "test_resource_map" "foobar" {
|
||||
name = "test"
|
||||
map_of_three = {
|
||||
one = "one"
|
||||
two = "two"
|
||||
empty = ""
|
||||
}
|
||||
map_values = {
|
||||
a = "1"
|
||||
b = "2"
|
||||
}
|
||||
}`,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
"test_resource_map.foobar", "computed_map.a", "1",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"test_resource_map.foobar", "computed_map.b", "2",
|
||||
),
|
||||
),
|
||||
},
|
||||
{
|
||||
Config: `
|
||||
resource "test_resource_map" "foobar" {
|
||||
name = "test"
|
||||
map_of_three = {
|
||||
one = "one"
|
||||
two = "two"
|
||||
empty = ""
|
||||
}
|
||||
map_values = {
|
||||
a = "3"
|
||||
b = "4"
|
||||
}
|
||||
}`,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
"test_resource_map.foobar", "computed_map.a", "3",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"test_resource_map.foobar", "computed_map.b", "4",
|
||||
),
|
||||
),
|
||||
},
|
||||
{
|
||||
Config: `
|
||||
resource "test_resource_map" "foobar" {
|
||||
name = "test"
|
||||
map_of_three = {
|
||||
one = "one"
|
||||
two = "two"
|
||||
empty = ""
|
||||
}
|
||||
map_values = {
|
||||
a = "3"
|
||||
}
|
||||
}`,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr(
|
||||
"test_resource_map.foobar", "computed_map.a", "3",
|
||||
),
|
||||
resource.TestCheckNoResourceAttr(
|
||||
"test_resource_map.foobar", "computed_map.b",
|
||||
),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user