-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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 0.12.1 trates "null" as literal value instead of using default variable #21702
Comments
Hi @bohdanyurov-gl! Sorry for this inconsistency, and thanks for reporting it. The key subtlety which that text is implying but not explicitly stating is that In particular, the presence of I assume your goal here was for We'll use this issue to represent finding a way to be more explicit about this requirement in the documentation. Thanks again for reporting this! |
I'm having a similar issue, but I think I'm using a
# main.tf
variable "env" {
default = "dev"
type = "string"
}
module "rds" {
source = "./modules/rds"
instance_class = var.env == "prod" ? "db.m5.large" : null
} # modules/rds/main.tf
variable "instance_class" {
default = "db.t2.small"
type = string
}
resource "aws_db_instance" "main" {
instance_class = var.instance_class
}
So in this case, it looks like Terraform is taking the Is this expected behavior? EDIT: my intent here is to say, "if this is production, use a larger instance, otherwise, whatever default the module provides is fine" |
I encountered something that might be related: I have this a Google Cloud SQL instance that may be either zonal or regional based on a resource "google_sql_database_instance" "sql_instance" {
# …
settings {
# …
location_preference {
zone = var.is_regional ? null : var.cluster_location
}
}
} When The resource was automatically assigned the zone ~ location_preference {
- zone = "europe-west1-d" -> null
} I don't know how to best handle this case. The best outcome for me would be to remove the whole block if |
We are seeing the same behavior on vSphere as @theneva is reporting Terraform keeps thinking the resource has changed from the sane defaults ` Small sample of the attributes affected, above. Edit: Turns out that this was all linked to a null value (like above) being passed to Organization Name and Full_Name (this appears to be new behavior in TF 0.12 but I will confirm) which caused the resource to be destroyed and recreated. Setting those variables instead of defaults resolved the issue.
|
yup, experiencing similar behaviour while trying to use module defaults. Any suggestions to this 🤷♂ ? (tf v0.12.9) |
@theneva I believe you could use |
Clever! I'm currently checking out Pulumi (because of this class of problems, and support for Kubernetes custom resource definitions), but might give it a shot if we decide to stick with Terraform 😄 |
Hi @apparentlymart, I think this issue should still be labelled as "bug" and not "documentation" as this is happening on regular arguments as shown in @bohdanyurov-gl Example#test.tf
module instance {
source = "./instance"
foo = null
} #instance/variables.tf
variable foo {
default = "bar"
} #instance/main.tf
resource "null_resource" instance_foo {
provisioner "local-exec" {
command = "echo ${var.foo}"
}
} gives the following error after module.instance.null_resource.instance_foo: Creating... Error: Invalid template interpolation value: The expression result is null. Cannot include a null value in a string template. |
I can reproduce this with the use case in the comment immediately above mine. I'm working around it with variable "image" {
type = string
// when this issue is resolved, set this to the actual default image we want
// https://github.com/hashicorp/terraform/issues/21702
default = ""
} And then inline in the module definition image = coalesce(var.image, "ubuntu/bionic") or whatever default value you want to actually use. |
reproduced with Terraform v0.12.20 |
I'm having issues where terraform is not omitting property when "null" returned from lookup() like this: |
reproduced with Terraform v0.12.21 |
Is there a fix / workaround ? |
When running terraform plan on version0.12.23,i am facing following issue,default value is being replaced with null. This was working fine in terraform0.11.11 New |
@jbardin, @bohdanyurov-gl , @apparentlymart - could we set it back to "bug" as described above |
i see the same behavior on 0.12.24 :
return with all three variables defaulted to and same behavior if the assignment is direct
with values defaulted to |
On 0.12.25, expanding a bit on @scodeman 's response. I'm trying to use this to safely wrap a base module with a few differences. A minimal example:
This also happens for required resources, such as the aws_ami data resource. (i.e. This seems to be what |
This is still broken on 0.13.2 |
This is still broken on 0.13.3 |
Is this solved by |
I dont think so. That's a different feature for a different purpose. |
Still broken in v0.13.5 |
Still an issue in 0.14.5. |
When null is passed to a submodule, Terraform uses this value (null) instead of submodule's default. hashicorp/terraform#21702
This is also more of an issue with the support for optional variables where those variables are set to |
This is still an issue in 0.14.10, and I don't see any notes about it in any of the 0.15 RC builds so safe to assume it will still be an issue there too. |
Still an issue in 0.15.0. |
I think the trick around this problem with null is doing something like this with a mix of thing in your local to do part of the conditional operator that deal with the var that can be null.
|
@mark-hubers That would only be a workaround if you wanted to maintain a different block for every possible combination of variables that could be null or not. This issue is about being able to nullify individual input variables and have them use their defaults. |
Re |
The issue is reported for 2 years, and now we heard "it's too late for 1.0", this is so frustrating. 1.0 is exactly where we would expect to see such a silly mistake fixed, but it seems no thorough review of all open issues that would be a breaking change was performed. let's hope this is fixed in the next 2 years for TF 2.0 |
Since the initial exchange here was around confusion about For those who want to follow the issue about the behavior of Thanks! |
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. |
Terraform Version
Terraform Configuration Files
Debug Output
Crash Output
Expected Behavior
Default value is used
Actual Behavior
Steps to Reproduce
Additional Context
References
https://www.terraform.io/docs/configuration/expressions.html
The text was updated successfully, but these errors were encountered: