Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/data-sources/mongodb_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ output "mongodb_version" {

- `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.
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) 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.

Expand All @@ -64,5 +64,5 @@ In addition to all above arguments, the following attributes are exported:
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
terraform import scaleway_mongodb_instance.main fr-par/11111111-1111-1111-1111-111111111111
```
6 changes: 5 additions & 1 deletion docs/resources/mongodb_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ The following arguments are supported:
- `private_network` - (Optional) Private Network endpoints of the Database Instance.
- `pn_id` - (Required) The ID of the Private Network.
- `public_network` - (Optional) Public network endpoint configuration (no arguments).
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the MongoDB® instance should be created.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the MongoDB® instance is associated with.

~> **Important** If neither private_network nor public_network is specified, a public network endpoint is created by default.


Expand All @@ -114,6 +117,7 @@ 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.
- `region` - The region of the MongoDB® instance.
- `private_network` - Private Network endpoints of the Database Instance.
- `id` - The ID of the endpoint.
- `ips` - List of IP addresses for your endpoint.
Expand All @@ -133,5 +137,5 @@ In addition to all arguments above, the following attributes are exported:
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
terraform import scaleway_mongodb_instance.main fr-par/11111111-1111-1111-1111-111111111111
```
4 changes: 2 additions & 2 deletions docs/resources/mongodb_snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The following arguments are supported:

~> **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.
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the MongoDB® snapshot should be created.

## Attributes Reference

Expand All @@ -58,5 +58,5 @@ In addition to all arguments above, the following attributes are exported:
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
terraform import scaleway_mongodb_snapshot.main fr-par/11111111-1111-1111-1111-111111111111
```
8 changes: 4 additions & 4 deletions internal/services/mongodb/data_source_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func DataSourceInstance() *schema.Resource {
}

func DataSourceInstanceRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
mongodbAPI, zone, region, err := newAPIWithZoneAndRegion(d, m)
mongodbAPI, region, err := newAPIWithRegion(d, m)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -65,10 +65,10 @@ func DataSourceInstanceRead(ctx context.Context, d *schema.ResourceData, m any)
instanceID = foundInstance.ID
}

zonedID := datasource.NewZonedID(instanceID, zone)
d.SetId(zonedID)
regionalID := datasource.NewRegionalID(instanceID, region)
d.SetId(regionalID)

err = d.Set("instance_id", zonedID)
err = d.Set("instance_id", regionalID)
if err != nil {
return diag.FromErr(err)
}
Expand Down
44 changes: 3 additions & 41 deletions internal/services/mongodb/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
mongodb "github.com/scaleway/scaleway-sdk-go/api/mongodb/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
)
Expand All @@ -26,30 +26,6 @@ func newAPI(m any) *mongodb.API {
return mongodb.NewAPI(meta.ExtractScwClient(m))
}

// newAPIWithZone returns a new mongoDB API and the zone for a Create request
func newAPIWithZone(d *schema.ResourceData, m any) (*mongodb.API, scw.Zone, error) {
zone, err := meta.ExtractZone(d, m)
if err != nil {
return nil, "", err
}

return newAPI(m), zone, nil
}

func newAPIWithZoneAndRegion(d *schema.ResourceData, m any) (*mongodb.API, scw.Zone, scw.Region, error) {
zone, err := meta.ExtractZone(d, m)
if err != nil {
return nil, "", "", err
}

region, err := meta.ExtractRegion(d, m)
if err != nil {
return nil, "", "", err
}

return newAPI(m), zone, region, nil
}

func newAPIWithRegion(d *schema.ResourceData, m any) (*mongodb.API, scw.Region, error) {
region, err := meta.ExtractRegion(d, m)
if err != nil {
Expand All @@ -59,23 +35,9 @@ func newAPIWithRegion(d *schema.ResourceData, m any) (*mongodb.API, scw.Region,
return newAPI(m), region, nil
}

// NewAPIWithZoneAndID returns a mongoDB API with zone and ID extracted from the state
func NewAPIWithZoneAndID(m any, id string) (*mongodb.API, scw.Zone, string, error) {
zone, ID, err := zonal.ParseID(id)
if err != nil {
return nil, "", "", err
}

return newAPI(m), zone, ID, nil
}

// NewAPIWithRegionAndID returns a mongoDB API with region and ID extracted from the state
func NewAPIWithRegionAndID(m any, id string) (*mongodb.API, scw.Region, string, error) {
zone, ID, err := zonal.ParseID(id)
if err != nil {
return nil, "", "", err
}

region, err := zone.Region()
region, ID, err := regional.ParseID(id)
if err != nil {
return nil, "", "", err
}
Expand Down
5 changes: 2 additions & 3 deletions internal/services/mongodb/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/ipam"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
Expand Down Expand Up @@ -263,7 +262,7 @@ func ResourceInstance() *schema.Resource {
}

func ResourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
mongodbAPI, zone, err := newAPIWithZone(d, m)
mongodbAPI, region, err := newAPIWithRegion(d, m)
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -361,7 +360,7 @@ func ResourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m any)
}
}

