-
Notifications
You must be signed in to change notification settings - Fork 113
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
consul_node resource doesn't inherit datacenter attribute from provider definition when defined #57
Comments
Hi @splashx , thanks for reporting the bug. In #56 you say that
? |
That is I think a reasonable acceptable behavior.
Yes - well I have not tested with other node types, but this is I think a general bug. |
I thought we had to do
Currently, it seems to me, that the behavior is 1 and 2 and never 3 but reading the documentation (https://github.com/terraform-providers/terraform-provider-consul/blame/master/website/docs/index.html.markdown#L57 and https://github.com/terraform-providers/terraform-provider-consul/blame/master/website/docs/r/keys.html.markdown#L40-L41) it should actually be:
Unless I'm missing something, this is not what is being done in https://github.com/terraform-providers/terraform-provider-consul/blob/master/consul/resource_consul_keys.go#L330-L340 From a quick glance at the code, most of the resources are using The documentation seems consistent that the order should be (resource, provider then agent): https://github.com/terraform-providers/terraform-provider-consul/blame/master/website/docs/r/catalog_entry.html.markdown#L48-L49, https://github.com/terraform-providers/terraform-provider-consul/blame/master/website/docs/r/key_prefix.html.markdown#L60-L61, etc. Only the documentation of The way I think changing the code to respect the documentation would be too much of a change and could surprise many people and that I could be better to change the documentation and the code so that first the datacenter defined in the resource is used, then the datacenter of the agent (current behavior) if possible then the one in the provider. This would change most parts of the documentation from:
to:
and would not be a breaking change. I will start working on a new PR for this change. |
Cool! I think that makes sense. Since we didnt have 1 defined and 3 never happened, it failed on 2 (the token did not have rights to list agents). From #56
🤞 |
…ched According to the current documentation, the datacenter attribute should default to the provider configuration and if it is not set to the datacenter of the agent terraform is connected to: * `datacenter` - (Optional) The datacenter to use. This overrides the datacenter in the provider setup and the agent's default datacenter. This is not what the code actually does and the datacenter in the provider configuration is not used most of the time. Since changing the plugin behavior to what is actually documented may break code relying on the current one. To keep backward compatibility, we can change the documentation to: * `datacenter` - (Optional) The datacenter to use. This overrides the agent's default datacenter and the datacenter in the provider setup. and fall back to the provider configuration only when the datacenter of the agent to which terraform is connected to can not be read (when ACL is enabled and the token used by terraform does not have permission to read /agent/self for example). The change is very noisy as it requires to change the `ConfigureFunc` of the provider from `(*consulapi.Client, error)` to `(*Config, error)` and update all places where was being used. I'm not sure how to write a test for this change as no other test requires ACL to be enabled. Discussion: hashicorp#57
Hi @splashx, I started to work on the issue. You can find the change here: https://github.com/remilapeyre/terraform-provider-consul/tree/datacenter-attribute-inheritance I checked the change with the following Consul (1.4.0) configuration:
this anonymous policy:
and the following terraform scenario:
Here, the result, first with the version 2.2.0 then with the version from the
As you can see, the 2.2.0 version was not able to get the datacenter from the agent but the other got it from the provider configuration. As I wrote in the commit, I'm not sure how to write tests for this change as it requires a specific configuration of Consul to trigger the bug. Could you confirm the new version fixed the issue you had? |
I just downloaded the latest provider version and have been bitten by this issue. :( |
Hi @ashald, I will merge the attached parch so this can be fixed in the next release. |
Thanks a lot! |
According to the current documentation, the datacenter attribute should default to the provider configuration and if it is not set to the datacenter of the agent terraform is connected to: * `datacenter` - (Optional) The datacenter to use. This overrides the datacenter in the provider setup and the agent's default datacenter. This is not what the code actually does and the datacenter in the provider configuration is not used most of the time. Since changing the plugin behavior to what is actually documented may break code relying on the current one. To keep backward compatibility, we can change the documentation to: * `datacenter` - (Optional) The datacenter to use. This overrides the agent's default datacenter and the datacenter in the provider setup. and fall back to the provider configuration only when the datacenter of the agent to which terraform is connected to can not be read (when ACL is enabled and the token used by terraform does not have permission to read /agent/self for example). The change is very noisy as it requires to change the `ConfigureFunc` of the provider from `(*consulapi.Client, error)` to `(*Config, error)` and update all places where was being used. Discussion: hashicorp#57
…105) According to the current documentation, the datacenter attribute should default to the provider configuration and if it is not set to the datacenter of the agent terraform is connected to: * `datacenter` - (Optional) The datacenter to use. This overrides the datacenter in the provider setup and the agent's default datacenter. This is not what the code actually does and the datacenter in the provider configuration is not used most of the time. Since changing the plugin behavior to what is actually documented may break code relying on the current one. To keep backward compatibility, we can change the documentation to: * `datacenter` - (Optional) The datacenter to use. This overrides the agent's default datacenter and the datacenter in the provider setup. and fall back to the provider configuration only when the datacenter of the agent to which terraform is connected to can not be read (when ACL is enabled and the token used by terraform does not have permission to read /agent/self for example). The change is very noisy as it requires to change the `ConfigureFunc` of the provider from `(*consulapi.Client, error)` to `(*Config, error)` and update all places where was being used. Discussion: #57
Hi, the fix for this issue has been released in the 2.4.0 version so this should work as expected now :) |
Terraform Version
Refer to #56
Affected Resource(s)
Refer to #56
Terraform Configuration Files
Refer to #56
Expected Behavior
Refer to #56
Actual Behavior
Refer to #56
Steps to Reproduce
Refer to #56
Important Factoids
Refer to #56
References
Refer to #56
The text was updated successfully, but these errors were encountered: