Skip to content

Commit

Permalink
docs: new mongodb docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeCrabe committed May 2, 2024
1 parent 77790b0 commit 2d7eed2
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 64 deletions.
34 changes: 34 additions & 0 deletions docs/resources/mongodb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "clevercloud_mongodb Resource - terraform-provider-clevercloud"
subcategory: ""
description: |-
Manage MongoDB https://www.mongodb.com/ product.
See product specification https://www.clever-cloud.com/fr/product/mongodb/.
---

# clevercloud_mongodb (Resource)

Manage [MongoDB](https://www.mongodb.com/) product.

See [product specification](https://www.clever-cloud.com/fr/product/mongodb/).



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) Name of the service
- `plan` (String) Database size and spec

### Read-Only

- `creation_date` (Number) Date of database creation
- `host` (String) Database host, used to connect to
- `id` (String) Generated unique identifier
- `password` (String) Login password
- `port` (Number) Database port
- `token` (String) Token to authenticate
- `user` (String) Login username
4 changes: 2 additions & 2 deletions pkg/provider/impl/provider_configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
var config ProviderData

tflog.Info(ctx, "configure provider...")
tflog.Debug(ctx, "configure provider...")

diags := req.Config.Get(ctx, &config)
resp.Diagnostics.Append(diags...)
Expand Down Expand Up @@ -59,5 +59,5 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
resp.DataSourceData = p
resp.ResourceData = p

tflog.Info(ctx, "provider configured")
tflog.Debug(ctx, "provider configured")
}
6 changes: 3 additions & 3 deletions pkg/resources/addon/resource_addon_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// Weird behaviour, but TF can ask for a Resource without having configured a Provider (maybe for Meta and Schema)
// So we need to handle the case there is no ProviderData
func (r *ResourceAddon) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "ResourceAddon.Configure()")
tflog.Debug(ctx, "ResourceAddon.Configure()")

// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (r *ResourceAddon) Create(ctx context.Context, req resource.CreateRequest,

// Read resource information
func (r *ResourceAddon) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
tflog.Info(ctx, "Addon READ", map[string]interface{}{"request": req})
tflog.Debug(ctx, "Addon READ", map[string]interface{}{"request": req})

var ad Addon
diags := req.State.Get(ctx, &ad)
Expand Down Expand Up @@ -168,7 +168,7 @@ func (r *ResourceAddon) Delete(ctx context.Context, req resource.DeleteRequest,
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "Addon DELETE", map[string]interface{}{"addon": ad})
tflog.Debug(ctx, "Addon DELETE", map[string]interface{}{"addon": ad})

res := tmp.DeleteAddon(ctx, r.cc, r.org, ad.ID.ValueString())
if res.IsNotFoundError() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/resources/cellar/bucket/resource_cellar_bucket_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// Weird behaviour, but TF can ask for a Resource without having configured a Provider (maybe for Meta and Schema)
// So we need to handle the case there is no ProviderData
func (r *ResourceCellarBucket) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "ResourceCellarBucket.Configure()")
tflog.Debug(ctx, "ResourceCellarBucket.Configure()")

// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
Expand Down Expand Up @@ -62,7 +62,7 @@ func (r *ResourceCellarBucket) Create(ctx context.Context, req resource.CreateRe

// Read resource information
func (r *ResourceCellarBucket) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
tflog.Info(ctx, "Cellar READ", map[string]interface{}{"request": req})
tflog.Debug(ctx, "Cellar READ", map[string]interface{}{"request": req})

var cellar CellarBucket
resp.Diagnostics.Append(req.State.Get(ctx, &cellar)...)
Expand Down Expand Up @@ -91,7 +91,7 @@ func (r *ResourceCellarBucket) Delete(ctx context.Context, req resource.DeleteRe
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "CELLAR BUCKET DELETE", map[string]interface{}{"bucket": bucket})
tflog.Debug(ctx, "CELLAR BUCKET DELETE", map[string]interface{}{"bucket": bucket})

cellarEnvRes := tmp.GetAddonEnv(ctx, r.cc, r.org, bucket.CellarID.ValueString())
if cellarEnvRes.HasError() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/resources/cellar/bucket/resource_cellar_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestAccCellarBucket_basic(t *testing.T) {
}

cellar = res.Payload()
fmt.Print(cellar)

defer func() {
rmRes := tmp.DeleteAddon(ctx, cc, org, cellar.ID)
Expand Down Expand Up @@ -83,7 +82,7 @@ func TestAccCellarBucket_basic(t *testing.T) {
}},
CheckDestroy: func(state *terraform.State) error {
for resourceName, resourceState := range state.RootModule().Resources {
tflog.Info(ctx, "TEST DESTROY", map[string]interface{}{"bucket": resourceState})
tflog.Debug(ctx, "TEST DESTROY", map[string]interface{}{"bucket": resourceState})
res := tmp.GetAddonEnv(context.Background(), cc, org, cellar.ID) // TODO: resourceState.Primary.ID)
if res.IsNotFoundError() {
continue
Expand Down
8 changes: 4 additions & 4 deletions pkg/resources/cellar/resource_cellar_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// Weird behaviour, but TF can ask for a Resource without having configured a Provider (maybe for Meta and Schema)
// So we need to handle the case there is no ProviderData
func (r *ResourceCellar) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "ResourceCellar.Configure()")
tflog.Debug(ctx, "ResourceCellar.Configure()")

// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
Expand Down Expand Up @@ -66,7 +66,7 @@ func (r *ResourceCellar) Create(ctx context.Context, req resource.CreateRequest,
}
addonRes := res.Payload()

tflog.Info(ctx, "get addon env vars", map[string]interface{}{"cellar": addonRes.RealID})
tflog.Debug(ctx, "get addon env vars", map[string]interface{}{"cellar": addonRes.RealID})
envRes := tmp.GetAddonEnv(ctx, r.cc, r.org, addonRes.RealID)
if envRes.HasError() {
resp.Diagnostics.AddError("failed to get addon env vars", envRes.Error().Error())
Expand All @@ -86,7 +86,7 @@ func (r *ResourceCellar) Create(ctx context.Context, req resource.CreateRequest,

// Read resource information
func (r *ResourceCellar) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
tflog.Info(ctx, "Cellar READ", map[string]interface{}{"request": req})
tflog.Debug(ctx, "Cellar READ", map[string]interface{}{"request": req})

var cellar Cellar
resp.Diagnostics.Append(req.State.Get(ctx, &cellar)...)
Expand Down Expand Up @@ -115,7 +115,7 @@ func (r *ResourceCellar) Delete(ctx context.Context, req resource.DeleteRequest,
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "CELLAR DELETE", map[string]interface{}{"cellar": cellar})
tflog.Debug(ctx, "CELLAR DELETE", map[string]interface{}{"cellar": cellar})

addonRes := tmp.GetAddon(ctx, r.cc, r.org, cellar.ID.ValueString())
if addonRes.IsNotFoundError() {
Expand Down
8 changes: 4 additions & 4 deletions pkg/resources/java/resource_java_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// Weird behaviour, but TF can ask for a Resource without having configured a Provider (maybe for Meta and Schema)
// So we need to handle the case there is no ProviderData
func (r *ResourceJava) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "ResourceJava.Configure()")
tflog.Debug(ctx, "ResourceJava.Configure()")

// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
Expand All @@ -29,7 +29,7 @@ func (r *ResourceJava) Configure(ctx context.Context, req resource.ConfigureRequ
r.org = provider.Organization()
}

tflog.Info(ctx, "AFTER CONFIGURED", map[string]interface{}{"cc": r.cc == nil, "org": r.org})
tflog.Debug(ctx, "AFTER CONFIGURED", map[string]interface{}{"cc": r.cc == nil, "org": r.org})
}

// Create a new resource
Expand Down Expand Up @@ -88,7 +88,7 @@ func (r *ResourceJava) Create(ctx context.Context, req resource.CreateRequest, r
return
}

tflog.Info(ctx, "BUILD FLAVOR RES"+createAppRes.Application.BuildFlavor.Name, map[string]interface{}{})
tflog.Debug(ctx, "BUILD FLAVOR RES"+createAppRes.Application.BuildFlavor.Name, map[string]interface{}{})
plan.ID = pkg.FromStr(createAppRes.Application.ID)
plan.DeployURL = pkg.FromStr(createAppRes.Application.DeployURL)
plan.VHost = pkg.FromStr(createAppRes.Application.Vhosts[0].Fqdn)
Expand Down Expand Up @@ -186,7 +186,7 @@ func (r *ResourceJava) Delete(ctx context.Context, req resource.DeleteRequest, r
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "JAVA DELETE", map[string]interface{}{"state": state})
tflog.Debug(ctx, "JAVA DELETE", map[string]interface{}{"state": state})

res := tmp.DeleteApp(ctx, r.cc, r.org, state.ID.ValueString())
if res.IsNotFoundError() {
Expand Down
12 changes: 6 additions & 6 deletions pkg/resources/materiakv/resource_materiakv_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// Weird behaviour, but TF can ask for a Resource without having configured a Provider (maybe for Meta and Schema)
// So we need to handle the case there is no ProviderData
func (r *ResourceMateriaKV) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "ResourceMateriaKV.Configure()")
tflog.Debug(ctx, "ResourceMateriaKV.Configure()")

// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
Expand Down Expand Up @@ -83,7 +83,7 @@ func (r *ResourceMateriaKV) Create(ctx context.Context, req resource.CreateReque
}

kvInfo := kvInfoRes.Payload()
tflog.Info(ctx, "API response", map[string]interface{}{
tflog.Debug(ctx, "API response", map[string]interface{}{
"payload": fmt.Sprintf("%+v", kvInfo),
})
kv.Host = pkg.FromStr(kvInfo.Host)
Expand All @@ -98,7 +98,7 @@ func (r *ResourceMateriaKV) Create(ctx context.Context, req resource.CreateReque

// Read resource information
func (r *ResourceMateriaKV) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
tflog.Info(ctx, "MateriaKV READ", map[string]interface{}{"request": req})
tflog.Debug(ctx, "MateriaKV READ", map[string]interface{}{"request": req})

var kv MateriaKV
diags := req.State.Get(ctx, &kv)
Expand Down Expand Up @@ -130,8 +130,8 @@ func (r *ResourceMateriaKV) Read(ctx context.Context, req resource.ReadRequest,
return
}

tflog.Info(ctx, "STATE", map[string]interface{}{"kv": kv})
tflog.Info(ctx, "API", map[string]interface{}{"kv": addonKV})
tflog.Debug(ctx, "STATE", map[string]interface{}{"kv": kv})
tflog.Debug(ctx, "API", map[string]interface{}{"kv": addonKV})
kv.Host = pkg.FromStr(addonKV.Host)
kv.Port = pkg.FromI(int64(addonKV.Port))
kv.Token = pkg.FromStr(addonKV.Token)
Expand All @@ -157,7 +157,7 @@ func (r *ResourceMateriaKV) Delete(ctx context.Context, req resource.DeleteReque
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "MateriaKV DELETE", map[string]interface{}{"kv": kv})
tflog.Debug(ctx, "MateriaKV DELETE", map[string]interface{}{"kv": kv})

res := tmp.DeleteAddon(ctx, r.cc, r.org, kv.ID.ValueString())
if res.IsNotFoundError() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/materiakv/resource_materiakv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAccMateriaKV_basic(t *testing.T) {
cc := client.New(client.WithAutoOauthConfig())
org := os.Getenv("ORGANISATION")
providerBlock := helper.NewProvider("clevercloud").SetOrganisation(org).String()
materiakvBlock := helper.NewRessource("clevercloud_materiadb_kv", rName, helper.SetKeyValues(map[string]any{"name": rName})).String()
materiakvBlock := helper.NewRessource("clevercloud_materiadb_kv", rName).SetOneValue("name", rName).String()

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down
20 changes: 12 additions & 8 deletions pkg/resources/mongodb/resource_mongodb_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mongodb
import (
"context"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand All @@ -16,7 +17,7 @@ import (
// Weird behaviour, but TF can ask for a Resource without having configured a Provider (maybe for Meta and Schema)
// So we need to handle the case there is no ProviderData
func (r *ResourceMongoDB) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "ResourceMongoDB.Configure()")
tflog.Debug(ctx, "ResourceMongoDB.Configure()")

// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
Expand Down Expand Up @@ -47,10 +48,9 @@ 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())
if plan.ID == "" {
resp.Diagnostics.AddError("failed to find plan", "expect:, got: "+mg.Plan.String())
resp.Diagnostics.AddError("failed to find plan", "expect: "+strings.Join(pkg.ProviderPlansAsList(prov), ", ")+", got: "+mg.Plan.String())
return
}

Expand Down Expand Up @@ -83,12 +83,14 @@ func (r *ResourceMongoDB) Create(ctx context.Context, req resource.CreateRequest
}

addonMG := mgInfoRes.Payload()
tflog.Info(ctx, "API response", map[string]interface{}{
tflog.Debug(ctx, "API response", map[string]interface{}{
"payload": fmt.Sprintf("%+v", addonMG),
})
mg.Host = pkg.FromStr(addonMG.Host)
mg.Port = pkg.FromI(int64(addonMG.Port))
mg.Token = pkg.FromStr(addonMG.Token)
mg.User = pkg.FromStr(addonMG.User)
mg.Password = pkg.FromStr(addonMG.Password)

resp.Diagnostics.Append(resp.State.Set(ctx, mg)...)
if resp.Diagnostics.HasError() {
Expand All @@ -98,7 +100,7 @@ func (r *ResourceMongoDB) Create(ctx context.Context, req resource.CreateRequest

// Read resource information
func (r *ResourceMongoDB) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
tflog.Info(ctx, "MongoDB READ", map[string]interface{}{"request": req})
tflog.Debug(ctx, "MongoDB READ", map[string]interface{}{"request": req})

var mg MongoDB
diags := req.State.Get(ctx, &mg)
Expand Down Expand Up @@ -130,11 +132,13 @@ func (r *ResourceMongoDB) Read(ctx context.Context, req resource.ReadRequest, re
return
}

tflog.Info(ctx, "STATE", map[string]interface{}{"mg": mg})
tflog.Info(ctx, "API", map[string]interface{}{"mg": addonMG})
tflog.Debug(ctx, "STATE", map[string]interface{}{"mg": mg})
tflog.Debug(ctx, "API", map[string]interface{}{"mg": addonMG})
mg.Host = pkg.FromStr(addonMG.Host)
mg.Port = pkg.FromI(int64(addonMG.Port))
mg.Token = pkg.FromStr(addonMG.Token)
mg.User = pkg.FromStr(addonMG.User)
mg.Password = pkg.FromStr(addonMG.Password)

diags = resp.State.Set(ctx, mg)
resp.Diagnostics.Append(diags...)
Expand All @@ -157,7 +161,7 @@ func (r *ResourceMongoDB) Delete(ctx context.Context, req resource.DeleteRequest
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "MongoDB DELETE", map[string]interface{}{"mg": mg})
tflog.Debug(ctx, "MongoDB DELETE", map[string]interface{}{"mg": mg})

res := tmp.DeleteAddon(ctx, r.cc, r.org, mg.ID.ValueString())
if res.IsNotFoundError() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/resources/mongodb/resource_mongodb_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type MongoDB struct {
Host types.String `tfsdk:"host"`
Port types.Int64 `tfsdk:"port"`
Token types.String `tfsdk:"token"`
User types.String `tfsdk:"user"`
Password types.String `tfsdk:"password"`
}

//go:embed resource_mongodb.md
Expand All @@ -37,6 +39,8 @@ func (r ResourceMongoDB) Schema(_ context.Context, req resource.SchemaRequest, r
"host": schema.StringAttribute{Computed: true, MarkdownDescription: "Database host, used to connect to"},
"port": schema.Int64Attribute{Computed: true, MarkdownDescription: "Database port"},
"token": schema.StringAttribute{Computed: true, MarkdownDescription: "Token to authenticate"},
"user": schema.StringAttribute{Computed: true, MarkdownDescription: "Login username"},
"password": schema.StringAttribute{Computed: true, MarkdownDescription: "Login password"},
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/resources/nodejs/resource_nodejs_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// Weird behaviour, but TF can ask for a Resource without having configured a Provider (maybe for Meta and Schema)
// So we need to handle the case there is no ProviderData
func (r *ResourceNodeJS) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
tflog.Info(ctx, "ResourceNodeJS.Configure()")
tflog.Debug(ctx, "ResourceNodeJS.Configure()")

// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
Expand All @@ -28,7 +28,7 @@ func (r *ResourceNodeJS) Configure(ctx context.Context, req resource.ConfigureRe
r.org = provider.Organization()
}

tflog.Info(ctx, "AFTER CONFIGURED", map[string]interface{}{"cc": r.cc == nil, "org": r.org})
tflog.Debug(ctx, "AFTER CONFIGURED", map[string]interface{}{"cc": r.cc == nil, "org": r.org})
}

// Create a new resource
Expand Down Expand Up @@ -106,7 +106,7 @@ func (r *ResourceNodeJS) Create(ctx context.Context, req resource.CreateRequest,

// Read resource information
func (r *ResourceNodeJS) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
tflog.Info(ctx, "NodeJS READ", map[string]interface{}{"request": req})
tflog.Debug(ctx, "NodeJS READ", map[string]interface{}{"request": req})

var app NodeJS
diags := req.State.Get(ctx, &app)
Expand Down Expand Up @@ -163,7 +163,7 @@ func (r *ResourceNodeJS) Delete(ctx context.Context, req resource.DeleteRequest,
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "NodeJS DELETE", map[string]interface{}{"app": app})
tflog.Debug(ctx, "NodeJS DELETE", map[string]interface{}{"app": app})

res := tmp.DeleteApp(ctx, r.cc, r.org, app.ID.ValueString())
if res.IsNotFoundError() {
Expand Down
Loading

0 comments on commit 2d7eed2

Please sign in to comment.