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

null not working as documented in 0.12 #22430

Closed
ljckennedy opened this issue Aug 12, 2019 · 2 comments
Closed

null not working as documented in 0.12 #22430

ljckennedy opened this issue Aug 12, 2019 · 2 comments
Labels

Comments

@ljckennedy
Copy link

Terraform Version

Terraform v0.12.6
+ provider.azuread v0.5.1
+ provider.azurerm v1.30.0
+ provider.helm v0.10.2
+ provider.kubernetes v1.8.1

Terraform Configuration Files

  network_profile {
    network_plugin = "${length(var.network_plugin) > 1 ? var.network_plugin : var.def_network_plugin }" 
    service_cidr = "${length(var.service_cidr) > 1 ? var.service_cidr : null }"
    dns_service_ip = "${length(var.dns_service_ip) > 1 ? var.dns_service_ip : null}"
    docker_bridge_cidr = "${length(var.docker_bridge_cidr) > 1 ? var.docker_bridge_cidr : null}"
  }

NB: network_plugin is set to kubenet which does not require the other variables to be set.

Debug Output

Crash Output

Error: Invalid function argument

on aks.tf line 61, in resource "azurerm_kubernetes_cluster" "aksqse":
61: service_cidr = "${length(var.service_cidr) > 1 ? var.service_cidr : null }"
|----------------
| var.service_cidr is null

Invalid value for "value" parameter: argument must not be null.

Expected Behavior

As the manual states:
a value that represents absence or omission. If you set an argument of a resource or module to null, Terraform behaves as though you had completely omitted it — it will use the argument's default value if it has one, or raise an error if the argument is mandatory. null is most useful in conditional expressions, so you can dynamically omit an argument if a condition isn't met.

Actual Behavior

Errors that the argument must not be null. This implies the value has been set as opposed to being unset.

Steps to Reproduce

Additional Context

occurs in azurerm_kubernetes_cluster however I do not think this is relevant.

References

@teamterraform
Copy link
Contributor

Hi @ljckennedy,

The error message here is complaining that var.service_cidr is null, not that the final service_cidr value is null. The length function does not accept null values for its argument, and so it's failing here.

Some other approaches here would include:

  • Making the default value of var.service_cidr be an empty string rather than null, so that length(var.service_cidr) will return zero when it isn't set.

  • Using coalesce to provide a default string value to use if var.service_cidr is null.

Because Terraform is working as designed here, we're going to close this out. If you have any further questions, please feel free to start a topic on the community forum!

@ghost
Copy link

ghost commented Sep 12, 2019

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 Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants