Skip to content

Commit

Permalink
fix: remove all hardcoded region parameters + default="par"
Browse files Browse the repository at this point in the history
  • Loading branch information
LeCrabe authored and miton18 committed Jun 10, 2024
1 parent 00264a7 commit 80b0224
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
5 changes: 3 additions & 2 deletions pkg/attributes/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/addon/resource_addon_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/cellar/resource_cellar_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/materiakv/resource_materiakv_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pkg/resources/materiakv/resource_materiakv_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"`
}

Expand All @@ -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"},
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/mongodb/resource_mongodb_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions pkg/resources/mongodb/resource_mongodb_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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"
)

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"`
Expand All @@ -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"},
Expand Down
3 changes: 2 additions & 1 deletion pkg/resources/postgresql/resource_postgresql_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit 80b0224

Please sign in to comment.