From 85dba37acc0ac16cae99a0be0c4783f39fc10981 Mon Sep 17 00:00:00 2001 From: "sammy.huang" Date: Fri, 24 May 2024 18:11:29 +0800 Subject: [PATCH] feat: support serverless plan (#31) Signed-off-by: Liang Huang --- docs/resources/cluster.md | 11 ++++++++++- .../resources/zillizcloud_cluster/resource.tf | 12 ++++++++++-- internal/provider/cluster_resource.go | 16 ++++++++-------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 129f03b..2536ef9 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -31,11 +31,20 @@ data "zillizcloud_project" "default" { resource "zillizcloud_cluster" "free_plan_cluster" { # Defining a basic starter cluster cluster_name = "Cluster-01" # The name of the cluster + plan = "Free" # The service plan for the cluster The name of the cluster project_id = data.zillizcloud_project.default.id # Linking to the project ID fetched earlier } -resource "zillizcloud_cluster" "standard_plan_cluster" { +resource "zillizcloud_cluster" "serverless_plan_cluster" { + # Defining a basic starter cluster cluster_name = "Cluster-02" # The name of the cluster + plan = "Serverless" # The service plan for the cluster# The name of the cluster + project_id = data.zillizcloud_project.default.id # Linking to the project ID fetched earlier +} + + +resource "zillizcloud_cluster" "standard_plan_cluster" { + cluster_name = "Cluster-03" # The name of the cluster region_id = "aws-us-east-2" # The region where the cluster will be deployed plan = "Standard" # The service plan for the cluster cu_size = "1" # The size of the compute unit diff --git a/examples/resources/zillizcloud_cluster/resource.tf b/examples/resources/zillizcloud_cluster/resource.tf index 6ecb13a..a4c02f0 100644 --- a/examples/resources/zillizcloud_cluster/resource.tf +++ b/examples/resources/zillizcloud_cluster/resource.tf @@ -16,15 +16,23 @@ data "zillizcloud_project" "default" { resource "zillizcloud_cluster" "free_plan_cluster" { # Defining a basic starter cluster cluster_name = "Cluster-01" # The name of the cluster + plan = "Free" # The service plan for the cluster The name of the cluster project_id = data.zillizcloud_project.default.id # Linking to the project ID fetched earlier } -resource "zillizcloud_cluster" "standard_plan_cluster" { +resource "zillizcloud_cluster" "serverless_plan_cluster" { + # Defining a basic starter cluster cluster_name = "Cluster-02" # The name of the cluster + plan = "Serverless" # The service plan for the cluster# The name of the cluster + project_id = data.zillizcloud_project.default.id # Linking to the project ID fetched earlier +} + + +resource "zillizcloud_cluster" "standard_plan_cluster" { + cluster_name = "Cluster-03" # The name of the cluster region_id = "aws-us-east-2" # The region where the cluster will be deployed plan = "Standard" # The service plan for the cluster cu_size = "1" # The size of the compute unit cu_type = "Performance-optimized" # The type of compute unit, optimized for performance project_id = data.zillizcloud_project.default.id # Linking to the project ID fetched earlier } - diff --git a/internal/provider/cluster_resource.go b/internal/provider/cluster_resource.go index d10052c..1a9dbcf 100644 --- a/internal/provider/cluster_resource.go +++ b/internal/provider/cluster_resource.go @@ -80,12 +80,12 @@ func (r *ClusterResource) Schema(ctx context.Context, req resource.SchemaRequest PlanModifiers: []planmodifier.String{ stringplanmodifier.RequiresReplace(), }, - Validators: []validator.String{ - stringvalidator.AlsoRequires( - path.MatchRelative().AtParent().AtName("cu_size"), - path.MatchRelative().AtParent().AtName("cu_type"), - ), - }, + // Validators: []validator.String{ + // stringvalidator.AlsoRequires( + // path.MatchRelative().AtParent().AtName("cu_size"), + // path.MatchRelative().AtParent().AtName("cu_type"), + // ), + // }, }, "cu_size": schema.Int64Attribute{ MarkdownDescription: "The size of the CU to be used for the created cluster. It is an integer from 1 to 256.", @@ -249,10 +249,10 @@ func (r *ClusterResource) Create(ctx context.Context, req resource.CreateRequest return } - if (data.Plan.IsNull() || zilliz.Plan(data.Plan.ValueString()) == zilliz.FreePlan) && data.CuSize.IsUnknown() && data.CuType.IsNull() { + if (data.Plan.IsNull() || zilliz.Plan(data.Plan.ValueString()) == zilliz.FreePlan || zilliz.Plan(data.Plan.ValueString()) == zilliz.ServerlessPlan) && data.CuSize.IsUnknown() && data.CuType.IsNull() { response, err = client.CreateServerlessCluster(zilliz.CreateServerlessClusterParams{ - // Plan: zilliz.Plan(data.Plan.ValueString()), + Plan: zilliz.Plan(data.Plan.ValueString()), ClusterName: data.ClusterName.ValueString(), ProjectId: data.ProjectId.ValueString(), })