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

terraform apply command doesn't present diff between false and null #273

Closed
chkp-idoma opened this issue Dec 9, 2019 · 4 comments
Closed
Labels
enhancement New feature or request

Comments

@chkp-idoma
Copy link

Terraform Version

Terraform v0.12.13

Terraform Configuration Files

Custom Provider:

func resourceTest() *schema.Resource {
	return &schema.Resource{
		Create: createTest,
		Read:   readTest,
		Update: updateTest,
		Delete: deleteTest,

		Schema: map[string]*schema.Schema{
			"name": &schema.Schema{
				Type:     schema.TypeString,
				Required: true,
			},
			"enable": &schema.Schema{
				Type:     schema.TypeBool,
				Optional: true,
			},
		},
	}
}

func createTest(d *schema.ResourceData, m interface{}) error {

	d.SetId("1234")
	return readTest(d, m)
}

func readTest(d *schema.ResourceData, m interface{}) error{

	_ = d.Set("name", d.Get("name"))

	return nil
}

func updateTest(d *schema.ResourceData, m interface{}) error {

	if d.HasChange("enable") {

		log.Println("enable changed")
		_ = d.Set("enable", d.Get("enable"))
	}

	return readTest(d, m)
}

func deleteTest(d *schema.ResourceData, m interface{}) error {
	return nil
}

Configuration file (.tf) on first terraform apply:

resource "temp" "example" {
  name = "test1"
}

Configuration file (.tf) on second terraform apply:

resource "temp" "example" {
  name = "test1"
  enable = false
}

Expected Behavior

On the second run of terraform apply, diff should be presented:

Terraform will perform the following actions:
# temp.example will be updated in-place
 ~ resource "temp" "example" {
          name = "test1"
      + enable = false
    }

Actual Behavior

temp.example: Refreshing state... [id=1234]

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Steps to Reproduce

  1. build the custom provider with this single resource
  2. write .tf file with the resource as shown in "Configuration file (.tf) on first terraform apply:"
  3. terraform init
  4. terraform apply
  5. change the .tf file as shown in "Configuration file (.tf) on second terraform apply:"
  6. terraform apply

Additional Context

I'm trying to show here that when TypeBool argument isn't set at the first run of terraform apply,
and in the second run this boolean argument is set to false in the configuration file, no diff shown.
It means there is no difference between false and null values in the .tfstate file.

*if this issue isn't related to this section please tell me where to open it.

@jbardin jbardin transferred this issue from hashicorp/terraform Dec 9, 2019
@appilon
Copy link
Contributor

appilon commented Dec 11, 2019

Hello @chkp-idoma unfortunately this is a known limitation of the current SDK, you cannot distinguish between Go's zero value and "unset/null". With other types, such as TypeInt you can work around this by using a sentinel value, such as -1, but with TypeBool unfortunately there are no tricks. We will be addressing this in future major releases of the SDK.

Related issue: #173

@chkp-idoma
Copy link
Author

Hi @appilon ,

Thanks for answering!

Is there any time estimation for this fix to be released?

@radeksimko radeksimko added the enhancement New feature or request label Dec 12, 2019
@radeksimko
Copy link
Member

Hi folks,
I'm going to close this as a duplicate of #102 as I believe it covers the exact same problem with a bit more context on why (which Alex also mentioned).

@chkp-idoma We tend not to publish any release dates, but I can say that supporting 0.12 types is one of our current priorities. We are practically sure though that supporting these in the provider will require deprecation of <0.12 from provider's perspective as only 0.12 uses the new protocol that allows us to carry all the important details about types.

The best you can do in the meantime is to read this blogpost, share it and encourage everyone to upgrade to 0.12.

@ghost
Copy link

ghost commented Mar 29, 2020

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.

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants