Wrong setting for cloudapiv6 k8s-lans-dhcp after terraform apply.
dreamblack86 opened this issue · 5 comments
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
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.
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.
Or the IONOS Cloud really sets the value to false
when this field is not present.
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. =)
@dreamblack86, please check v6.0.0-alpha.4