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

Default is ignored in properties with a DiffSuppressFunc #70

Closed
renier opened this issue Oct 21, 2016 · 5 comments
Closed

Default is ignored in properties with a DiffSuppressFunc #70

renier opened this issue Oct 21, 2016 · 5 comments
Labels
bug Something isn't working

Comments

@renier
Copy link

renier commented Oct 21, 2016

Terraform Version

Terraform v0.7.7

Affected Resource(s)

Any resource with a property that has both a Default value and a DiffSuppressFunc

Example code

https://github.com/softlayer/terraform-provider-softlayer/blob/aa6f146/softlayer/resource_softlayer_virtual_guest.go#L197-L209

Description

If you have a property that has both a Default value and a DiffSuppressFunc, Terraform does not seem to use the Default value when generating the ResourceData for a new resource (no existing state yet).

Workaround: https://github.com/softlayer/terraform-provider-softlayer/blob/aa6f146/softlayer/resource_softlayer_virtual_guest.go#L310-L316

Expected Behavior

For Terraform to use the Default value for optional properties when there is no existing resource state yet.

@mitchellh
Copy link
Contributor

Kind of confusing but I believe this is working as intended as shown here: hashicorp/terraform@fa9758e

Well, working as "intended" may not be working as designed... so this may still be a bug. @catsby @stack72: what do you think here? Should diff suppression be ignored when the default value is used?

@marionettist
Copy link

This is still happening in terraform 0.11.10

Terraform itself handles this well, i.e. when a provider defines a resource which has an attribute foo with a default value and the diff function set, calling d.get("foo") in the provider correctly returns the default value when a resource does not specify the foo attribute.

However, the terraform provider acceptance test framework doesn't behave the same way: the default value for the attribute is ignored and the default value for the type is returned instead.
So I believe ti's a bug in the testing framework...

It would be great to get this fixed as it makes testing providers quite difficult in some cases.
I will have a look to see if I can identify where the change should be made and what it should be, but any pointers would be appreciated.

@marionettist
Copy link

marionettist commented Nov 5, 2018

Just wanted to add that, if my understanding of the work-around is correct, it will only work with types such as TypeString or TypeInt, i.e. types that can have at least 3 values: one for the type's default, one for an arbitrary attribute default that helps determine whether or not the user has specified a value for the attribute, and one for the actual value of the attribute as specified by the user.

It then means that the work-around does not actually work for attributes of type TypeBool.
So imho, this bug prevents providers with attributes of type TypeBool defining a default value and a suppress func to be succesfully acceptance tested.

@hashibot hashibot transferred this issue from hashicorp/terraform Sep 26, 2019
@hashibot hashibot added the bug Something isn't working label Oct 2, 2019
@bflad
Copy link
Contributor

bflad commented Mar 30, 2022

Hi folks 👋

A lot has changed with Terraform CLI and terraform-plugin-sdk between when this issue was raised and now. For example, there have been significant updates to the difference handling logic and the acceptance testing framework now uses real Terraform CLI commands and artifacts rather than re-implementing or emulating some of the previous Terraform core logic internally. State value checking should be wholly representative of an actual terraform apply.

If you are still running into problems in this area with recent versions of Terraform CLI and the SDK, my suggestion would be to open a new issue so we can take a fresh look. Thanks so much.

@bflad bflad closed this as completed Mar 30, 2022
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants