hetznercloud / terraform-provider-hcloud

Terraform Hetzner Cloud provider
https://registry.terraform.io/providers/hetznercloud/hcloud/latest
Mozilla Public License 2.0
495 stars 72 forks source link

fix(ssh-key): data inconsistency with empty label objects #922

Closed apricote closed 5 months ago

apricote commented 5 months ago

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 commented 5 months ago

We have manually tested the various combinations for empty label attributes:

We plan to add some more detailed tests in the coming weeks, but wanted to get this fix out immediately.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 69.76%. Comparing base (800a66c) to head (f7991a3).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #922 +/- ## ======================================= Coverage 69.76% 69.76% ======================================= Files 63 63 Lines 7938 7938 ======================================= Hits 5538 5538 Misses 1701 1701 Partials 699 699 ``` | [Flag](https://app.codecov.io/gh/hetznercloud/terraform-provider-hcloud/pull/922/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hetznercloud) | Coverage Δ | | |---|---|---| | [e2e](https://app.codecov.io/gh/hetznercloud/terraform-provider-hcloud/pull/922/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hetznercloud) | `69.76% <100.00%> (ø)` | | | [unit](https://app.codecov.io/gh/hetznercloud/terraform-provider-hcloud/pull/922/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hetznercloud) | `34.22% <100.00%> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=hetznercloud#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.