terraform-plugin-sdk
terraform-plugin-sdk copied to clipboard
ResourceData.Partial does not work for TypeSet of primtives
SDK version
v2.0.0 (although able to repro in 1.15.0 and 1.0.0)
Relevant provider source code
I used an update that sets d.Partial and schema with a TypeSet (nested or root) and then errors to reproduce:
package main
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
)
func main() {
plugin.Serve(&plugin.ServeOpts{ProviderFunc: Provider})
}
func Provider() *schema.Provider {
return &schema.Provider{
ResourcesMap: map[string]*schema.Resource{
"example_example": resourceServer(),
},
}
}
func resourceServer() *schema.Resource {
return &schema.Resource{
Create: func(d *schema.ResourceData, m interface{}) error {
d.SetId("123")
return nil
},
Read: func(d *schema.ResourceData, m interface{}) error {
return nil
},
Update: func(d *schema.ResourceData, m interface{}) error {
d.Partial(true)
return fmt.Errorf("something happened!")
},
Delete: func(d *schema.ResourceData, m interface{}) error {
return nil
},
Schema: map[string]*schema.Schema{
"number": {
Type: schema.TypeSet,
Optional: true,
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
},
},
}
}
Terraform Configuration Files
Apply a create:
resource "example_example" "test" {
number = [24]
}
Modify the number attribute:
resource "example_example" "test" {
number = [26]
}
When you apply you will get an error from the update, but the value is still written, even though d.Partial(true) was called.
Debug Output
Expected Behavior
State should still show number = [24]
Actual Behavior
State shows number = [26]
Steps to Reproduce
See above
References
Somewhat related to https://github.com/hashicorp/terraform-plugin-sdk/issues/476
I've only confirmed this with primitive type sets (where the hash will not match), its possible that when the hashing matches nested schema.Resource information may be unaffected as well.
Hello, do you have any update on this issue? Maybe there is some other option how to refresh state in code without ResourceData.Partial ?