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

[Bug]: [hcloud_ssh_key] Error: Provider produced inconsistent result after apply #921

Closed
trombonax opened this issue Apr 30, 2024 · 2 comments · Fixed by #922 or #920
Closed

[Bug]: [hcloud_ssh_key] Error: Provider produced inconsistent result after apply #921

trombonax opened this issue Apr 30, 2024 · 2 comments · Fixed by #922 or #920
Assignees
Labels

Comments

@trombonax
Copy link

What happened?

opentofu-1.6.2

terraform-1.8.2

provider[registry.terraform.io/hetznercloud/hcloud] = 1.46.1

provider[registry.opentofu.org/hetznercloud/hcloud] = 1.46.1

~$ tofu / terraform apply
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to module.ssh_key["key01"].hcloud_ssh_key.this, provider "provider[\"registry.terraform.io/hetznercloud/hcloud\"]" produced an unexpected new value: .labels: was cty.MapValEmpty(cty.String), but now
│ null.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to module.ssh_key["key02"].hcloud_ssh_key.this, provider "provider[\"registry.terraform.io/hetznercloud/hcloud\"]" produced an unexpected new value: .labels: was cty.MapValEmpty(cty.String), but now null.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

What did you expect to happen?

simply ssh key add as resource via module

Please provide a minimal working example

module "hcloud-ssh-key":

# -- main

resource "hcloud_ssh_key" "this" {

  lifecycle {
    ignore_changes        = [fingerprint] # TODO: bug
    create_before_destroy = false
  }

  name       = var.key_name
  public_key = var.key
  labels     = try(var.labels, null)
}

# -- vars

variable "key_name" {
  description = "Hetzner Cloud SSH key name"
  type        = string
  default     = ""
}

variable "key" {
  description = "Hetzner Cloud SSH key content"
  type        = string
  default     = ""
  sensitive   = true
}

variable "labels" {
  description = "Hetzner Cloud ssh key user-defined labels"
  type        = map(any)
  default     = {}
}

module call from manifest:

module "ssh_key" {

  for_each = var.ssh_key

  source = "../terraform-modules/hcloud-ssh-key"

  key_name = each.value.name
  key      = each.value.key
}

variable "ssh_key" {
  description = "Hetzner Cloud SSH keys"
  type        = map(any)
  default = {
    "key01" = {
      name = "key01"
      key  = "ssh-ed25519 <key01>"
    },
    "key02" = {
      name = "key02"
      key  = "ssh-ed25519 <key02>"
    }
  }
}
@trombonax trombonax added the bug label Apr 30, 2024
@apricote
Copy link
Member

apricote commented May 2, 2024

Hey @trombonax,

thank you very much for reporting this issue! This was recently refactored in #855, #881 and #817 and we did not catch this with our test suite.

The issue happens once you assign an empty map to labels: labels = {} which happens in your code in try(var.labels, null), as var.labels is set to {} by default.

We are working on a fix and an extended test suite to make sure this does not get reintroduced. Until that is released you can fix your issue, but using null instead of {} as the default for your labels. I think you can even remove the try().

@apricote apricote self-assigned this May 2, 2024
apricote added a commit that referenced this issue May 2, 2024
When we implemented the Label helper we added some extra logic that
handled the difference between the `label` attribute default (null) and
the Hetzner Cloud API default (`{}`). This worked well in our test
cases, but breaks if you pass an empty object to the attribute:

    When applying changes to hcloud_ssh_key.this, provider
    "provider[\"registry.terraform.io/hetznercloud/hcloud\"]" produced
    an unexpected new value: .labels: was cty.MapValEmpty(cty.String),
    but now null.

We have now fixed this by setting the default of the labels field to
an empty object to match the return value of the API. With this, we no
longer need the workaround to handle null labels in Terraform config.

Fixes #921
apricote added a commit that referenced this issue May 2, 2024
When we implemented the Label helper we added some extra logic that
handled the difference between the `label` attribute default (null) and
the Hetzner Cloud API default (`{}`). This worked well in our test
cases, but breaks if you pass an empty object to the attribute:

    When applying changes to hcloud_ssh_key.this, provider
    "provider[\"registry.terraform.io/hetznercloud/hcloud\"]" produced
    an unexpected new value: .labels: was cty.MapValEmpty(cty.String),
    but now null.

We have now fixed this by setting the default of the labels field to
an empty object to match the return value of the API. With this, we no
longer need the workaround to handle null labels in Terraform config.

Fixes #921
apricote added a commit that referenced this issue May 2, 2024
When we implemented the Label helper we added some extra logic that
handled the difference between the `label` attribute default (null) and
the Hetzner Cloud API default (`{}`). This worked well in our test
cases, but breaks if you pass an empty object to the attribute:

```
When applying changes to hcloud_ssh_key.this, provider
"provider[\"registry.terraform.io/hetznercloud/hcloud\"]" produced an
unexpected new value: .labels: was cty.MapValEmpty(cty.String), but now
null.
```

We have now fixed this by setting the default of the labels field to an
empty object to match the return value of the API. With this, we no
longer need the workaround to handle null labels in Terraform config.

Fixes #921
apricote pushed a commit that referenced this issue May 3, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.47.0](v1.46.1...v1.47.0)
(2024-05-02)


### Features

* test with Terraform 1.8
([#919](#919))
([800a66c](800a66c))


### Bug Fixes

* **ssh-key:** data inconsistency with empty label objects
([#922](#922))
([7e1bf2c](7e1bf2c)),
closes
[#921](#921)
* **subnet:** handle new error message for deleting subnets with
attached resources
([#923](#923))
([932c47b](932c47b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
@trombonax
Copy link
Author

@apricote
hello
with provider 1.47.0 is all fine, I'm doesn't see reported issue anymore
thank you !

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