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

Cannot create a consul key/value with an actual empty string #165

Closed
rnsc opened this issue Dec 4, 2019 · 5 comments
Closed

Cannot create a consul key/value with an actual empty string #165

rnsc opened this issue Dec 4, 2019 · 5 comments

Comments

@rnsc
Copy link

rnsc commented Dec 4, 2019

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

Terraform v0.12.13
+ provider.azurerm v1.37.0
+ provider.consul v2.6.0
+ provider.null v2.1.2
+ provider.random v2.2.1
+ provider.tls v2.1.1
+ provider.vault v2.6.0

Your version of Terraform is out of date! The latest version
is 0.12.17. You can update by downloading from www.terraform.io/downloads.html

Affected Resource(s)

  • consul_keys

Terraform Configuration Files

resource "consul_keys" "consul" {
  key {
    path  = "my_value"
    value = ""
    delete =  true
  }
}

The above script is an extract of my Terraform module.
I have multiple other values that are set just fine (those values are not empty).
However, for a specific set of values, it happens that the value can be just empty.
Our tools expect that key to exist after the Terraform deployment, even if it's empty.

Expected Behavior

I was assuming that the key would be created in my KV with an empty string value.

Actual Behavior

The key is not even created as Terraform considers the empty string to be null.

Steps to Reproduce

  1. Just create an empty key/value pair in a Consul KV with Terraform.
remilapeyre pushed a commit to remilapeyre/terraform-provider-consul that referenced this issue Dec 4, 2019
@remilapeyre
Copy link
Collaborator

Thanks @rnsc, this is a bug that dates from the time when consul_keys could be used as a datasource. A name attribute and an empty value meant that the key should not be created but its value read from the KV store.

Apparently the case where a key with an empty value needed to be created had not been considered, #166 should fix this.

@rnsc
Copy link
Author

rnsc commented Dec 5, 2019

@remilapeyre , thanks for the quick response.
Was wondering though, how fast will this provider be released with a new version fixing this?

@remilapeyre
Copy link
Collaborator

I'm working on fixing #160 and hope to make a release after that.

@lachlancooper
Copy link

Thanks for the fix! Just wanted to note that I'm still seeing an issue with empty string values in provider version 2.6.1.

While the keys are created as expected and all works well if there are no other changes to apply, any keys with empty strings show up in the plan output if there are changes to apply to different keys in the same resource. For example:

- key {
    - delete = true -> null
    - flags  = 0 -> null
    - path   = "configuration/global/env_vars/TO_BE_DELETED" -> null
    - value  = "foobar" -> null
  }
...
- key {
    - delete = true -> null
    - flags  = 0 -> null
    - path   = "configuration/global/env_vars/UNCHANGED_EMPTY_STRING" -> null
  }
+ key {
    + delete = true
    + flags  = 0
    + path   = "configuration/global/env_vars/UNCHANGED_EMPTY_STRING"
    + value  = (known after apply)
  }

I'm able to reproduce this consistently. Let me know if there's any further information I can provide.

@remilapeyre
Copy link
Collaborator

I can reproduce this too, this is because the value attribute is marked as Computed so Terraform get confused, as it's unset it expect to read a new value for it from the server. I don't think we can improve that without removing the possibility to read keys using the consul_keys, which is deprecated but still work.

In my test, the end result was correct and configuration/global/env_vars/UNCHANGED_EMPTY_STRING would not appear in the plan unless another key was changed. If the behaviour is the same on your end I'm afraid we will have to keep it that until the next major release of the provider, the plan is a bit too much noisy but it's a compromise with our backward compatibility requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants