-
Notifications
You must be signed in to change notification settings - Fork 130
feat(mongodb): add support for v1alpha1 #2777
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
49827b5
feat(mongodb): resource instance
jremy42 9569d5e
feat(mongodb): add test for instance
jremy42 dd3394f
feat(mongodb): add basic test for instance
jremy42 95bc488
feat(mongodb): add snapshot and test
jremy42 ffccd89
feat(mongodb): with private network
jremy42 9d0b3d1
feat(mongodb): delete private network
jremy42 b76484d
t
jremy42 898ae01
feat(mongodb): add data source and docs
jremy42 6e79c7a
feat(mongodb): add cassette with sdk
jremy42 2af9383
feat(mongodb): fix tflint
jremy42 26ee147
feat(mongodb): add datasource doc
jremy42 eca169b
feat(mongodb): fix lint
jremy42 f1387f7
feat(mongodb): fix lint
jremy42 20a41fc
feat(mongodb): fix lint
jremy42 399024a
feat(mongodb): fix lint
jremy42 b9870f0
feat(mongodb): fix lint
jremy42 245d3f2
feat(mongodb): fix lint
jremy42 dfe5719
feat(mongodb): add mongodb to workflow
jremy42 ad14126
feat(mongodb): add test for update tag and password
jremy42 680795f
fix(mongodb): add trademark in docs
jremy42 c6a3c00
feat(mongodb): add getsnapshot in test
jremy42 fe47373
feat(mongodb): refacto update snapshot and instance
jremy42 f6b4f77
feat(mongodb): replace TM by ® in docs
jremy42 8891670
feat(mongodb): remove id from snapshot doc
jremy42 534f2de
feat(mongodb): add warning when user_name change
jremy42 28f270b
feat(mongodb): add id doc snapshot
jremy42 fca955e
Merge branch 'master' into feat/add_support_for_mondoDB
jremy42 6f685b5
Merge branch 'master' into feat/add_support_for_mondoDB
jremy42 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 hidden or 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 |
---|---|---|
|
@@ -30,6 +30,7 @@ jobs: | |
- lb | ||
- marketplace | ||
- mnq | ||
- mongodb | ||
- object | ||
- rdb | ||
- redis | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -31,6 +31,7 @@ jobs: | |
- lb | ||
- marketplace | ||
- mnq | ||
- mongodb | ||
- object | ||
- rdb | ||
- redis | ||
|
This file contains hidden or 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,68 @@ | ||
--- | ||
subcategory: "MongoDB®" | ||
page_title: "Scaleway: scaleway_mongodb_instance" | ||
--- | ||
|
||
# scaleway_mongodb_instance | ||
|
||
Gets information about a MongoDB® Instance. | ||
|
||
For further information refer to the Managed Databases for MongoDB® [API documentation](https://developers.scaleway.com/en/products/mongodb/api/) | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
# Get info by name | ||
data "scaleway_mongodb_instance" "my_instance" { | ||
name = "foobar" | ||
} | ||
|
||
# Get info by instance ID | ||
data "scaleway_mongodb_instance" "my_instance" { | ||
instance_id = "11111111-1111-1111-1111-111111111111" | ||
} | ||
|
||
# Get other attributes | ||
output "mongodb_version" { | ||
description = "Version of the MongoDB instance" | ||
value = data.scaleway_mongodb_instance.my_instance.version | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
- `name` - (Optional) The name of the MongoDB® instance. | ||
|
||
- `instance_id` - (Optional) The MongoDB® instance ID. | ||
|
||
-> **Note** You must specify at least one: `name` or `instance_id`. | ||
|
||
- `project_id` - (Optional) The ID of the project the MongoDB® instance is in. Can be used to filter instances when using `name`. | ||
|
||
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#zones) in which the MongoDB® Instance exists. | ||
|
||
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the MongoDB® instance is in. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all above arguments, the following attributes are exported: | ||
|
||
- `id` - The ID of the MongoDB® Instance. | ||
- `name` - The name of the MongoDB® instance. | ||
- `version` - The version of MongoDB® running on the instance. | ||
- `node_type` - The type of MongoDB® node. | ||
- `node_number` - The number of nodes in the MongoDB® cluster. | ||
- `created_at` - The date and time the MongoDB® instance was created. | ||
- `project_id` - The ID of the project the instance belongs to. | ||
- `tags` - A list of tags attached to the MongoDB® instance. | ||
- `volume_type` - The type of volume attached to the MongoDB® instance. | ||
- `volume_size_in_gb` - The size of the attached volume, in GB. | ||
- `public_network` - The details of the public network configuration, if applicable. | ||
|
||
## Import | ||
|
||
MongoDB® instance can be imported using the `id`, e.g. | ||
|
||
```bash | ||
terraform import scaleway_mongodb_instance.main fr-par-1/11111111-1111-1111-1111-111111111111 | ||
``` |
This file contains hidden or 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,70 @@ | ||
--- | ||
subcategory: "MongoDB®" | ||
page_title: "Scaleway: scaleway_mongodb_instance" | ||
--- | ||
|
||
# Resource: scaleway_mongodb_instance | ||
|
||
Creates and manages Scaleway MongoDB® instance. | ||
For more information refer to [the API documentation](https://www.scaleway.com/en/docs/managed-databases/mongodb/). | ||
|
||
## Example Usage | ||
|
||
### Basic | ||
|
||
```terraform | ||
resource "scaleway_mongodb_instance" "main" { | ||
name = "test-mongodb-basic1" | ||
version = "7.0.12" | ||
node_type = "MGDB-PLAY2-NANO" | ||
node_number = 1 | ||
user_name = "my_initial_user" | ||
password = "thiZ_is_v&ry_s3cret" | ||
volume_size_in_gb = 5 | ||
|
||
} | ||
``` | ||
|
||
|
||
### Restore From Snapshot | ||
|
||
```terraform | ||
|
||
resource "scaleway_mongodb_instance" "restored_instance" { | ||
snapshot_id = "${scaleway_vpc_private_network.pn.idscaleway_mongodb_snapshot.main_snapshot.id}" | ||
name = "restored-mongodb-from-snapshot" | ||
node_type = "MGDB-PLAY2-NANO" | ||
node_number = 1 | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
- `version` - (Optional) MongoDB® version of the instance. | ||
- `node_type` - (Required) The type of MongoDB® intance to create. | ||
- `user_name` - (Optional) Name of the user created when the intance is created. | ||
- `password` - (Optional) Password of the user. | ||
- `name` - (Optional) Name of the MongoDB® instance. | ||
- `tags` - (Optional) List of tags attached to the MongoDB® instance. | ||
- `volume_type` - (Optional) Volume type of the instance. | ||
- `volume_size_in_gb` - (Optional) Volume size in GB. | ||
- `snapshot_id` - (Optional) Snapshot ID to restore the MongoDB® instance from. | ||
- `public_network` - (Optional) Public network specs details. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
- `id` - The ID of the MongoDB® instance. | ||
- `created_at` - The date and time of the creation of the MongoDB® instance. | ||
- `updated_at` - The date and time of the last update of the MongoDB® instance. | ||
|
||
## Import | ||
|
||
MongoDB® instance can be imported using the `id`, e.g. | ||
|
||
```bash | ||
terraform import scaleway_mongodb_instance.main fr-par-1/11111111-1111-1111-1111-111111111111 | ||
``` |
This file contains hidden or 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,62 @@ | ||
--- | ||
subcategory: "MongoDB®" | ||
page_title: "Scaleway: scaleway_mongodb_snapshot" | ||
--- | ||
|
||
# Resource: scaleway_mongodb_snapshot | ||
|
||
Creates and manages Scaleway MongoDB® snapshots. | ||
For more information refer to [the API documentation](https://www.scaleway.com/en/docs/managed-databases/mongodb/). | ||
|
||
## Example Usage | ||
|
||
|
||
```terraform | ||
|
||
resource "scaleway_mongodb_snapshot" "main" { | ||
instance_id = "${scaleway_mongodb_instance.main.id}" | ||
name = "name-snapshot" | ||
expires_at = "2024-12-31T23:59:59Z" | ||
} | ||
``` | ||
|
||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
- `instance_id` - (Required) The ID of the MongoDB® instance from which the snapshot was created. | ||
|
||
- `name` - (Optional) The name of the MongoDB® snapshot. | ||
|
||
- `expires_at` - (Required) The expiration date of the MongoDB® snapshot in ISO 8601 format (e.g. `2024-12-31T23:59:59Z`). | ||
|
||
~> **Important:** Once set, `expires_at` cannot be removed. | ||
|
||
- `region` - (Defaults to [provider](../index.md) `region`) The [region](../guides/regions_and_zones.md#regions) in which the MongoDB® snapshot should be created. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
- `id` - The ID of the snapshot. | ||
|
||
- `instance_name` - The name of the MongoDB® instance from which the snapshot was created. | ||
|
||
- `size` - The size of the MongoDB® snapshot in bytes. | ||
|
||
- `node_type` - The type of node associated with the MongoDB® snapshot. | ||
|
||
- `volume_type` - The type of volume used for the MongoDB® snapshot. | ||
|
||
- `created_at` - The date and time when the MongoDB® snapshot was created. | ||
|
||
- `updated_at` - The date and time of the last update of the MongoDB® snapshot. | ||
|
||
## Import | ||
|
||
MongoDB® snapshots can be imported using the `{region}/{id}`, e.g. | ||
|
||
```bash | ||
terraform import scaleway_mongodb_snapshot.main fr-par-1/11111111-1111-1111-1111-111111111111 | ||
``` |
This file contains hidden or 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 hidden or 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,111 @@ | ||
package mongodb | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
mongodb "github.com/scaleway/scaleway-sdk-go/api/mongodb/v1alpha1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
"github.com/scaleway/terraform-provider-scaleway/v2/internal/datasource" | ||
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality" | ||
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types" | ||
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify" | ||
) | ||
|
||
func DataSourceInstance() *schema.Resource { | ||
dsSchema := datasource.SchemaFromResourceSchema(ResourceInstance().Schema) | ||
|
||
datasource.AddOptionalFieldsToSchema(dsSchema, "name", "region", "project_id") | ||
|
||
dsSchema["name"].ConflictsWith = []string{"instance_id"} | ||
dsSchema["instance_id"] = &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "instance id", | ||
ConflictsWith: []string{"name"}, | ||
ValidateDiagFunc: verify.IsUUIDorUUIDWithLocality(), | ||
} | ||
|
||
return &schema.Resource{ | ||
ReadContext: DataSourceInstanceRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func DataSourceInstanceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
mongodbAPI, zone, region, err := newAPIWithZoneAndRegion(d, m) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
instanceID, ok := d.GetOk("instance_id") | ||
if !ok { | ||
instanceName := d.Get("name").(string) | ||
res, err := mongodbAPI.ListInstances(&mongodb.ListInstancesRequest{ | ||
Region: region, | ||
Name: types.ExpandStringPtr(instanceName), | ||
ProjectID: types.ExpandStringPtr(d.Get("project_id")), | ||
}, scw.WithContext(ctx)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
foundInstance, err := datasource.FindExact( | ||
res.Instances, | ||
func(s *mongodb.Instance) bool { return s.Name == instanceName }, | ||
instanceName, | ||
) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
instanceID = foundInstance.ID | ||
} | ||
|
||
zonedID := datasource.NewZonedID(instanceID, zone) | ||
d.SetId(zonedID) | ||
err = d.Set("instance_id", zonedID) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
getReq := &mongodb.GetInstanceRequest{ | ||
Region: region, | ||
InstanceID: locality.ExpandID(instanceID.(string)), | ||
} | ||
instance, err := mongodbAPI.GetInstance(getReq, scw.WithContext(ctx)) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
_ = d.Set("name", instance.Name) | ||
_ = d.Set("version", instance.Version) | ||
_ = d.Set("node_number", int(instance.NodeNumber)) | ||
_ = d.Set("node_type", instance.NodeType) | ||
_ = d.Set("project_id", instance.ProjectID) | ||
_ = d.Set("tags", instance.Tags) | ||
_ = d.Set("created_at", instance.CreatedAt.Format(time.RFC3339)) | ||
_ = d.Set("region", instance.Region.String()) | ||
|
||
if instance.Volume != nil { | ||
_ = d.Set("volume_type", instance.Volume.Type) | ||
_ = d.Set("volume_size_in_gb", int(instance.Volume.Size/scw.GB)) | ||
} | ||
|
||
publicNetworkEndpoint, publicNetworkExists := flattenPublicNetwork(instance.Endpoints) | ||
if publicNetworkExists { | ||
_ = d.Set("public_network", publicNetworkEndpoint) | ||
} | ||
|
||
if len(instance.Settings) > 0 { | ||
settingsMap := make(map[string]string) | ||
for _, setting := range instance.Settings { | ||
settingsMap[setting.Name] = setting.Value | ||
} | ||
_ = d.Set("settings", settingsMap) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.