From 44be59708ccacfd05b4f591ad2f95e3f853e1f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20COLLIGNON=20DUCRET?= Date: Mon, 10 Jun 2024 11:55:57 +0200 Subject: [PATCH] feat: set par as default regions --- docs/resources/addon.md | 5 ++++- docs/resources/cellar.md | 3 +++ docs/resources/java_war.md | 2 +- docs/resources/materia_kv.md | 3 +++ docs/resources/mongodb.md | 3 +++ docs/resources/nodejs.md | 2 +- docs/resources/php.md | 2 +- docs/resources/postgresql.md | 3 +++ docs/resources/python.md | 2 +- docs/resources/scala.md | 2 +- docs/resources/static.md | 2 +- pkg/application/creation.go | 3 ++- pkg/attributes/common.go | 7 +++++-- pkg/resources/addon/resource_addon_schema.go | 12 +++++++++--- pkg/resources/cellar/resource_cellar_schema.go | 10 ++++++++-- pkg/resources/materiakv/resource_materiakv_schema.go | 10 ++++++++-- pkg/resources/mongodb/resource_mongodb_schema.go | 12 +++++++++--- pkg/resources/nodejs/resource_nodejs_test.go | 3 +++ .../postgresql/resource_postgresql_schema.go | 12 +++++++++--- 19 files changed, 75 insertions(+), 23 deletions(-) diff --git a/docs/resources/addon.md b/docs/resources/addon.md index e318ddb..6cbfea4 100644 --- a/docs/resources/addon.md +++ b/docs/resources/addon.md @@ -26,9 +26,12 @@ List of available providers: - `name` (String) Name of the addon - `plan` (String) billing plan -- `region` (String) Geographical region where the addon will be deployed (when relevant) - `third_party_provider` (String) Provider ID +### Optional + +- `region` (String) Geographical region where the addon will be deployed (when relevant) + ### Read-Only - `configurations` (Map of String, Sensitive) Any configuration exposed by the addon diff --git a/docs/resources/cellar.md b/docs/resources/cellar.md index 62627f4..f709d5e 100644 --- a/docs/resources/cellar.md +++ b/docs/resources/cellar.md @@ -21,6 +21,9 @@ See [product specification](https://www.clever-cloud.com/doc/deploy/addon/cellar ### Required - `name` (String) Name of the Cellar + +### Optional + - `region` (String) Geographical region where the data will be stored ### Read-Only diff --git a/docs/resources/java_war.md b/docs/resources/java_war.md index 911a665..27f3064 100644 --- a/docs/resources/java_war.md +++ b/docs/resources/java_war.md @@ -86,7 +86,6 @@ resource "clevercloud_java_war" "myapp" { - `max_instance_count` (Number) Maximum instance count, if different from min value, enable autoscaling - `min_instance_count` (Number) Minimum instance count - `name` (String) Application name -- `region` (String) Geographical region where the database will be deployed - `smallest_flavor` (String) Smallest instance flavor ### Optional @@ -102,6 +101,7 @@ Can be either app_xxx or postgres_yyy ID format - `hooks` (Block, Optional) (see [below for nested schema](#nestedblock--hooks)) - `java_version` (String) Choose the JVM version between 7 to 17 for OpenJDK or graalvm-ce for GraalVM 21.0.0.2 (based on OpenJDK 11.0). - `redirect_https` (Boolean) Redirect client from plain to TLS port +- `region` (String) Geographical region where the database will be deployed - `sticky_sessions` (Boolean) Enable sticky sessions, use it when your client sessions are instances scoped ### Read-Only diff --git a/docs/resources/materia_kv.md b/docs/resources/materia_kv.md index 5c7f581..9b4a84e 100644 --- a/docs/resources/materia_kv.md +++ b/docs/resources/materia_kv.md @@ -18,6 +18,9 @@ Manage Materia KV databases ### Required - `name` (String) Name of the service + +### Optional + - `region` (String) Geographical region where the data will be stored ### Read-Only diff --git a/docs/resources/mongodb.md b/docs/resources/mongodb.md index 7e84cba..f2157fc 100644 --- a/docs/resources/mongodb.md +++ b/docs/resources/mongodb.md @@ -22,6 +22,9 @@ See [product specification](https://www.clever-cloud.com/fr/product/mongodb/). - `name` (String) Name of the service - `plan` (String) Database size and spec + +### Optional + - `region` (String) Geographical region where the data will be stored ### Read-Only diff --git a/docs/resources/nodejs.md b/docs/resources/nodejs.md index 0c39431..4354313 100644 --- a/docs/resources/nodejs.md +++ b/docs/resources/nodejs.md @@ -86,7 +86,6 @@ resource "clevercloud_nodejs" "myapp" { - `max_instance_count` (Number) Maximum instance count, if different from min value, enable autoscaling - `min_instance_count` (Number) Minimum instance count - `name` (String) Application name -- `region` (String) Geographical region where the database will be deployed - `smallest_flavor` (String) Smallest instance flavor ### Optional @@ -103,6 +102,7 @@ Can be either app_xxx or postgres_yyy ID format - `hooks` (Block, Optional) (see [below for nested schema](#nestedblock--hooks)) - `package_manager` (String) Either npm, npm-ci, yarn, yarn2 or custom - `redirect_https` (Boolean) Redirect client from plain to TLS port +- `region` (String) Geographical region where the database will be deployed - `registry` (String) The host of your private repository, available values: github or the registry host - `registry_token` (String, Sensitive) Private repository token - `start_script` (String) Set custom start script, instead of `npm start` diff --git a/docs/resources/php.md b/docs/resources/php.md index df55be4..e443fac 100644 --- a/docs/resources/php.md +++ b/docs/resources/php.md @@ -24,7 +24,6 @@ See [PHP product](https://www.clever-cloud.com/doc/getting-started/by-language/p - `max_instance_count` (Number) Maximum instance count, if different from min value, enable autoscaling - `min_instance_count` (Number) Minimum instance count - `name` (String) Application name -- `region` (String) Geographical region where the database will be deployed - `smallest_flavor` (String) Smallest instance flavor ### Optional @@ -42,6 +41,7 @@ Can be either app_xxx or postgres_yyy ID format - `php_version` (String) PHP version (Default: 8) - `redirect_https` (Boolean) Redirect client from plain to TLS port - `redis_sessions` (Boolean) Use a linked Redis instance to store sessions (Default: false) +- `region` (String) Geographical region where the database will be deployed - `sticky_sessions` (Boolean) Enable sticky sessions, use it when your client sessions are instances scoped - `webroot` (String) Define the DocumentRoot of your project (default: ".") diff --git a/docs/resources/postgresql.md b/docs/resources/postgresql.md index 9adab9c..eaaa343 100644 --- a/docs/resources/postgresql.md +++ b/docs/resources/postgresql.md @@ -30,6 +30,9 @@ resource "clevercloud_postgresql" "postgresql_database" { - `name` (String) Name of the service - `plan` (String) Database size and spec + +### Optional + - `region` (String) Geographical region where the data will be stored ### Read-Only diff --git a/docs/resources/python.md b/docs/resources/python.md index 6bca66b..7d5055b 100644 --- a/docs/resources/python.md +++ b/docs/resources/python.md @@ -86,7 +86,6 @@ resource "clevercloud_python" "myapp" { - `max_instance_count` (Number) Maximum instance count, if different from min value, enable autoscaling - `min_instance_count` (Number) Minimum instance count - `name` (String) Application name -- `region` (String) Geographical region where the database will be deployed - `smallest_flavor` (String) Smallest instance flavor ### Optional @@ -103,6 +102,7 @@ Can be either app_xxx or postgres_yyy ID format - `pip_requirements` (String) Define a custom requirements.txt file (default: requirements.txt) - `python_version` (String) Python version >= 2.7 - `redirect_https` (Boolean) Redirect client from plain to TLS port +- `region` (String) Geographical region where the database will be deployed - `sticky_sessions` (Boolean) Enable sticky sessions, use it when your client sessions are instances scoped ### Read-Only diff --git a/docs/resources/scala.md b/docs/resources/scala.md index 52ceaba..6020896 100644 --- a/docs/resources/scala.md +++ b/docs/resources/scala.md @@ -86,7 +86,6 @@ resource "clevercloud_scala" "myapp" { - `max_instance_count` (Number) Maximum instance count, if different from min value, enable autoscaling - `min_instance_count` (Number) Minimum instance count - `name` (String) Application name -- `region` (String) Geographical region where the database will be deployed - `smallest_flavor` (String) Smallest instance flavor ### Optional @@ -101,6 +100,7 @@ Can be either app_xxx or postgres_yyy ID format - `environment` (Map of String, Sensitive) Environment variables injected into the application - `hooks` (Block, Optional) (see [below for nested schema](#nestedblock--hooks)) - `redirect_https` (Boolean) Redirect client from plain to TLS port +- `region` (String) Geographical region where the database will be deployed - `sticky_sessions` (Boolean) Enable sticky sessions, use it when your client sessions are instances scoped ### Read-Only diff --git a/docs/resources/static.md b/docs/resources/static.md index e4a2aa9..3c26190 100644 --- a/docs/resources/static.md +++ b/docs/resources/static.md @@ -86,7 +86,6 @@ resource "clevercloud_static" "myapp" { - `max_instance_count` (Number) Maximum instance count, if different from min value, enable autoscaling - `min_instance_count` (Number) Minimum instance count - `name` (String) Application name -- `region` (String) Geographical region where the database will be deployed - `smallest_flavor` (String) Smallest instance flavor ### Optional @@ -101,6 +100,7 @@ Can be either app_xxx or postgres_yyy ID format - `environment` (Map of String, Sensitive) Environment variables injected into the application - `hooks` (Block, Optional) (see [below for nested schema](#nestedblock--hooks)) - `redirect_https` (Boolean) Redirect client from plain to TLS port +- `region` (String) Geographical region where the database will be deployed - `sticky_sessions` (Boolean) Enable sticky sessions, use it when your client sessions are instances scoped ### Read-Only diff --git a/pkg/application/creation.go b/pkg/application/creation.go index 85a2686..705b446 100644 --- a/pkg/application/creation.go +++ b/pkg/application/creation.go @@ -2,6 +2,7 @@ package application import ( "context" + "fmt" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -39,7 +40,7 @@ func CreateApp(ctx context.Context, req CreateReq) (*CreateRes, diag.Diagnostics appRes := tmp.CreateApp(ctx, req.Client, req.Organization, req.Application) if appRes.HasError() { diags.AddError("failed to create application", appRes.Error().Error()) - tflog.Error(ctx, "failed to create app", map[string]interface{}{"error": appRes.Error().Error()}) + tflog.Error(ctx, "failed to create app", map[string]interface{}{"error": appRes.Error().Error(), "payload": fmt.Sprintf("%+v", req.Application)}) return nil, diags } diff --git a/pkg/attributes/common.go b/pkg/attributes/common.go index 7e773e3..7584c09 100644 --- a/pkg/attributes/common.go +++ b/pkg/attributes/common.go @@ -6,6 +6,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/schema/validator" + + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" "go.clever-cloud.com/terraform-provider/pkg" ) @@ -44,8 +46,9 @@ var runtimeCommon = map[string]schema.Attribute{ MarkdownDescription: "Use dedicated instance with given flavor for build step", }, "region": schema.StringAttribute{ - Required: true, - // Default: stringdefault.StaticString("par"), // TODO default value must be computed before apply + Optional: true, + Computed: true, + Default: stringdefault.StaticString("par"), MarkdownDescription: "Geographical region where the database will be deployed", }, "sticky_sessions": schema.BoolAttribute{ diff --git a/pkg/resources/addon/resource_addon_schema.go b/pkg/resources/addon/resource_addon_schema.go index d2f3c7d..0666e42 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" ) @@ -28,9 +29,14 @@ func (r ResourceAddon) Schema(_ context.Context, req resource.SchemaRequest, res MarkdownDescription: resourcePostgresqlDoc, Attributes: map[string]schema.Attribute{ // 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)"}, //TODO , Default: stringdefault.StaticString("par")}, + "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the addon"}, + "plan": schema.StringAttribute{Required: true, MarkdownDescription: "billing plan"}, + "region": schema.StringAttribute{ + Optional: true, + Computed: true, + Default: stringdefault.StaticString("par"), + MarkdownDescription: "Geographical region where the addon will be deployed (when relevant)", + }, "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 2849006..81755d1 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" ) @@ -29,8 +30,13 @@ func (r ResourceCellar) Schema(_ context.Context, req resource.SchemaRequest, re MarkdownDescription: resourceCellarDoc, 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"}, // TODO, Default: stringdefault.StaticString("par")}, + "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the Cellar"}, + "region": schema.StringAttribute{ + Optional: true, + Computed: true, + 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_schema.go b/pkg/resources/materiakv/resource_materiakv_schema.go index 009f083..d8aab4c 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" ) @@ -28,8 +29,13 @@ 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"}, - "region": schema.StringAttribute{Required: true, MarkdownDescription: "Geographical region where the data will be stored"}, // TODO, Default: stringdefault.StaticString("par")}, + "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the service"}, + "region": schema.StringAttribute{ + Optional: true, + Computed: true, + Default: stringdefault.StaticString("par"), + MarkdownDescription: "Geographical region where the data will be stored", + }, // 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_schema.go b/pkg/resources/mongodb/resource_mongodb_schema.go index 3060db9..f8cbb30 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" ) @@ -30,9 +31,14 @@ 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"}, - "region": schema.StringAttribute{Required: true, MarkdownDescription: "Geographical region where the data will be stored"}, // TODO, Default: stringdefault.StaticString("par")}, + "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the service"}, + "plan": schema.StringAttribute{Required: true, MarkdownDescription: "Database size and spec"}, + "region": schema.StringAttribute{ + Optional: true, + Computed: true, + Default: stringdefault.StaticString("par"), + MarkdownDescription: "Geographical region where the data will be stored", + }, // provider "id": schema.StringAttribute{Computed: true, MarkdownDescription: "Generated unique identifier"}, diff --git a/pkg/resources/nodejs/resource_nodejs_test.go b/pkg/resources/nodejs/resource_nodejs_test.go index 04a6ffc..6748817 100644 --- a/pkg/resources/nodejs/resource_nodejs_test.go +++ b/pkg/resources/nodejs/resource_nodejs_test.go @@ -135,6 +135,9 @@ func TestAccNodejs_basic(t *testing.T) { if !app.StickySessions { return assertError("expect option to be set", "sticky_sessions", app.StickySessions) } + if app.Zone != "par" { + return assertError("expect region to be 'par'", "region", app.Zone) + } appEnvRes := tmp.GetAppEnv(ctx, cc, org, id) if appEnvRes.HasError() { diff --git a/pkg/resources/postgresql/resource_postgresql_schema.go b/pkg/resources/postgresql/resource_postgresql_schema.go index f7a3917..5ef5624 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" ) @@ -31,9 +32,14 @@ func (r ResourcePostgreSQL) Schema(_ context.Context, req resource.SchemaRequest MarkdownDescription: resourcePostgresqlDoc, 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"}, - "region": schema.StringAttribute{Required: true, MarkdownDescription: "Geographical region where the data will be stored"}, // TODO, Default: stringdefault.StaticString("par")}, + "name": schema.StringAttribute{Required: true, MarkdownDescription: "Name of the service"}, + "plan": schema.StringAttribute{Required: true, MarkdownDescription: "Database size and spec"}, + "region": schema.StringAttribute{ + Optional: true, + Computed: true, + Default: stringdefault.StaticString("par"), + MarkdownDescription: "Geographical region where the data will be stored", + }, // provider "id": schema.StringAttribute{Computed: true, MarkdownDescription: "Generated unique identifier"},