Skip to content

Commit

Permalink
chore: Creates base resource schema for advancedclustertpf (#2691)
Browse files Browse the repository at this point in the history
* add data source tests

* call conversion.UpdateSchemaDescription

* remove Description using regexp in VsCode:  ^(?!.*MarkdownDescription:).*Description:.*\n

* required attributes in data source test

* use resource model

* PoC model

* codegen config for advanced_cluster

* apply latest codegen

* make codegen the main schema file

* change HC model names

* use schemas as in current resource

* simplify data sources

* mongo db version error comment

* fix build issues

* delete CustomType generated by HC tool

* fix schema

* adjust test

* advanced_configuration
  • Loading branch information
lantoli authored Oct 31, 2024
1 parent d19e8b9 commit cae0f37
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 12,801 deletions.
2 changes: 2 additions & 0 deletions internal/service/advancedclustertpf/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
)

Expand All @@ -26,6 +27,7 @@ type ds struct {

func (d *ds) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = DataSourceSchema(ctx)
conversion.UpdateSchemaDescription(&resp.Schema)
}

func (d *ds) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
Expand Down
716 changes: 7 additions & 709 deletions internal/service/advancedclustertpf/data_source_schema.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/service/advancedclustertpf/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"go.mongodb.org/atlas-sdk/v20241023001/admin"
)

func NewTFModel(ctx context.Context, apiResp *admin.ClusterDescription20240805) (*TFModel, diag.Diagnostics) {
return &TFModel{}, nil
func NewTFModel(ctx context.Context, apiResp *admin.ClusterDescription20240805, diags *diag.Diagnostics) *TFModel {
return &TFModel{}
}

func NewAtlasReq(ctx context.Context, plan *TFModel) (*admin.ClusterDescription20240805, diag.Diagnostics) {
Expand Down
2 changes: 2 additions & 0 deletions internal/service/advancedclustertpf/plural_data_source.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/datasource"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
)

Expand All @@ -25,6 +26,7 @@ type pluralDS struct {

func (d *pluralDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = PluralDataSourceSchema(ctx)
conversion.UpdateSchemaDescription(&resp.Schema)
}

func (d *pluralDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
Expand Down
2,947 changes: 12 additions & 2,935 deletions internal/service/advancedclustertpf/plural_data_source_schema.go

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions internal/service/advancedclustertpf/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
)

Expand All @@ -24,16 +24,20 @@ type rs struct {
}

func (r *rs) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{} // TEMPORARY: empty schema, change later to ResourceSchema(ctx)
resp.Schema = ResourceSchema(ctx)
conversion.UpdateSchemaDescription(&resp.Schema)
}

func (r *rs) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
var tfModel struct{} // TEMPORARY: empty model
var tfModel TFModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &tfModel)...)
if resp.Diagnostics.HasError() {
return
}
var tfNewModel struct{} // TEMPORARY: empty model
tfNewModel := NewTFModel(ctx, nil, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
resp.Diagnostics.Append(resp.State.Set(ctx, tfNewModel)...)
}

Expand Down
9,599 changes: 473 additions & 9,126 deletions internal/service/advancedclustertpf/resource_schema.go

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion internal/service/advancedclustertpf/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,26 @@ func TestAccAdvancedCluster_basic(t *testing.T) {
}

func configBasic() string {
return `
return `
/*
// TODO: resource not used yet until we have a fake model so test can run
resource "mongodbatlas_advanced_cluster" "test" {
project_id = "111111111111111111111111"
name = "test"
cluster_type = "TYPE"
}
*/
data "mongodbatlas_advanced_cluster" "test" {
project_id = "111111111111111111111111"
name = "test"
// depends_on = [mongodbatlas_advanced_cluster.test]
}
data "mongodbatlas_advanced_clusters" "tests" {
project_id = "111111111111111111111111"
// depends_on = [mongodbatlas_advanced_cluster.test]
}
`
}

This file was deleted.

31 changes: 28 additions & 3 deletions tools/codegen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resources:
group_id: project_id
ignores: ["links"]
timeouts: ["create", "update", "delete"]

# overrides:
# project_id:
# plan_modifiers: [{
Expand All @@ -25,12 +25,12 @@ resources:
# ],
# definition: "stringvalidator.ConflictsWith(path.MatchRoot(\"name\"))"
# }]

# prefix_path:
# computability:
# optional: true
# computed: true

search_deployment:
read:
path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/deployment
Expand All @@ -43,3 +43,28 @@ resources:
group_id: project_id
ignores: ["links"]
timeouts: ["create", "update", "delete"]

advanced_cluster:
read:
path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}
method: GET
create:
path: /api/atlas/v2/groups/{groupId}/clusters
method: POST
schema:
aliases:
group_id: project_id
ignores: ["links"]
timeouts: ["create", "update", "delete"]

# advanced_configuration attribute in advanced_cluster
advanced_cluster_process_args:
read:
path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/processArgs
method: GET
create:
path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/processArgs
method: PATCH
schema:
aliases:
group_id: project_id

0 comments on commit cae0f37

Please sign in to comment.