Skip to content

Commit

Permalink
feat: Add 'lans' property for Dataplatform clusters (#541)
Browse files Browse the repository at this point in the history
* feat: Add 'lans' property for Dataplatform clusters

* refactor: Add/move some error checks

* doc: Add documentation for new 'lans' attribute
  • Loading branch information
adeatcu-ionos authored Apr 22, 2024
1 parent 2ddabfa commit 89f68dc
Show file tree
Hide file tree
Showing 44 changed files with 1,533 additions and 544 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix name validation for Dataplatform resources
- Change location for MongoDB tests to improve running time
- Change location for PgSQL tests to improve running time
- Add new attribute for Dataplatform clusters: `lans`

## 6.4.14
### Features
Expand Down
6 changes: 6 additions & 0 deletions docs/data-sources/dataplatform_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ The following attributes are returned by the datasource:
* value - is the token
* `server` - cluster server (same as `config[0].clusters[0].cluster.server` but provided as an attribute for ease of use)
* `ca_crt` - base64 decoded cluster certificate authority data (provided as an attribute for direct use)
* `lans` - A list of LANs you want this node pool to be part of
* `lan_id` - The LAN ID of an existing LAN at the related data center
* `dhcp` - Indicates if the Kubernetes node pool LAN will reserve an IP using DHCP. The default value is 'true'.
* `routes` - An array of additional LANs attached to worker nodes
* `gateway` - IPv4 or IPv6 gateway IP for the route
* `network` - IPv4 or IPv6 CIDR to be routed via the interface

**NOTE**: The whole `config` node is marked as **sensitive**.

Expand Down
32 changes: 31 additions & 1 deletion docs/resources/dataplatform_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,31 @@ resource "ionoscloud_dataplatform_cluster" "example" {
day_of_the_week = "Sunday"
time = "09:00:00"
}
version = "23.7"
version = "23.11"
lans {
lan_id = <LAN_ID>
dhcp = false
routes {
network = <CIDR>
gateway = <GATEWAY_IP>
}
}
lans {
lan_id = <LAN_ID>
dhcp = false
routes {
network = <CIDR>
gateway = <GATEWAY_IP>
}
routes {
network = <CIDR>
gateway = <GATEWAY_IP>
}
routes {
network = <CIDR>
gateway = <GATEWAY_IP>
}
}
}
```

Expand All @@ -39,6 +63,12 @@ resource "ionoscloud_dataplatform_cluster" "example" {
* `maintenance_window` - (Optional)[string] Starting time of a weekly 4 hour-long window, during which maintenance might occur in hh:mm:ss format
* `time` - (Required)[string] Time at which the maintenance should start. Must conform to the 'HH:MM:SS' 24-hour format. This pattern matches the "HH:MM:SS 24-hour format with leading 0" format. For more information take a look at [this link](https://stackoverflow.com/questions/7536755/regular-expression-for-matching-hhmm-time-format).
* `day_of_the_week` - (Required)[string] Must be set with one the values `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday`, `Saturday` or `Sunday`.
* `lans` - (Optional)[list] A list of LANs you want this node pool to be part of.
* `lan_id` - (Required)[string] The LAN ID of an existing LAN at the related data center.
* `dhcp` - (Optional)[bool] Indicates if the Kubernetes node pool LAN will reserve an IP using DHCP. The default value is 'true'.
* `routes` - (Optional)[list] An array of additional LANs attached to worker nodes.
* `gateway` - (Required)[string] IPv4 or IPv6 gateway IP for the route.
* `network` - (Required)[string] IPv4 or IPv6 CIDR to be routed via the interface.

## Import

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/iancoleman/strcase v0.3.0
github.com/ionos-cloud/sdk-go-cert-manager v1.0.1
github.com/ionos-cloud/sdk-go-container-registry v1.1.0
github.com/ionos-cloud/sdk-go-dataplatform v1.0.0
github.com/ionos-cloud/sdk-go-dataplatform v1.0.3
github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.0.0
github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ github.com/ionos-cloud/sdk-go-cert-manager v1.0.1 h1:QGnenRREavvU0ZrXvY4hmCMXRyv
github.com/ionos-cloud/sdk-go-cert-manager v1.0.1/go.mod h1:EYDegkY6fUSkx0BL0GpNMpKvp33AId2vTZL44YLPreA=
github.com/ionos-cloud/sdk-go-container-registry v1.1.0 h1:H92gzx9oj0vvbozbXwn2RLNEw7++1Ns3Kl9PGrh5Waw=
github.com/ionos-cloud/sdk-go-container-registry v1.1.0/go.mod h1:woBP1+A4N0KXiRj9jG4y/hEXgrVjJv0CUlAvc24mCeo=
github.com/ionos-cloud/sdk-go-dataplatform v1.0.0 h1:seX3oHtMmmlmwSCYUUF91Jrx4B/B9tMyNSNkHbjlAxA=
github.com/ionos-cloud/sdk-go-dataplatform v1.0.0/go.mod h1:YitNqq01IAbzMr1GpXIDW1+pvhiY9eUs7/+rB9UitXE=
github.com/ionos-cloud/sdk-go-dataplatform v1.0.3 h1:eaZITgPaLHbK4d/nVaImvP19a5yAumI5hprjM/B1qSE=
github.com/ionos-cloud/sdk-go-dataplatform v1.0.3/go.mod h1:LXJGnUwLLiJhKgApv7TIPGy7WOuGbYIzBPFxGpNfqN0=
github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.0.0 h1:zTfeV4lwp7c8xkjoJH50oz96cuaUVgbypbG7U3dVi5c=
github.com/ionos-cloud/sdk-go-dbaas-mariadb v1.0.0/go.mod h1:627dsH56YGQD7x0g2FGdVsxNtBySvQ3QU0uG+d6/Evk=
github.com/ionos-cloud/sdk-go-dbaas-mongo v1.3.1 h1:+tDoZ8IEPxYwJd6fDIpWksNJs9Zzw7Pu5A39jTew058=
Expand Down
53 changes: 49 additions & 4 deletions ionoscloud/data_source_dataplatform_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ package ionoscloud
import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"log"
"strings"

"gopkg.in/yaml.v3"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
dataplatform "github.com/ionos-cloud/sdk-go-dataplatform"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
dataplatformService "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/dataplatform"
"gopkg.in/yaml.v3"
)

func dataSourceDataplatformCluster() *schema.Resource {
Expand Down Expand Up @@ -175,6 +177,44 @@ func dataSourceDataplatformCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"lans": {
Type: schema.TypeSet,
Description: "A list of LANs you want this node pool to be part of",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"lan_id": {
Type: schema.TypeString,
Description: "The LAN ID of an existing LAN at the related data center",
Computed: true,
},
"dhcp": {
Type: schema.TypeBool,
Description: "Indicates if the Kubernetes node pool LAN will reserve an IP using DHCP. The default value is 'true'",
Computed: true,
},
"routes": {
Type: schema.TypeSet,
Description: "An array of additional LANs attached to worker nodes",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network": {
Type: schema.TypeString,
Description: "IPv4 or IPv6 CIDR to be routed via the interface",
Computed: true,
},
"gateway": {
Type: schema.TypeString,
Description: "IPv4 or IPv6 gateway IP for the route",
Computed: true,
},
},
},
},
},
},
},
},
Timeouts: &resourceDefaultTimeouts,
}
Expand Down Expand Up @@ -267,16 +307,21 @@ func setAdditionalDataplatformClusterData(ctx context.Context, d *schema.Resourc

/* get from api and set in schema the kubeconfig*/
if cluster.Id != nil {
kubeConfig, _, err := client.GetClusterKubeConfig(ctx, *cluster.Id)
kubeConfigMap, _, err := client.GetClusterKubeConfig(ctx, *cluster.Id)
if err != nil {
return fmt.Errorf("an error occurred while fetching the kubernetes config for cluster with ID %s: %w", *cluster.Id, err)
}

if err := d.Set("kube_config", kubeConfig); err != nil {
kubeConfig, err := json.Marshal(kubeConfigMap)
if err != nil {
return err
}
kubeConfigString := string(kubeConfig)
if err := d.Set("kube_config", kubeConfigString); err != nil {
return err
}

if err := setDataplatformConfigData(d, kubeConfig); err != nil {
if err := setDataplatformConfigData(d, kubeConfigString); err != nil {
return err
}
}
Expand Down
44 changes: 43 additions & 1 deletion ionoscloud/resource_dataplatform_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"log"
"regexp"

"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
dataplatformService "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/dataplatform"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
)

func resourceDataplatformCluster() *schema.Resource {
Expand Down Expand Up @@ -67,6 +68,47 @@ func resourceDataplatformCluster() *schema.Resource {
},
},
},
"lans": {
Type: schema.TypeSet,
Description: "A list of LANs you want this node pool to be part of",
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"lan_id": {
Type: schema.TypeString,
Description: "The LAN ID of an existing LAN at the related data center",
Required: true,
},
"dhcp": {
Type: schema.TypeBool,
Description: "Indicates if the Kubernetes node pool LAN will reserve an IP using DHCP. The default value is 'true'",
Optional: true,
Default: true,
},
"routes": {
Type: schema.TypeSet,
Description: "An array of additional LANs attached to worker nodes",
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"network": {
Type: schema.TypeString,
Description: "IPv4 or IPv6 CIDR to be routed via the interface",
ValidateDiagFunc: validation.ToDiagFunc(validation.IsCIDR),
Required: true,
},
"gateway": {
Type: schema.TypeString,
Description: "IPv4 or IPv6 gateway IP for the route",
ValidateDiagFunc: validation.ToDiagFunc(validation.IsIPAddress),
Required: true,
},
},
},
},
},
},
},
},
Timeouts: &resourceDefaultTimeouts,
}
Expand Down
Loading

0 comments on commit 89f68dc

Please sign in to comment.