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

Wrong setting for cloudapiv6 k8s-lans-dhcp after terraform apply. #25

Closed
dreamblack86 opened this issue Jun 17, 2021 · 5 comments · Fixed by #38
Closed

Wrong setting for cloudapiv6 k8s-lans-dhcp after terraform apply. #25

dreamblack86 opened this issue Jun 17, 2021 · 5 comments · Fixed by #38
Assignees
Labels
bug Something isn't working

Comments

@dreamblack86
Copy link
Contributor

Description

We use the new feature of static routes for our Kubernetes clusters. This feature was added in the IONOS Cloud API v6. The problem now is that we urgently want to disable "dhcp". Do I set this directly in the Cloud API v6 via an HTTPS request. Is that also taken over correctly. However, the Terraform provider does not do this.

Expected behavior

The expected behavior would be that if I set dhcp = false in the "lans" property in the object in the K8s node pool, but the IONOS cloud maintains this value at "true". As a result, our "internal" network is not reachable.

Environment

Terraform version:

0.14.3

Provider version:

6.0.0-alpha.2

OS:

NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"

How to Reproduce

This can be easily reproduced by using the new Terraform Provider with v6 support and setting the resource ionoscloud_k8s_node_pool to false for the LANs DHCP. After a Terraform apply this value will not be applied to the IONOS cloud.

resource "ionoscloud_k8s_node_pool" "np0" {
  availability_zone = "ZONE_1"
  cores_count       = 8
  cpu_family        = "INTEL_SKYLAKE"
  datacenter_id     = ionoscloud_datacenter.dc.id
  k8s_cluster_id    = ionoscloud_k8s_cluster.ncc.id
  k8s_version       = "1.20.6"
  lans {
    id   = ionoscloud_lan.internal.id
    dhcp = false

Error and Debug Output

Statefile:

            "k8s_version": "1.20.6",
            "lans": [
              {
                "dhcp": true,
                "id": 1

Additional Notes

That issue on the ionos-cloud/sdk-go looks a lot like the cause to me:
ionos-cloud/sdk-go#5

@dreamblack86 dreamblack86 added the bug Something isn't working label Jun 17, 2021
@mflorin
Copy link
Contributor

mflorin commented Jun 17, 2021

Hello @dreamblack86 ,

The problem is actually with terraform's implementation of GetOk() for boolean fields; since GetOk() returns non-zero values, false will be ignored.

The marshaling/un-marshaling of the sdk structure behaves correctly because of the use of a pointer - omitempty is
affected by the pointer being nil or not, and not by the actual value being false or true.

We will fix the provider by working around GetOk() somehow. I'll keep you posted.

@dreamblack86
Copy link
Contributor Author

Hi @mflorin ,
I think the IONOS Cloud is handling the non-existence of the switch incorrectly. That is, if the IONOS Cloud receives a data structure without the DHCP parameter, the default is unfortunately not => false but => true. Which is actually not correct. I can well imagine that it is so "wanted" because it certainly corresponds to the IONOS Cloud standard. So maybe the name of the field should be reconsidered.

So you should maybe:

// KubernetesNodePoolLan struct for KubernetesNodePoolLan
type KubernetesNodePoolLan struct {
    // The LAN ID of an existing LAN at the related datacenter
   Id *int32 `json:"id,omitempty"`
   // Indicates if the Kubernetes Node Pool LAN will reserve an IP using DHCP
   Dhcp *bool `json:"dhcp,omitempty"`
   // array of additional LANs attached to worker nodes
   Routes *[]KubernetesNodePoolLanRoutes `json:"routes,omitempty"`
}

Replace with this.

// KubernetesNodePoolLan struct for KubernetesNodePoolLan
type KubernetesNodePoolLan struct {
    // The LAN ID of an existing LAN at the related datacenter
   Id *int32 `json:"id,omitempty"`
   // Indicates if the Kubernetes Node Pool LAN will reserve an IP using DHCP
   DhcpDisable *bool `json:"dhcp_disable,omitempty"`
   // array of additional LANs attached to worker nodes
   Routes *[]KubernetesNodePoolLanRoutes `json:"routes,omitempty"`
}

This ensures that if the customer leaves this field "empty", the correct default is set from IONOS's point of view.

@dreamblack86
Copy link
Contributor Author

Or the IONOS Cloud really sets the value to false when this field is not present.

@dreamblack86
Copy link
Contributor Author

Hi @mflorin Sorry about the wrong SDK reference. I just noticed that the pointers for booleans are used in a newer version of the SDK than my version. BTW that helps me then already in another place. =)

iblindu added a commit that referenced this issue Jun 24, 2021
iblindu added a commit that referenced this issue Jul 1, 2021
…erver (#38)

* fix: fixes #25 correctly set of dhcp + nil check + added firewall_type field in server resource

* docs update for k8s node pool
@iblindu
Copy link
Contributor

iblindu commented Jul 5, 2021

@dreamblack86, please check v6.0.0-alpha.4

@iblindu iblindu closed this as completed Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants