-
Notifications
You must be signed in to change notification settings - Fork 168
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
chore: Generate Flex Cluster data source file and schemas #2725
Open
cveticm
wants to merge
4
commits into
CLOUDP-262066-flex-cluster-dev
Choose a base branch
from
CLOUDP-278904
base: CLOUDP-262066-flex-cluster-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+203
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//nolint:gocritic | ||
package flexcluster | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
// "github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
// "github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config" | ||
) | ||
|
||
var _ datasource.DataSource = &ds{} | ||
var _ datasource.DataSourceWithConfigure = &ds{} | ||
|
||
func DataSource() datasource.DataSource { | ||
return &ds{ | ||
DSCommon: config.DSCommon{ | ||
DataSourceName: resourceName, | ||
}, | ||
} | ||
} | ||
|
||
type ds struct { | ||
config.DSCommon | ||
} | ||
|
||
func (d *ds) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
// TODO: Schema and model must be defined in data_source_schema.go. Details on scaffolding this file found in contributing/development-best-practices.md under "Scaffolding Schema and Model Definitions" | ||
resp.Schema = DataSourceSchema(ctx) | ||
} | ||
|
||
func (d *ds) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
// var tfModel TFModel | ||
// resp.Diagnostics.Append(req.Config.Get(ctx, &tfModel)...) | ||
// if resp.Diagnostics.HasError() { | ||
// return | ||
// } | ||
|
||
// TODO: make get request to resource | ||
|
||
// connV2 := d.Client.AtlasV2 | ||
//if err != nil { | ||
// resp.Diagnostics.AddError("error fetching resource", err.Error()) | ||
// return | ||
//} | ||
|
||
// TODO: process response into new terraform state | ||
// newFlexClusterModel, diags := NewTFModel(ctx, apiResp) | ||
// if diags.HasError() { | ||
// resp.Diagnostics.Append(diags...) | ||
// return | ||
// } | ||
// resp.Diagnostics.Append(resp.State.Set(ctx, newFlexClusterModel)...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package flexcluster | ||
|
||
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: dataSourceSchema(false), | ||
} | ||
} | ||
|
||
func dataSourceSchema(isPlural bool) map[string]schema.Attribute { | ||
return map[string]schema.Attribute{ | ||
"project_id": schema.StringAttribute{ | ||
Required: true, | ||
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.\n\n**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.", | ||
}, | ||
"name": schema.StringAttribute{ | ||
Required: !isPlural, | ||
Computed: isPlural, | ||
MarkdownDescription: "Human-readable label that identifies the flex cluster.", | ||
}, | ||
"provider_settings": schema.SingleNestedAttribute{ | ||
Attributes: map[string]schema.Attribute{ | ||
"backing_provider_name": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Cloud service provider on which MongoDB Cloud provisioned the flex cluster.", | ||
}, | ||
"disk_size_gb": schema.Float64Attribute{ | ||
Computed: true, | ||
MarkdownDescription: "Storage capacity available to the flex cluster expressed in gigabytes.", | ||
}, | ||
"provider_name": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Human-readable label that identifies the cloud service provider.", | ||
}, | ||
"region_name": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Human-readable label that identifies the geographic location of your MongoDB flex cluster. The region you choose can affect network latency for clients accessing your databases. For a complete list of region names, see [AWS](https://docs.atlas.mongodb.com/reference/amazon-aws/#std-label-amazon-aws), [GCP](https://docs.atlas.mongodb.com/reference/google-gcp/), and [Azure](https://docs.atlas.mongodb.com/reference/microsoft-azure/).", | ||
}, | ||
}, | ||
Computed: true, | ||
MarkdownDescription: "Group of cloud provider settings that configure the provisioned MongoDB flex cluster.", | ||
}, | ||
"tags": schema.MapAttribute{ | ||
ElementType: types.StringType, | ||
Computed: true, | ||
MarkdownDescription: "Map that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the instance.", | ||
}, | ||
"backup_settings": schema.SingleNestedAttribute{ | ||
Attributes: map[string]schema.Attribute{ | ||
"enabled": schema.BoolAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Flag that indicates whether backups are performed for this flex cluster. Backup uses [TODO](TODO) for flex clusters.", | ||
}, | ||
}, | ||
Computed: true, | ||
MarkdownDescription: "Flex backup configuration", | ||
}, | ||
"cluster_type": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Flex cluster topology.", | ||
}, | ||
"connection_strings": schema.SingleNestedAttribute{ | ||
Attributes: map[string]schema.Attribute{ | ||
"standard": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Public connection string that you can use to connect to this cluster. This connection string uses the mongodb:// protocol.", | ||
}, | ||
"standard_srv": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Public connection string that you can use to connect to this flex cluster. This connection string uses the `mongodb+srv://` protocol.", | ||
}, | ||
}, | ||
Computed: true, | ||
MarkdownDescription: "Collection of Uniform Resource Locators that point to the MongoDB database.", | ||
}, | ||
"create_date": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Date and time when MongoDB Cloud created this instance. This parameter expresses its value in ISO 8601 format in UTC.", | ||
}, | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies the instance.", | ||
}, | ||
"mongo_db_version": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Version of MongoDB that the instance runs.", | ||
}, | ||
"state_name": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Human-readable label that indicates the current operating condition of this instance.", | ||
}, | ||
"termination_protection_enabled": schema.BoolAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Flag that indicates whether termination protection is enabled on the cluster. If set to `true`, MongoDB Cloud won't delete the cluster. If set to `false`, MongoDB Cloud will delete the cluster.", | ||
}, | ||
"version_release_system": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Method by which the cluster maintains the MongoDB versions.", | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||
package flexcluster | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
|
||||||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||||||
"github.com/hashicorp/terraform-plugin-framework/types" | ||||||
) | ||||||
|
||||||
func DataSourcePluralSchema(ctx context.Context) schema.Schema { | ||||||
return schema.Schema{ | ||||||
Attributes: map[string]schema.Attribute{ | ||||||
"project_id": schema.StringAttribute{ | ||||||
Required: true, | ||||||
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.\n\n**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.", | ||||||
}, | ||||||
"flex_clusters": schema.ListNestedAttribute{ | ||||||
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.
Suggested change
Would prefer to have consistency with other plural data sources in our provider, |
||||||
Computed: true, | ||||||
NestedObject: schema.NestedAttributeObject{ | ||||||
Attributes: dataSourceSchema(true), | ||||||
}, | ||||||
MarkdownDescription: "List of returned documents that MongoDB Cloud provides when completing this request.", | ||||||
}, | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
type TFModelDSP struct { | ||||||
ProjectId types.String `tfsdk:"project_id"` | ||||||
FlexClusters []TFModel `tfsdk:"flex_clusters"` | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you will need to add
conversion.UpdateSchemaDescription(&resp.Schema)
after this line to add the Description field to all attributes like in the resourceThere 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.
Noted! Since this PR is focused on implementing the schemas, I'll exclude this from this PR and include it in the data source implementation ticket 👍