-
Notifications
You must be signed in to change notification settings - Fork 26
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
Should not try to parse empty strings #66
Comments
@athak You have to pass the variables to the inputs of the module, but I see the vars being interpolated directly into the underlying resources instead. can you show all the tf files including the module? |
@renier thanks for the prompt reply. The module in this case is being called without those arguments since they are optional:
So the defaults kick in which are the empty strings. |
I see what you mean now. I don't know how to get around this currently without removing the vars you don't intend to use. Don't think this is an actual issue with the provider. Just how you setup the vars to drive the module. |
I just made a quick experiment using the old softlayer_virtual_guest resource included in terraform, adjusting the argument names:
Same module call, default empty strings. No errors. |
I see in the source code of the old softlayer_virtual_guest resource that block_device_template_group_gid, backend_vlan_id and frontend_vlan_id are defined as TypeString and then parsed to int. Maybe that's the workaround? |
This appears to be a related issue: hashicorp/terraform#6254 If converting the arguments to TypeString is not possible, how about using a special value like -1 to be interpreted as nil? There seems currently to be no way to pass integers to modules. |
Ok, so setting the default for public_vlan_id and private_vlan_id to -1 seems to work with the current code, since it checks for values > 0. The instance is correctly created. However, the terraform plan shows:
The terraform.tfstate does have the assigned vlan numbers though. So we can go with this for now for VLAN ids but it feels a bit dirty for the planning phase. The conflict between image_id with default empty string and os_reference code remains. |
@athak that is a problem in terraform when you mark a fields conflicting with each other. It looks up the values and that's how it deals with explicit empty strings when the type is TypeInt. You should look at creating a module that uses images and another that uses os reference codes. |
@renier I understand the current limitations in terraform and the fact that we still have to go through a lot of workarounds to achieve certain goals due to lack of certain features. I go through that pain every day. However, maintaining an almost exact duplicate copy of a module because of this kind of shortcoming is not a realistic solution. Sometimes certain improvements/workarounds can be made to accommodate shortcomings in the underlying framework. |
@athak open to looking at a PR showing your idea on solving this at the provider level. However, a PR up to Terraform would be more appropriate. |
@renier unfortunately my knowledge in Go is not up to par for this. Anyway, thanks for your help. |
@athak do you have an idea though on what the provider could do in this case? The conflict resolution is managed above the provider plugin, so I can't immediately think of a solution, unless we lift that conflict relationship. You can tinker around and try it. We would have to manage the potential conflict locally in the provider. Assuming that would help you. |
DiffSuppressFunc can be added to |
DiffSuppressFunc is not without its problems. |
private_vlan_id and public_vlan_id don't have to have a default value. The following DiffSuppressFunc ignores difference when private_vlan_id = 0 or public_vlan_id = 0
|
I came across a comment by @mitchellh in this issue which basically is about the same functionalluty. He states that
hoping to provide a way in the future to unset a value. Is this something that can be implemented? Our current pain points are with image_id, {public,private}_vlan_id. Allowing the use of 0 or other value as "unset" would greatly simplify our current code. |
@athak Have you tried setting those defaults to 0?
|
@renier yes, in the case of image_id it conflicts with os_reference_code. In the case of the vlan ids, 0 is initially accepted as a value and the instance is created and a correct vlan id is assigned. However, once the instance is created, issuing a plan produces the following for example:
|
We are trying to encapsulate some functionality in a custom module, trying to expose as many arguments from the underlying resources as possible through the module. One of the resources used inside the module is softlayer_virtual_guest. So for example the module has these variables declared among others:
And then passed to the resource:
The problem is that if no value is passed to the module, it still tries to interpret/parse the empty strings resulting in:
The first two are the public and private_vlan_id arguments. Commenting those in the resource makes the errors go away.
Given that these are optional arguments, empty strings should be interpreted as nil. This is with terraform 0.7.13 and latest provider release, 1.3.0.
Thanks for the awesome work!
Cheers,
Atha
The text was updated successfully, but these errors were encountered: