diff --git a/go.mod b/go.mod index 3d173a1..b886700 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/hashicorp/go-version v1.5.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0 github.com/mitchellh/go-homedir v1.1.0 - github.com/syseleven/go-metakube v0.0.0-20230110080853-e37d025caddf + github.com/syseleven/go-metakube v0.0.0-20230214162150-bac65fa46326 go.uber.org/zap v1.19.0 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 ) diff --git a/go.sum b/go.sum index 75e88ad..ad801b8 100644 --- a/go.sum +++ b/go.sum @@ -306,8 +306,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/syseleven/go-metakube v0.0.0-20230110080853-e37d025caddf h1:k/SAqRjiAvP3dhEgLEIYY/vNCorZcJMxwyyh4EKtUfQ= -github.com/syseleven/go-metakube v0.0.0-20230110080853-e37d025caddf/go.mod h1:Wmf9qWGkFXBGAJxXuwGH+SH6eq9txahkGRpTUz/JFhY= +github.com/syseleven/go-metakube v0.0.0-20230214162150-bac65fa46326 h1:xXowml9+zi3i9DY2Hr6/9WDPWt25fwjIg3imN/LD1Ss= +github.com/syseleven/go-metakube v0.0.0-20230214162150-bac65fa46326/go.mod h1:Wmf9qWGkFXBGAJxXuwGH+SH6eq9txahkGRpTUz/JFhY= github.com/syseleven/terraform-plugin-sdk/v2 v2.17.0-sys11-1 h1:M2c981F8TnNf8yFGD51oHNzMYcIIQ6nbySBrvUQrckM= github.com/syseleven/terraform-plugin-sdk/v2 v2.17.0-sys11-1/go.mod h1:tunSMaRkZLxRmsJZAFXiznrk8Vl+KJ+GAfW52tQMu7w= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= diff --git a/metakube/resource_metakube_cluster.go b/metakube/resource_metakube_cluster.go index 6ed962e..4fdbd5f 100644 --- a/metakube/resource_metakube_cluster.go +++ b/metakube/resource_metakube_cluster.go @@ -238,8 +238,8 @@ func metakubeResourceClusterSSHKeys(d *schema.ResourceData) []string { func metakubeResourceClusterFindDatacenterByName(ctx context.Context, k *metakubeProviderMeta, d *schema.ResourceData) (*models.Datacenter, diag.Diagnostics) { name := d.Get("dc_name").(string) - p := datacenter.NewListDatacentersParams().WithContext(ctx) - r, err := k.client.Datacenter.ListDatacenters(p, k.auth) + p := datacenter.NewListDatacentersV2Params().WithContext(ctx) + r, err := k.client.Datacenter.ListDatacentersV2(p, k.auth) if err != nil { return nil, diag.Errorf("Can't list datacenters: %s", stringifyResponseError(err)) } diff --git a/metakube/resource_metakube_cluster_structure.go b/metakube/resource_metakube_cluster_structure.go index b3f3da8..fa72458 100644 --- a/metakube/resource_metakube_cluster_structure.go +++ b/metakube/resource_metakube_cluster_structure.go @@ -59,35 +59,6 @@ func flattenUpdateWindow(in *models.UpdateWindow) []interface{} { return []interface{}{m} } -func flattenMachineNetworks(in []*models.MachineNetworkingConfig) []interface{} { - if len(in) < 1 { - return []interface{}{} - } - - att := make([]interface{}, len(in)) - - for i, v := range in { - m := make(map[string]interface{}) - - if v.CIDR != "" { - m["cidr"] = v.CIDR - } - if v.Gateway != "" { - m["gateway"] = v.Gateway - } - if l := len(v.DNSServers); l > 0 { - ds := make([]interface{}, l) - for i, s := range v.DNSServers { - ds[i] = s - } - m["dns_servers"] = ds - } - att[i] = m - } - - return att -} - func flattenClusterCloudSpec(values clusterPreserveValues, in *models.CloudSpec) []interface{} { if in == nil { return []interface{}{} @@ -409,43 +380,6 @@ func expandUpdateWindow(p []interface{}) *models.UpdateWindow { return ret } -func expandMachineNetworks(p []interface{}) []*models.MachineNetworkingConfig { - if len(p) < 1 { - return nil - } - var machines []*models.MachineNetworkingConfig - for _, elem := range p { - in := elem.(map[string]interface{}) - obj := &models.MachineNetworkingConfig{} - - if v, ok := in["cidr"]; ok { - if vv, ok := v.(string); ok && v != "" { - obj.CIDR = vv - } - } - - if v, ok := in["gateway"]; ok { - if vv, ok := v.(string); ok && v != "" { - obj.Gateway = vv - } - } - - if v, ok := in["dns_servers"]; ok { - if vv, ok := v.([]interface{}); ok { - for _, s := range vv { - if ss, ok := s.(string); ok && s != "" { - obj.DNSServers = append(obj.DNSServers, ss) - } - } - } - } - - machines = append(machines, obj) - } - - return machines -} - func expandAuditLogging(enabled bool) *models.AuditLoggingSettings { return &models.AuditLoggingSettings{ Enabled: enabled, diff --git a/metakube/resource_metakube_cluster_structure_test.go b/metakube/resource_metakube_cluster_structure_test.go index 6ddda7e..c70494e 100644 --- a/metakube/resource_metakube_cluster_structure_test.go +++ b/metakube/resource_metakube_cluster_structure_test.go @@ -20,7 +20,6 @@ func TestMetakubeClusterFlattenSpec(t *testing.T) { Start: "Tue 02:00", Length: "3h", }, - MachineNetworks: nil, EnableUserSSHKeyAgent: true, AuditLogging: &models.AuditLoggingSettings{}, Cloud: &models.CloudSpec{ @@ -362,51 +361,6 @@ func TestFlattenAzureCloudSpec(t *testing.T) { } } -func TestFlattenMachineNetwork(t *testing.T) { - cases := []struct { - Input []*models.MachineNetworkingConfig - ExpectedOutput []interface{} - }{ - { - []*models.MachineNetworkingConfig{ - { - CIDR: "192.168.0.0/24", - Gateway: "192.168.1.1", - DNSServers: []string{ - "192.200.200.1", - "192.200.200.201", - }, - }, - }, - []interface{}{ - map[string]interface{}{ - "cidr": "192.168.0.0/24", - "gateway": "192.168.1.1", - "dns_servers": []interface{}{ - "192.200.200.1", - "192.200.200.201", - }, - }, - }, - }, - { - []*models.MachineNetworkingConfig{}, - []interface{}{}, - }, - { - nil, - []interface{}{}, - }, - } - - for _, tc := range cases { - output := flattenMachineNetworks(tc.Input) - if diff := cmp.Diff(tc.ExpectedOutput, output); diff != "" { - t.Fatalf("Unexpected output from expander: mismatch (-want +got):\n%s", diff) - } - } -} - func TestExpandClusterSpec(t *testing.T) { cases := []struct { Input []interface{} @@ -448,7 +402,6 @@ func TestExpandClusterSpec(t *testing.T) { Start: "Tue 02:00", Length: "3h", }, - MachineNetworks: nil, AuditLogging: &models.AuditLoggingSettings{}, UsePodSecurityPolicyAdmissionPlugin: true, UsePodNodeSelectorAdmissionPlugin: true, @@ -708,53 +661,6 @@ func TestExpandAzureCloudSpec(t *testing.T) { } } -func TestExpandMachineNetwork(t *testing.T) { - cases := []struct { - Input []interface{} - ExpectedOutput []*models.MachineNetworkingConfig - }{ - { - []interface{}{ - map[string]interface{}{ - "cidr": "192.168.0.0/24", - "gateway": "192.168.1.1", - "dns_servers": []interface{}{ - "192.200.200.1", - "192.200.200.201", - }, - }, - }, - []*models.MachineNetworkingConfig{ - { - CIDR: "192.168.0.0/24", - Gateway: "192.168.1.1", - DNSServers: []string{ - "192.200.200.1", - "192.200.200.201", - }, - }, - }, - }, - { - []interface{}{ - map[string]interface{}{}, - }, - []*models.MachineNetworkingConfig{{}}, - }, - { - []interface{}{}, - nil, - }, - } - - for _, tc := range cases { - output := expandMachineNetworks(tc.Input) - if diff := cmp.Diff(tc.ExpectedOutput, output); diff != "" { - t.Fatalf("Unexpected output from expander: mismatch (-want +got):\n%s", diff) - } - } -} - func TestExpandAuditLogging(t *testing.T) { want := &models.AuditLoggingSettings{ Enabled: true,