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]: Since upgrading to terraform 1.4.x, the provider keeps trying to remove and re-assign private networks #650

Open
ttaghavi opened this issue Apr 4, 2023 · 11 comments
Assignees
Labels
bug pinned requires: plugin-framework The issue can be fixed after the resource has be migrated to the plugin framework.

Comments

@ttaghavi
Copy link

ttaghavi commented Apr 4, 2023

What happened?

After upgrading from terraform 1.3.9 to 1.4.x, I see following behavior.

NOTE: Am using the latest version for terraform-provider-hcloud.

provider "registry.terraform.io/hetznercloud/hcloud" {
  version     = "1.37.0"
  constraints = "~> 1.37.0"

Network resources

resource "hcloud_network" "cluster_network_eu_central" {
  name     = "cluster-network-eu-central"
  ip_range = "10.0.0.0/16"

  delete_protection = false
}                                                                                                                      
                                                                                                                                                                                                                                              
resource "hcloud_network_subnet" "cluster_subnet_eu_central" {
  type         = "cloud"
  network_id   = hcloud_network.cluster_network_eu_central.id
  network_zone = "eu-central"
  ip_range     = "10.0.1.0/24"
}

The hcloud_server resource then uses this network via:

  network {
    network_id = hcloud_network.cluster_network_eu_central.id
  }

On a first run, everything is created correctly.

On subsequent runs (without changing any terraform files), I get:

 ~ resource "hcloud_server" "node" {
        id                         = "<server_id>"
        name                       = "server-fsn1-cpx11-1"
        # (18 unchanged attributes hidden)

      - network {
          - alias_ips   = [] -> null
          - ip          = "10.0.1.6" -> null
          - mac_address = "<mac_address> -> null
          - network_id  = <network_id> -> null
        }
      + network {
          + alias_ips   = (known after apply)
          + ip          = (known after apply)
          + mac_address = (known after apply)
          + network_id  = <network_id>
        }

        # (1 unchanged block hidden)
    }

Applying this plan detaches the private ip from the servers and re-attaches them. Further runs behave exactly the same.

Reverting back to 1.3.9 correctly shows:

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

What did you expect to happen?

Same output as 1.3.9.

Please provide a minimal working example

See What ahappened? field.

@ttaghavi ttaghavi added the bug label Apr 4, 2023
@ttaghavi ttaghavi changed the title [Bug]: Since upgrading to terraform 1.4.x, the provider keeps trying remove and re-assign private networks [Bug]: Since upgrading to terraform 1.4.x, the provider keeps trying to remove and re-assign private networks Apr 4, 2023
@apricote apricote self-assigned this Apr 5, 2023
@apricote
Copy link
Member

apricote commented Apr 5, 2023

I can confirm that this also happens for me.

Unfortunately we have some holidays coming up in Germany, so I don't think I will be able to take a deeper look at this until next week. Please continue to use Terraform v1.3 for now.

@apricote
Copy link
Member

apricote commented Apr 5, 2023

I was able to supress the diff by adding alias_ips = [] to the network block. I think this is a new bug in Terraform. Will continue to investigate in the coming weeks.

resource "hcloud_server" "node" {
  name        = "gh-650"
  location    = "hel1"
  server_type = "cx11"
  image       = "ubuntu-22.04"

  network {
    network_id = hcloud_network.cluster_network_eu_central.id
+   alias_ips = []
  }
}

@ttaghavi
Copy link
Author

Thanks for the feedback @apricote

I can confirm that setting alias_ips = [] suppresses the diff.

@apricote
Copy link
Member

I think this regression was willfully added to Terraform v1.4 in hashicorp/terraform#32536 :

While it may be safer to leave the questionable set block behavior as-is to avoid possible regressions with legacy providers, the framework has added full support for nested blocks, which means that new providers now have access to the complete values and are no longer limited by the behaviors of the legacy SDK. A number of tests cases for nested set blocks were added here, which do fail without the accompanying changes.

This is unfortunately a large refactoring that is expected of us here. As far as I can tell this should affectshcloud_server.network.alias_ips and hcloud_firewall.rule.{source,destination}_ips, but I can only reproduce it for the server resource and dont understand why. I will have another look at this tomorrow.

@spoletum
Copy link

spoletum commented May 2, 2023

The same applies to public networks, issue and resolution.

@furstenbergs
Copy link

furstenbergs commented Jul 12, 2023

I'm currently using version 1.41.0 of the hcloud provider and Terraform 1.5.2.

I'm assigning an alias IP to my resource, for example;

  network {
    network_id = hcloud_network.private.id
    ip         = "10.100.0.2"
    alias_ips  = [
      "10.100.127.10"
    ]
  }

The alias IP is assigned successfully, but on subsequent run, it's removing the alias IP without any code change.

# hcloud_server_network.server will be updated in-place
  ~ resource "hcloud_server_network" "server-network-az1" {
      ~ alias_ips   = [
          - "10.100.127.10",
        ]
        id          = "34780594-3110924"
        # (4 unchanged attributes hidden)
    }

And on the next run it add the alias IP back again, etc. I've tried different versions of Terraform, including 1.3.8, 1,4,1 but the issue remains. Also tried with older versions of the hcloud provider with no luck.

@apricote
Copy link
Member

@furstenbergs If this still happens in Terraform 1.3, please open a new issue as its unrelated to this issue. Could you also post a full terraform configuration for reproduction?

@asteinba
Copy link

Hey @apricote,

just ran into this and searched a while for the solution. The alias_ips= [] workaround works well. Is there a update about that issue? Anything we can do to support you with this issue :)?

@apricote
Copy link
Member

Hey @asteinba,

sorry for not updating this issue. As far as I could find out, updating the the "new" Plugin Framework is the only way to get this fixed.
We had our first refactoring session this week (#749), and we plan an making slow but steady progress on this. In any way, the hcloud_server resource is by far the most complicated resource we have, and we will probably tackle this one last.

This comment was marked as off-topic.

@github-actions github-actions bot added the stale label Dec 14, 2023
@apricote apricote added pinned and removed stale labels Dec 14, 2023
mrclrchtr added a commit to hcloud-talos/terraform-hcloud-talos that referenced this issue Jun 3, 2024
jdelic added a commit to jdelic/saltshaker that referenced this issue Sep 13, 2024
@jooola jooola added the requires: plugin-framework The issue can be fixed after the resource has be migrated to the plugin framework. label Dec 13, 2024
@shinebayar-g
Copy link

This is still happening in the latest provider version 1.49.1 and terraform version 1.10.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug pinned requires: plugin-framework The issue can be fixed after the resource has be migrated to the plugin framework.
Projects
None yet
Development

No branches or pull requests

7 participants