Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceData.Partial does not work for TypeSet of primtives #525

Open
paultyng opened this issue Aug 7, 2020 · 2 comments
Open

ResourceData.Partial does not work for TypeSet of primtives #525

paultyng opened this issue Aug 7, 2020 · 2 comments
Labels
bug Something isn't working subsystem/types Issues and feature requests related to the type system of Terraform and our shims around it.

Comments

@paultyng
Copy link
Contributor

paultyng commented Aug 7, 2020

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 #476

@paultyng paultyng added the bug Something isn't working label Aug 7, 2020
@paultyng
Copy link
Contributor Author

paultyng commented Aug 7, 2020

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.

@paultyng paultyng changed the title ResourceData.Partial does not work for TypeSet ResourceData.Partial does not work for TypeSet of primtives Aug 7, 2020
@paddycarver paddycarver added the subsystem/types Issues and feature requests related to the type system of Terraform and our shims around it. label Jan 6, 2021
@Slonimskaia
Copy link

Hello, do you have any update on this issue? Maybe there is some other option how to refresh state in code without ResourceData.Partial ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working subsystem/types Issues and feature requests related to the type system of Terraform and our shims around it.
Projects
None yet
Development

No branches or pull requests

3 participants