-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Adjusts search_deployment schema definitions with structure of new schema scaffolding command #1830
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package searchdeployment | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
func DataSourceSchema(ctx context.Context) schema.Schema { | ||
return schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Unique 24-hexadecimal digit string that identifies the search deployment.", | ||
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies the search deployment.", | ||
}, | ||
"cluster_name": schema.StringAttribute{ | ||
Required: true, | ||
Description: "Label that identifies the cluster to return the search nodes for.", | ||
MarkdownDescription: "Label that identifies the cluster to return the search nodes for.", | ||
}, | ||
"project_id": schema.StringAttribute{ | ||
Required: true, | ||
Description: "Unique 24-hexadecimal digit string that identifies your project.", | ||
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies your project.", | ||
}, | ||
"specs": schema.ListNestedAttribute{ | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"instance_size": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Hardware specification for the search node instance sizes.", | ||
MarkdownDescription: "Hardware specification for the search node instance sizes.", | ||
}, | ||
"node_count": schema.Int64Attribute{ | ||
Computed: true, | ||
Description: "Number of search nodes in the cluster.", | ||
MarkdownDescription: "Number of search nodes in the cluster.", | ||
}, | ||
}, | ||
}, | ||
Description: "List of settings that configure the search nodes for your cluster.", | ||
MarkdownDescription: "List of settings that configure the search nodes for your cluster.", | ||
}, | ||
"state_name": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Human-readable label that indicates the current operating condition of this search deployment.", | ||
MarkdownDescription: "Human-readable label that indicates the current operating condition of this search deployment.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type TFSearchDeploymentDSModel struct { | ||
ID types.String `tfsdk:"id"` | ||
ClusterName types.String `tfsdk:"cluster_name"` | ||
ProjectID types.String `tfsdk:"project_id"` | ||
Specs types.List `tfsdk:"specs"` | ||
StateName types.String `tfsdk:"state_name"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package searchdeployment | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" | ||
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
func ResourceSchema(ctx context.Context) schema.Schema { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is creating the schema in a separate file a new convention in the repo? Is the what the scaffolding command will do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct, scaffolding command will be adjusted to this convention of having the schema and tf models in separate files. |
||
return schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Unique 24-hexadecimal digit string that identifies the search deployment.", | ||
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies the search deployment.", | ||
}, | ||
"cluster_name": schema.StringAttribute{ | ||
Required: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.RequiresReplace(), | ||
}, | ||
Description: "Label that identifies the cluster to return the search nodes for.", | ||
MarkdownDescription: "Label that identifies the cluster to return the search nodes for.", | ||
}, | ||
"project_id": schema.StringAttribute{ | ||
Required: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.RequiresReplace(), | ||
}, | ||
Description: "Unique 24-hexadecimal character string that identifies the project.", | ||
MarkdownDescription: "Unique 24-hexadecimal character string that identifies the project.", | ||
}, | ||
"specs": schema.ListNestedAttribute{ | ||
Validators: []validator.List{ | ||
listvalidator.SizeAtMost(1), | ||
listvalidator.SizeAtLeast(1), | ||
}, | ||
Required: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"instance_size": schema.StringAttribute{ | ||
Required: true, | ||
Description: "Hardware specification for the search node instance sizes.", | ||
MarkdownDescription: "Hardware specification for the search node instance sizes.", | ||
}, | ||
"node_count": schema.Int64Attribute{ | ||
Required: true, | ||
Description: "Number of search nodes in the cluster.", | ||
MarkdownDescription: "Number of search nodes in the cluster.", | ||
}, | ||
}, | ||
}, | ||
Description: "List of settings that configure the search nodes for your cluster.", | ||
MarkdownDescription: "List of settings that configure the search nodes for your cluster.", | ||
}, | ||
"state_name": schema.StringAttribute{ | ||
Computed: true, | ||
Description: "Human-readable label that indicates the current operating condition of this search deployment.", | ||
MarkdownDescription: "Human-readable label that indicates the current operating condition of this search deployment.", | ||
}, | ||
"timeouts": timeouts.Attributes(ctx, timeouts.Opts{ | ||
Create: true, | ||
Update: true, | ||
Delete: true, | ||
}), | ||
}, | ||
} | ||
} | ||
|
||
type TFSearchDeploymentRSModel struct { | ||
ID types.String `tfsdk:"id"` | ||
ClusterName types.String `tfsdk:"cluster_name"` | ||
ProjectID types.String `tfsdk:"project_id"` | ||
Specs types.List `tfsdk:"specs"` | ||
StateName types.String `tfsdk:"state_name"` | ||
Timeouts timeouts.Value `tfsdk:"timeouts"` | ||
} | ||
|
||
type TFSearchNodeSpecModel struct { | ||
InstanceSize types.String `tfsdk:"instance_size"` | ||
NodeCount types.Int64 `tfsdk:"node_count"` | ||
} | ||
|
||
var SpecObjectType = types.ObjectType{AttrTypes: map[string]attr.Type{ | ||
"instance_size": types.StringType, | ||
"node_count": types.Int64Type, | ||
}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
provider: | ||
name: mongodbatlas | ||
|
||
resources: | ||
search_deployment: | ||
read: | ||
path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/deployment | ||
method: GET | ||
create: | ||
path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/deployment | ||
method: POST | ||
schema: | ||
ignores: [] | ||
|
||
|
||
data_sources: | ||
search_deployment: | ||
read: | ||
path: /api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/deployment | ||
method: GET | ||
schema: | ||
ignores: [] | ||
AgustinBettati marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will scaffolding be used only for new TF plugin or also for older one? just to understand if it's enough to generate MarkdownDescription or we also want to generate Description.
or maybe having an input param (defaulted to new plugin?) in the tool if we want to support both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tool is limited to generating new TF framework code. I have left both definitions as they are both generated by the tool and provide unique value as per comments in the terraform code: