Scalr / terraform-provider-scalr

Terraform Provider to manage Scalr TACO
Mozilla Public License 2.0
19 stars 11 forks source link

Potential bug with scalr_variable variable #270

Open TNonet opened 1 year ago

TNonet commented 1 year ago

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:

emocharnik commented 1 year ago

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

TNonet commented 1 year ago

Thank you!

petroprotsakh commented 1 year ago

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 commented 1 year ago

@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
}