diff --git a/gridscale/resource_gridscale_k8s.go b/gridscale/resource_gridscale_k8s.go index b667f195..138152ba 100644 --- a/gridscale/resource_gridscale_k8s.go +++ b/gridscale/resource_gridscale_k8s.go @@ -801,10 +801,18 @@ func resourceGridscaleK8sCreate(d *schema.ResourceData, meta interface{}) error client := meta.(*gsclient.Client) errorPrefix := fmt.Sprintf("create k8s (%s) resource -", d.Id()) template, err := deriveK8sTemplateFromResourceData(client, d) - if err != nil { return err } + // check if the k8s release is supported by gs tf provider v1 + templateRelease, err := NewRelease(template.Properties.Release) + if err != nil { + return fmt.Errorf("%s error: %v", errorPrefix, err) + } + err = templateRelease.CheckIfK8SReleaseIsSupported() + if err != nil { + return fmt.Errorf("%s error: %v", errorPrefix, err) + } requestBody := gsclient.PaaSServiceCreateRequest{ Name: d.Get("name").(string), PaaSServiceTemplateUUID: template.Properties.ObjectUUID, @@ -1075,8 +1083,17 @@ func resourceGridscaleK8sDelete(d *schema.ResourceData, meta interface{}) error } func validateK8sParameters(d *schema.ResourceDiff, template gsclient.PaaSTemplate) error { - var errorMessages []string + // check if the k8s release is supported by gs tf provider v1 + templateRelease, err := NewRelease(template.Properties.Release) + if err != nil { + return err + } + err = templateRelease.CheckIfK8SReleaseIsSupported() + if err != nil { + return err + } + var errorMessages []string worker_memory_scheme, mem_ok := template.Properties.ParametersSchema["k8s_worker_node_ram"] // TODO: The API scheme will be CHANGED in the future. There will be multiple node pools. if memory, ok := d.GetOk("node_pool.0.memory"); ok && mem_ok { diff --git a/gridscale/resource_gridscale_release.go b/gridscale/resource_gridscale_release.go index f8140834..cf94dddd 100644 --- a/gridscale/resource_gridscale_release.go +++ b/gridscale/resource_gridscale_release.go @@ -17,6 +17,8 @@ type Feature struct { Release } +const unsupportedK8SRelease = "1.30" + // NewRelease creates a new Release instance. func NewRelease(representation string) (*Release, error) { version, err := goVersion.NewVersion(representation) @@ -28,7 +30,7 @@ func NewRelease(representation string) (*Release, error) { } // CheckIfFeatureIsKnown checks by a Release receiver if a passed Feature instance is known. -func (r *Release) CheckIfFeatureIsKnown(f *Feature) *ReleaseFeatureIncompatibilityError { +func (r *Release) CheckIfFeatureIsKnown(f *Feature) error { if r.LessThan(&f.Version) { return &ReleaseFeatureIncompatibilityError{ Detail: fmt.Sprintf("Feature '%s' is part of release %s but requested for release %s.", f.Description, f.String(), r.String()), @@ -36,3 +38,13 @@ func (r *Release) CheckIfFeatureIsKnown(f *Feature) *ReleaseFeatureIncompatibili } return nil } + +// CheckIfK8SReleaseIsSupported checks if the Kubernetes release is supported by this gridscale terraform provider. +func (r *Release) CheckIfK8SReleaseIsSupported() error { + if r.GreaterThanOrEqual(goVersion.Must(goVersion.NewVersion(unsupportedK8SRelease))) { + return &ReleaseFeatureIncompatibilityError{ + Detail: fmt.Sprintf("this gridscale terraform provider version v1 supports only Kubernetes release < %s, for Kubernetes release %s please use gridscale terraform provider version v2", unsupportedK8SRelease, r.String()), + } + } + return nil +}