From 80b0224a531ac3d5f36d69040cc0361142446da8 Mon Sep 17 00:00:00 2001 From: LeCrabe Date: Fri, 31 May 2024 10:47:57 +0200 Subject: [PATCH] fix: remove all hardcoded region parameters + default="par" --- pkg/attributes/common.go | 5 +++-- pkg/resources/addon/resource_addon_schema.go | 3 ++- pkg/resources/cellar/resource_cellar_schema.go | 3 ++- pkg/resources/materiakv/resource_materiakv_crud.go | 2 +- pkg/resources/materiakv/resource_materiakv_schema.go | 5 ++++- pkg/resources/mongodb/resource_mongodb_crud.go | 3 ++- pkg/resources/mongodb/resource_mongodb_schema.go | 7 +++++-- pkg/resources/postgresql/resource_postgresql_schema.go | 3 ++- 8 files changed, 21 insertions(+), 10 deletions(-) diff --git a/pkg/attributes/common.go b/pkg/attributes/common.go index c6a7d7b..e37c1e5 100644 --- a/pkg/attributes/common.go +++ b/pkg/attributes/common.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "go.clever-cloud.com/terraform-provider/pkg" @@ -44,8 +45,8 @@ var runtimeCommon = map[string]schema.Attribute{ MarkdownDescription: "Use dedicated instance with given flavor for build step", }, "region": schema.StringAttribute{ - Required: true, - MarkdownDescription: "Geographical region where the app will be deployed", + Default: stringdefault.StaticString("par"), + MarkdownDescription: "Geographical region where the database will be deployed", }, "sticky_sessions": schema.BoolAttribute{ Optional: true, diff --git a/pkg/resources/addon/resource_addon_schema.go b/pkg/resources/addon/resource_addon_schema.go index 233a762..2df7790 100644 --- a/pkg/resources/addon/resource_addon_schema.go +++ b/pkg/resources/addon/resource_addon_schema.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -30,7 +31,7 @@ func (r ResourceAddon) Schema(_ context.Context, req resource.SchemaRequest, res // customer provided "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the addon"}, "plan": schema.StringAttribute{Required: true, MarkdownDescription: "billing plan"}, - "region": schema.StringAttribute{Required: true, MarkdownDescription: "Geographical region where the addon will be deployed (when relevant)"}, + "region": schema.StringAttribute{MarkdownDescription: "Geographical region where the addon will be deployed (when relevant)", Default: stringdefault.StaticString("par")}, "third_party_provider": schema.StringAttribute{Required: true, MarkdownDescription: "Provider ID"}, // provider diff --git a/pkg/resources/cellar/resource_cellar_schema.go b/pkg/resources/cellar/resource_cellar_schema.go index 5600287..6299a1c 100644 --- a/pkg/resources/cellar/resource_cellar_schema.go +++ b/pkg/resources/cellar/resource_cellar_schema.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -30,7 +31,7 @@ func (r ResourceCellar) Schema(_ context.Context, req resource.SchemaRequest, re Attributes: map[string]schema.Attribute{ // customer provided "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the Cellar"}, - "region": schema.StringAttribute{Required: true, MarkdownDescription: "Geographical region where the data will be stored"}, + "region": schema.StringAttribute{MarkdownDescription: "Geographical region where the data will be stored", Default: stringdefault.StaticString("par")}, // provider "id": schema.StringAttribute{Computed: true, MarkdownDescription: "Generated unique identifier"}, diff --git a/pkg/resources/materiakv/resource_materiakv_crud.go b/pkg/resources/materiakv/resource_materiakv_crud.go index aed38bd..5dbb6c3 100644 --- a/pkg/resources/materiakv/resource_materiakv_crud.go +++ b/pkg/resources/materiakv/resource_materiakv_crud.go @@ -59,7 +59,7 @@ func (r *ResourceMateriaKV) Create(ctx context.Context, req resource.CreateReque Name: kv.Name.ValueString(), Plan: plan.ID, ProviderID: "kv", - Region: "par", + Region: kv.Region.ValueString(), } res := tmp.CreateAddon(ctx, r.cc, r.org, addonReq) diff --git a/pkg/resources/materiakv/resource_materiakv_schema.go b/pkg/resources/materiakv/resource_materiakv_schema.go index f7659da..0dbd2e6 100644 --- a/pkg/resources/materiakv/resource_materiakv_schema.go +++ b/pkg/resources/materiakv/resource_materiakv_schema.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -15,6 +16,7 @@ type MateriaKV struct { CreationDate types.Int64 `tfsdk:"creation_date"` Host types.String `tfsdk:"host"` Port types.Int64 `tfsdk:"port"` + Region types.String `tfsdk:"region"` Token types.String `tfsdk:"token"` } @@ -27,7 +29,8 @@ func (r ResourceMateriaKV) Schema(_ context.Context, req resource.SchemaRequest, MarkdownDescription: resourceMateriaKVDoc, Attributes: map[string]schema.Attribute{ // customer provided - "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the service"}, + "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the service"}, + "region": schema.StringAttribute{MarkdownDescription: "Geographical region where the database will be deployed", Default: stringdefault.StaticString("par")}, // provider "id": schema.StringAttribute{Computed: true, MarkdownDescription: "Generated unique identifier"}, "creation_date": schema.Int64Attribute{Computed: true, MarkdownDescription: "Date of database creation"}, diff --git a/pkg/resources/mongodb/resource_mongodb_crud.go b/pkg/resources/mongodb/resource_mongodb_crud.go index bedec88..3cb7ecf 100644 --- a/pkg/resources/mongodb/resource_mongodb_crud.go +++ b/pkg/resources/mongodb/resource_mongodb_crud.go @@ -49,6 +49,7 @@ func (r *ResourceMongoDB) Create(ctx context.Context, req resource.CreateRequest addonsProviders := addonsProvidersRes.Payload() prov := pkg.LookupAddonProvider(*addonsProviders, "mongodb-addon") plan := pkg.LookupProviderPlan(prov, mg.Plan.ValueString()) + // TODO if plan.ID == "" { resp.Diagnostics.AddError("failed to find plan", "expect: "+strings.Join(pkg.ProviderPlansAsList(prov), ", ")+", got: "+mg.Plan.String()) return @@ -58,7 +59,7 @@ func (r *ResourceMongoDB) Create(ctx context.Context, req resource.CreateRequest Name: mg.Name.ValueString(), Plan: plan.ID, ProviderID: "mongodb-addon", - Region: "par", + Region: mg.Region.ValueString(), } res := tmp.CreateAddon(ctx, r.cc, r.org, addonReq) diff --git a/pkg/resources/mongodb/resource_mongodb_schema.go b/pkg/resources/mongodb/resource_mongodb_schema.go index 75deb44..9558697 100644 --- a/pkg/resources/mongodb/resource_mongodb_schema.go +++ b/pkg/resources/mongodb/resource_mongodb_schema.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -13,6 +14,7 @@ type MongoDB struct { ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` Plan types.String `tfsdk:"plan"` + Region types.String `tfsdk:"region"` CreationDate types.Int64 `tfsdk:"creation_date"` Host types.String `tfsdk:"host"` Port types.Int64 `tfsdk:"port"` @@ -29,8 +31,9 @@ func (r ResourceMongoDB) Schema(_ context.Context, req resource.SchemaRequest, r MarkdownDescription: resourceMongoDBDoc, Attributes: map[string]schema.Attribute{ // customer provided - "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the service"}, - "plan": schema.StringAttribute{Required: true, MarkdownDescription: "Database size and spec"}, + "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the service"}, + "plan": schema.StringAttribute{Required: true, MarkdownDescription: "Database size and spec"}, + "region": schema.StringAttribute{MarkdownDescription: "Geographical region where the database will be deployed", Default: stringdefault.StaticString("par")}, // provider "id": schema.StringAttribute{Computed: true, MarkdownDescription: "Generated unique identifier"}, diff --git a/pkg/resources/postgresql/resource_postgresql_schema.go b/pkg/resources/postgresql/resource_postgresql_schema.go index 52f8f43..739d848 100644 --- a/pkg/resources/postgresql/resource_postgresql_schema.go +++ b/pkg/resources/postgresql/resource_postgresql_schema.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -33,7 +34,7 @@ func (r ResourcePostgreSQL) Schema(_ context.Context, req resource.SchemaRequest // customer provided "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the service"}, "plan": schema.StringAttribute{Required: true, MarkdownDescription: "Database size and spec"}, - "region": schema.StringAttribute{Required: true, MarkdownDescription: "Geographical region where the database will be deployed"}, + "region": schema.StringAttribute{MarkdownDescription: "Geographical region where the database will be deployed", Default: stringdefault.StaticString("par")}, // provider "id": schema.StringAttribute{Computed: true, MarkdownDescription: "Generated unique identifier"},