d.SetId(zonal.NewIDString(zone, res.ID))
d.SetId(regional.NewIDString(region, res.ID))

_, err = waitForInstance(ctx, mongodbAPI, res.Region, res.ID, d.Timeout(schema.TimeoutCreate))
if err != nil {
Expand Down
7 changes: 1 addition & 6 deletions internal/services/mongodb/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,7 @@ func IsInstanceDestroyed(tt *acctest.TestTools) resource.TestCheckFunc {
continue
}

mongodbAPI, zone, ID, err := mongodb.NewAPIWithZoneAndID(tt.Meta, rs.Primary.ID)
if err != nil {
return err
}

extractRegion, err := zone.Region()
mongodbAPI, extractRegion, ID, err := mongodb.NewAPIWithRegionAndID(tt.Meta, rs.Primary.ID)
if err != nil {
return err
}
Expand Down
13 changes: 6 additions & 7 deletions internal/services/mongodb/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
)
Expand Down Expand Up @@ -86,7 +85,7 @@ func ResourceSnapshot() *schema.Resource {
}

func ResourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
mongodbAPI, zone, region, err := newAPIWithZoneAndRegion(d, m)
mongodbAPI, region, err := newAPIWithRegion(d, m)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -105,7 +104,7 @@ func ResourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m any)
}

if snapshot != nil {
d.SetId(zonal.NewIDString(zone, snapshot.ID))
d.SetId(regional.NewIDString(region, snapshot.ID))

_, err = waitForSnapshot(ctx, mongodbAPI, region, instanceID, snapshot.ID, d.Timeout(schema.TimeoutCreate))
if err != nil {
Expand All @@ -122,7 +121,7 @@ func ResourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m any) di
return diag.FromErr(err)
}

zone, snapshotID, err := zonal.ParseID(d.Id())
_, snapshotID, err := regional.ParseID(d.Id())
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -134,7 +133,7 @@ func ResourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m any) di
return diag.FromErr(err)
}

_ = d.Set("instance_id", zonal.NewIDString(zone, *snapshot.InstanceID))
_ = d.Set("instance_id", regional.NewIDString(region, *snapshot.InstanceID))
_ = d.Set("name", snapshot.Name)
_ = d.Set("instance_name", snapshot.InstanceName)
_ = d.Set("size", int64(snapshot.SizeBytes))
Expand All @@ -154,7 +153,7 @@ func ResourceSnapshotUpdate(ctx context.Context, d *schema.ResourceData, m any)
return diag.FromErr(err)
}

_, snapshotID, err := zonal.ParseID(d.Id())
_, snapshotID, err := regional.ParseID(d.Id())
if err != nil {
return diag.FromErr(err)
}
Expand Down Expand Up @@ -200,7 +199,7 @@ func ResourceSnapshotDelete(_ context.Context, d *schema.ResourceData, m any) di
return diag.FromErr(err)
}

_, snapshotID, err := zonal.ParseID(d.Id())
_, snapshotID, err := regional.ParseID(d.Id())
if err != nil {
return diag.FromErr(err)
}
Expand Down
4 changes: 2 additions & 2 deletions templates/data-sources/mongodb_instance.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ output "mongodb_version" {

- `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.
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) 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.

Expand All @@ -64,5 +64,5 @@ In addition to all above arguments, the following attributes are exported:
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
terraform import scaleway_mongodb_instance.main fr-par/11111111-1111-1111-1111-111111111111
```
6 changes: 5 additions & 1 deletion templates/resources/mongodb_instance.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ The following arguments are supported:
- `private_network` - (Optional) Private Network endpoints of the Database Instance.
- `pn_id` - (Required) The ID of the Private Network.
- `public_network` - (Optional) Public network endpoint configuration (no arguments).
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the MongoDB® instance should be created.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the MongoDB® instance is associated with.

~> **Important** If neither private_network nor public_network is specified, a public network endpoint is created by default.


Expand All @@ -114,6 +117,7 @@ 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.
- `region` - The region of the MongoDB® instance.
- `private_network` - Private Network endpoints of the Database Instance.
- `id` - The ID of the endpoint.
- `ips` - List of IP addresses for your endpoint.
Expand All @@ -133,5 +137,5 @@ In addition to all arguments above, the following attributes are exported:
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
terraform import scaleway_mongodb_instance.main fr-par/11111111-1111-1111-1111-111111111111
```
4 changes: 2 additions & 2 deletions templates/resources/mongodb_snapshot.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The following arguments are supported:

~> **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.
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the MongoDB® snapshot should be created.

## Attributes Reference

Expand All @@ -58,5 +58,5 @@ In addition to all arguments above, the following attributes are exported:
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
terraform import scaleway_mongodb_snapshot.main fr-par/11111111-1111-1111-1111-111111111111
```
Loading