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

Potential bug with scalr_variable variable #270

Open
TNonet opened this issue Aug 16, 2023 · 4 comments
Open

Potential bug with scalr_variable variable #270

TNonet opened this issue Aug 16, 2023 · 4 comments

Comments

@TNonet
Copy link

TNonet commented Aug 16, 2023

If you create a scalr_variable with the following specifications:

resource "scalr_variable" "..." {
  key          = "FOO"
  value        = null
  category     = "terraform"
  workspace_id = var.workspace_id
}

The variable set in the workspace has a incorrect state

{
      "module": "...",
      "mode": "managed",
      "type": "scalr_variable",
      "name": "...",
      "provider": "provider[\"registry.scalr.io/scalr/scalr\"]",
      "instances": [
        {
          "schema_version": 3,
          "attributes": {
            "account_id": "...",
            "category": "terraform",
            "description": "",
            "environment_id": "...",
            "final": false,
            "force": false,
            "hcl": false,
            "id": "...",
            "key": "FOO",
            "sensitive": false,
            "value": "", <- THIS IS WRONG. Should be null
            "workspace_id": "...",
          },
   ....

I think this is a bug. Either:

  • it should yell at you for setting the value to null if it can't handle nulls and coerces null into ""
  • or it should actually set the value to null instead of "".
@emocharnik
Copy link
Contributor

Hi, @TNonet. Thanks for the report!
@DayS1eeper @petroprotsakh can you the root cause of the issue?

@TNonet
Copy link
Author

TNonet commented Aug 16, 2023

Thank you!

@petroprotsakh
Copy link
Member

Setting a null value here is equivalent to omitting the value attribute entirely from Terraform's perspective, as
it treats optional attributes as "unset" when a null value is passed.
That's true for the currently used legacy SDK: you can't tell zero values from unset in provider. Terraform Plugin Framework solves this, but the plans to migrate to it are still ephemeral.

@emocharnik
Copy link
Contributor

@TNonet can you tell us a use case? Also, do you consider an option to assign a default value to the variable in the source code? For example:

variable "foo" {
  default = null
}

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