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

nested Set does not detect updates to elements, only recreation #783

Open
khumps opened this issue Jul 14, 2021 · 2 comments
Open

nested Set does not detect updates to elements, only recreation #783

khumps opened this issue Jul 14, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@khumps
Copy link

khumps commented Jul 14, 2021

SDK version

github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0

Relevant provider source code

		Schema: map[string]*schema.Schema{
			"user": {
				Type: schema.TypeSet,
				Elem: resourceDoorUser(),
				Set: func(i interface{}) int {
					m := i.(map[string]interface{})
					token := m["token"].(string)
					return schema.HashString(token)
				},
				Required: true,
			},
		},
                 // resourceDoorUser() schema
		Schema: map[string]*schema.Schema{
			"token": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"first_name": {
				Type:     schema.TypeString,
				Required: true,
			},
			"last_name": {
				Type:     schema.TypeString,
				Required: true,
			},
			"credential": {
				Type:     schema.TypeSet,
				Elem:     resourceDoorCredential(),
				Optional: true,
			},
		},
                 // resourceDoorCredential() schema
		Schema: map[string]*schema.Schema{
			"token": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"profile_token": { // TODO this should support a set of profiles, not just a single one
				Type:     schema.TypeString,
				Required: true,
			},
			"pin": {
				Type:     schema.TypeString,
				Required: true,
			},
		}

Terraform Configuration Files

resource "axis_door_users" "test" {
  user {
	first_name = "Test"
	last_name = "User"
	credential {
	  profile_token = data.axis_door_profile.test.id //defined elsewhere
	  pin = "1234"
	}
  }

}

Debug Output

https://gist.github.com/khumps/20e7510f20089c677aa64c248f6c0dd8

Expected Behavior

If I change something about a user such as first/last name or profile_token or pin from credential it should show up in the plan as a change to the sub-block

Actual Behavior

A full deletion of the sub-block followed by a creation of an identical one with the changes

Steps to Reproduce

terraform apply followed by another terraform apply with a small change

@khumps khumps added the bug Something isn't working label Jul 14, 2021
@vadim-su
Copy link

I faced with same problem recently. What is temporary resolve do you use?

@BorisMikhailovski
Copy link

I have similiar problem with TypeSet, when trying to remove single member left in TypeSet, TF (SDK) fails to recognise last member removal

The current solution is to work with TypeList, yet there will be always chance that order will change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants