-
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
feat: search node management with mongodbatlas_search_deployment
resource and data source
#1633
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c556c7d
TEMPORARY - use SDK Preview
AgustinBettati 0589e2f
feat: new search node resource
AgustinBettati dc91828
wip - acceptance tests
AgustinBettati dc1db71
fixes in tests and adding CI workflow
AgustinBettati 4f9297a
use state property to verify transition for create, update, and delet…
AgustinBettati cd9c94e
add specific documentation to clarify specs as a list nested attribute
AgustinBettati 2e58578
addressing PR comments
AgustinBettati f65af95
addressing doc reviews
AgustinBettati 1034904
adjusting to new state names and transitions
AgustinBettati 7a5d987
refactor name from search_node to search_deployment
AgustinBettati 6fc6e3e
feat: implement search node data source with acceptance tests and docs
AgustinBettati 27a3d55
Revert "TEMPORARY - use SDK Preview"
AgustinBettati ad15dd4
Merge remote-tracking branch 'origin/master' into CLOUDP-206622
AgustinBettati b195da1
adjust documentation links
AgustinBettati fe93442
small naming change
AgustinBettati 951f4ff
change in search deployment example readme phrasing
AgustinBettati 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
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,11 @@ | ||
# MongoDB Atlas Provider - Atlas Cluster with dedicated Search Nodes Deployment | ||
|
||
This example shows how you can use Atlas Dedicated Search Nodes in Terraform. As a prerequisite, you need to create a project and cluster resource. | ||
AgustinBettati marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Variables Required to be set: | ||
|
||
- `public_key`: Atlas public key | ||
- `private_key`: Atlas private key | ||
- `org_id`: Organization ID where the project and cluster will be created. | ||
|
||
For additional information you can visit the [Search Node Documentation](https://www.mongodb.com/docs/atlas/cluster-config/multi-cloud-distribution/#search-nodes-for-workload-isolation). |
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,33 @@ | ||
resource "mongodbatlas_project" "example" { | ||
name = "project-name" | ||
org_id = var.org_id | ||
} | ||
|
||
resource "mongodbatlas_advanced_cluster" "example" { | ||
project_id = mongodbatlas_project.example.id | ||
name = "ClusterExample" | ||
cluster_type = "REPLICASET" | ||
|
||
replication_specs { | ||
region_configs { | ||
electable_specs { | ||
instance_size = "M10" | ||
node_count = 3 | ||
} | ||
provider_name = "AWS" | ||
priority = 7 | ||
region_name = "US_EAST_1" | ||
} | ||
} | ||
} | ||
|
||
resource "mongodbatlas_search_deployment" "example" { | ||
project_id = mongodbatlas_project.example.id | ||
cluster_name = mongodbatlas_advanced_cluster.example.name | ||
specs = [ | ||
{ | ||
instance_size = "S20_HIGHCPU_NVME" | ||
node_count = 2 | ||
} | ||
] | ||
} |
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,4 @@ | ||
provider "mongodbatlas" { | ||
public_key = var.public_key | ||
private_key = var.private_key | ||
} |
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,12 @@ | ||
variable "public_key" { | ||
description = "Public API key to authenticate to Atlas" | ||
type = string | ||
} | ||
variable "private_key" { | ||
description = "Private API key to authenticate to Atlas" | ||
type = string | ||
} | ||
variable "org_id" { | ||
description = "Atlas Organization ID" | ||
type = string | ||
} |
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,9 @@ | ||
terraform { | ||
required_providers { | ||
mongodbatlas = { | ||
source = "mongodb/mongodbatlas" | ||
version = "~> 1.13" | ||
} | ||
} | ||
required_version = ">= 1.0" | ||
} |
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
99 changes: 99 additions & 0 deletions
99
mongodbatlas/fw_data_source_mongodbatlas_search_deployment.go
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,99 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var _ datasource.DataSource = &SearchDeploymentDS{} | ||
var _ datasource.DataSourceWithConfigure = &SearchDeploymentDS{} | ||
|
||
func NewSearchDeploymentDS() datasource.DataSource { | ||
return &SearchDeploymentDS{ | ||
DSCommon: DSCommon{ | ||
dataSourceName: searchDeploymentName, | ||
}, | ||
} | ||
} | ||
|
||
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"` | ||
} | ||
|
||
type SearchDeploymentDS struct { | ||
DSCommon | ||
} | ||
|
||
func (d *SearchDeploymentDS) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
"cluster_name": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
"project_id": schema.StringAttribute{ | ||
Required: true, | ||
}, | ||
"specs": schema.ListNestedAttribute{ | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"instance_size": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
"node_count": schema.Int64Attribute{ | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
Computed: true, | ||
}, | ||
"state_name": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *SearchDeploymentDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var searchDeploymentConfig tfSearchDeploymentDSModel | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &searchDeploymentConfig)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
connV2 := d.client.AtlasV2 | ||
projectID := searchDeploymentConfig.ProjectID.ValueString() | ||
clusterName := searchDeploymentConfig.ClusterName.ValueString() | ||
deploymentResp, _, err := connV2.AtlasSearchApi.GetAtlasSearchDeployment(ctx, projectID, clusterName).Execute() | ||
if err != nil { | ||
resp.Diagnostics.AddError("error getting search node information", err.Error()) | ||
return | ||
} | ||
|
||
newSearchDeploymentModel, diagnostics := newTFSearchDeployment(ctx, clusterName, deploymentResp, nil) | ||
resp.Diagnostics.Append(diagnostics...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
dsModel := convertToDSModel(newSearchDeploymentModel) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, dsModel)...) | ||
} | ||
|
||
func convertToDSModel(inputModel *tfSearchDeploymentRSModel) tfSearchDeploymentDSModel { | ||
return tfSearchDeploymentDSModel{ | ||
ID: inputModel.ID, | ||
ClusterName: inputModel.ClusterName, | ||
ProjectID: inputModel.ProjectID, | ||
Specs: inputModel.Specs, | ||
StateName: inputModel.StateName, | ||
} | ||
} |
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
Oops, something went wrong.
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.
CI: true is missing ;-). cc @marcosuma
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.
true, however that env variable is not used in this job as no tests need to be skipped (several jobs dont define it). Can add just for consistency.
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.
yeah, i know it's only used when calling SkipTestForCI , it was more to advocate for a common env zone :-)
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 try to answer to your PR :) but I think the global env variables would make the opposite effect here when you create a new job and you don't immediately expect there are global variables that might affect this job's behaviour
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.
or it could be the opposite, that you try to use SkipTestForCI and don't know why it's not skipping it.
I think it depends on the expectations set on the tests run from that GH action. for me it's clear in this case that all tests "want" to have CI:true even if they don't use/need it right now.