Skip to content
Open
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
54 changes: 54 additions & 0 deletions docs/resources/datawarehouse_database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
subcategory: "Data Warehouse"
page_title: "Scaleway: scaleway_datawarehouse_database"
---

# Resource: scaleway_datawarehouse_database

Creates and manages Scaleway Data Warehouse databases within a deployment.
For more information refer to the [product documentation](https://www.scaleway.com/en/docs/data-warehouse/).

## Example Usage

### Basic

```terraform
resource "scaleway_datawarehouse_deployment" "main" {
name = "my-datawarehouse"
version = "v25"
replica_count = 1
cpu_min = 2
cpu_max = 4
ram_per_cpu = 4
password = "thiZ_is_v&ry_s3cret"
}

resource "scaleway_datawarehouse_database" "main" {
deployment_id = scaleway_datawarehouse_deployment.main.id
name = "my_database"
}
```

## Argument Reference

The following arguments are supported:

- `deployment_id` - (Required) ID of the Data Warehouse deployment to which this database belongs.
- `name` - (Required) Name of the database.
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the database should be created.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the database (format: `{region}/{deployment_id}/{name}`).
- `size` - Size of the database in GB.

## Import

Data Warehouse databases can be imported using the `{region}/{deployment_id}/{name}`, e.g.

```bash
terraform import scaleway_datawarehouse_database.main fr-par/11111111-1111-1111-1111-111111111111/my_database
```

83 changes: 83 additions & 0 deletions docs/resources/datawarehouse_deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
subcategory: "Data Warehouse"
page_title: "Scaleway: scaleway_datawarehouse_deployment"
---

# Resource: scaleway_datawarehouse_deployment

Creates and manages Scaleway Data Warehouse deployments.
For more information refer to the [product documentation](https://www.scaleway.com/en/docs/data-warehouse/).

## Example Usage

### Basic

```terraform
resource "scaleway_datawarehouse_deployment" "main" {
name = "my-datawarehouse"
version = "v25"
replica_count = 1
cpu_min = 2
cpu_max = 4
ram_per_cpu = 4
password = "thiZ_is_v&ry_s3cret"
}
```

### With Tags

```terraform
resource "scaleway_datawarehouse_deployment" "main" {
name = "my-datawarehouse"
version = "v25"
replica_count = 1
cpu_min = 2
cpu_max = 4
ram_per_cpu = 4
password = "thiZ_is_v&ry_s3cret"
tags = ["production", "analytics"]
}
```

## Argument Reference

The following arguments are supported:

- `name` - (Required) Name of the Data Warehouse deployment.
- `version` - (Required, Forces new resource) ClickHouse version to use (e.g., "v25"). Changing this forces recreation of the deployment.
- `replica_count` - (Required) Number of replicas.
- `cpu_min` - (Required) Minimum CPU count. Must be less than or equal to `cpu_max`.
- `cpu_max` - (Required) Maximum CPU count. Must be greater than or equal to `cpu_min`.
- `ram_per_cpu` - (Required) RAM per CPU in GB.
- `password` - (Optional) Password for the first user of the deployment. If not specified, a random password will be generated. Note: password is only used during deployment creation.
- `tags` - (Optional) List of tags to apply to the deployment.
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the deployment should be created.
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the deployment is associated with.

~> **Important:** Private endpoints are not yet supported by the API. A public endpoint is always created automatically.

~> **Note:** During the private beta phase, modifying `cpu_min`, `cpu_max`, and `replica_count` has no effect until the feature is launched in general availability.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the deployment.
- `status` - The status of the deployment (e.g., "ready", "provisioning").
- `created_at` - Date and time of deployment creation (RFC 3339 format).
- `updated_at` - Date and time of deployment last update (RFC 3339 format).
- `public_network` - Public endpoint information (always created automatically).
- `id` - The ID of the public endpoint.
- `dns_record` - DNS record for the public endpoint.
- `services` - List of services exposed on the public endpoint.
- `protocol` - Service protocol (e.g., "tcp", "https", "mysql").
- `port` - TCP port number.

## Import

Data Warehouse deployments can be imported using the `{region}/{id}`, e.g.

```bash
terraform import scaleway_datawarehouse_deployment.main fr-par/11111111-1111-1111-1111-111111111111
```

77 changes: 77 additions & 0 deletions docs/resources/datawarehouse_user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
subcategory: "Data Warehouse"
page_title: "Scaleway: scaleway_datawarehouse_user"
---

# Resource: scaleway_datawarehouse_user

Creates and manages Scaleway Data Warehouse users within a deployment.
For more information refer to the [product documentation](https://www.scaleway.com/en/docs/data-warehouse/).

## Example Usage

### Basic

```terraform
resource "scaleway_datawarehouse_deployment" "main" {
name = "my-datawarehouse"
version = "v25"
replica_count = 1
cpu_min = 2
cpu_max = 4
ram_per_cpu = 4
password = "thiZ_is_v&ry_s3cret"
}

resource "scaleway_datawarehouse_user" "main" {
deployment_id = scaleway_datawarehouse_deployment.main.id
name = "my_user"
password = "user_password_123"
}
```

### Admin User

```terraform
resource "scaleway_datawarehouse_deployment" "main" {
name = "my-datawarehouse"
version = "v25"
replica_count = 1
cpu_min = 2
cpu_max = 4
ram_per_cpu = 4
password = "thiZ_is_v&ry_s3cret"
}

resource "scaleway_datawarehouse_user" "admin" {
deployment_id = scaleway_datawarehouse_deployment.main.id
name = "admin_user"
password = "admin_password_456"
is_admin = true
}
```

## Argument Reference

The following arguments are supported:

- `deployment_id` - (Required) ID of the Data Warehouse deployment to which this user belongs.
- `name` - (Required) Name of the ClickHouse user.
- `password` - (Required) Password for the ClickHouse user.
- `is_admin` - (Optional) Whether the user has administrator privileges. Defaults to `false`.
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the user should be created.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `id` - The ID of the user (format: `{region}/{deployment_id}/{name}`).

## Import

Data Warehouse users can be imported using the `{region}/{deployment_id}/{name}`, e.g.

```bash
terraform import scaleway_datawarehouse_user.main fr-par/11111111-1111-1111-1111-111111111111/my_user
```

149 changes: 149 additions & 0 deletions internal/services/datawarehouse/database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package datawarehouse

import (
"context"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
datawarehouseapi "github.com/scaleway/scaleway-sdk-go/api/datawarehouse/v1beta1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
)

func ResourceDatabase() *schema.Resource {
return &schema.Resource{
CreateContext: resourceDatabaseCreate,
ReadContext: resourceDatabaseRead,
DeleteContext: resourceDatabaseDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Schema: map[string]*schema.Schema{
"region": regional.Schema(),
"deployment_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "ID of the Datawarehouse deployment to which this database belongs.",
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Name of the database.",
},
"size": {
Type: schema.TypeInt,
Computed: true,
Description: "Size of the database (in GB).",
},
},
}
}

func resourceDatabaseCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
api := NewAPI(meta)

region := scw.Region(d.Get("region").(string))
deploymentID := d.Get("deployment_id").(string)
name := d.Get("name").(string)

req := &datawarehouseapi.CreateDatabaseRequest{
Region: region,
DeploymentID: deploymentID,
Name: name,
}

_, err := api.CreateDatabase(req, scw.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
}

d.SetId(ResourceDatabaseID(region, deploymentID, name))

return resourceDatabaseRead(ctx, d, meta)
}

func resourceDatabaseRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
api := NewAPI(meta)

region, deploymentID, name, err := ResourceDatabaseParseID(d.Id())
if err != nil {
return diag.FromErr(err)
}

resp, err := api.ListDatabases(&datawarehouseapi.ListDatabasesRequest{
Region: region,
DeploymentID: deploymentID,
Name: scw.StringPtr(name),
}, scw.WithContext(ctx))
if err != nil {
if httperrors.Is404(err) {
d.SetId("")

return nil
}

return diag.FromErr(err)
}

var found *datawarehouseapi.Database

for _, db := range resp.Databases {
if db.Name == name {
found = db

break
}
}

if found == nil {
d.SetId("")

return nil
}

_ = d.Set("deployment_id", deploymentID)
_ = d.Set("name", found.Name)
_ = d.Set("size", int(found.Size))

return nil
}

func resourceDatabaseDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
api := NewAPI(meta)

region, deploymentID, name, err := ResourceDatabaseParseID(d.Id())
if err != nil {
return diag.FromErr(err)
}

err = api.DeleteDatabase(&datawarehouseapi.DeleteDatabaseRequest{
Region: region,
DeploymentID: deploymentID,
Name: name,
}, scw.WithContext(ctx))
if err != nil && !httperrors.Is404(err) {
return diag.FromErr(err)
}

d.SetId("")

return nil
}

func ResourceDatabaseID(region scw.Region, deploymentID, name string) string {
return fmt.Sprintf("%s/%s/%s", region, deploymentID, name)
}

func ResourceDatabaseParseID(id string) (scw.Region, string, string, error) {
parts := strings.Split(id, "/")
if len(parts) != 3 {
return "", "", "", fmt.Errorf("unexpected format of ID (%s), expected region/deployment_id/name", id)
}

return scw.Region(parts[0]), parts[1], parts[2], nil
}
Loading
Loading