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

Removing overridden default value does not trigger diff #4501

Closed
yissachar opened this issue Jan 4, 2016 · 4 comments
Closed

Removing overridden default value does not trigger diff #4501

yissachar opened this issue Jan 4, 2016 · 4 comments

Comments

@yissachar
Copy link
Contributor

Let's say I have the following VPC definition:

resource "aws_vpc" "main" {
    cidr_block = "10.0.0.0/16"
    enable_dns_hostnames = true

    tags {
        Name = "main"
    }
}

I've set enable_dns_hostnames to true, overriding the default value of false. I apply the changes and go on my way. A little while later I decide that I don't want to enable DNS hostnames after all, so I remove that line, assuming that it will revert to the default of false. But when I run terraform plan it tells me that no changes were detected. In order to trigger a diff detection I have to explicitly set enable_dns_hostnames to false, which seems wrong.

@apparentlymart
Copy link
Contributor

The enable_dns_hostnames attribute is a member of a weird class of arguments that are both "Optional" and "Computed" at the same time.

In user-oriented terms, this means that the value is optional but if you don't specify it then its value isn't known until after the object has been created, since the default is defined by the remote API. Once a resource has been created, Terraform will just accept whatever value the server currently has unless you specifically override it.

The trick with this sort of attribute is that Terraform uses the presence or absense of the configuration as the trigger to decide whether you want to accept the server's default or override your own. When you removed the enable_dns_hostnames = true you effectively told Terraform "I don't care"; explicitly specifying false tells Terraform that you want to override the value the server has.

While I agree this is a little surprising, it is the intended behavior. It doesn't help that the Terraform docs don't really ever talk about this special Optional+Computed case; perhaps we could consider this a ticket to clarify this somehow in the documentation?

@yissachar
Copy link
Contributor Author

That explanation makes sense. Would definitely be nice to have this explained somewhere in the docs.

@mildwonkey
Copy link
Contributor

Since this is a very old issue, and the AWS provider documentation is in the aws provider repository, I am going to close this issue. If this is still a problem, please open a new issue with the aws provider. Thanks!

@ghost
Copy link

ghost commented Oct 13, 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 as resolved and limited conversation to collaborators Oct 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants