Skip to content

Commit 905db64

Browse files
feat(rdb): add rdb_instance password_wo (#3614)
* feat(rdb): add rdb_instance password_wo * fix(rdb): keep password optional to prevent breaking change
1 parent a01110a commit 905db64

File tree

15 files changed

+2847
-227
lines changed

15 files changed

+2847
-227
lines changed

docs/resources/rdb_instance.md

Lines changed: 107 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ page_title: "Scaleway: scaleway_rdb_instance"
88
Creates and manages Scaleway Database Instances.
99
For more information, see refer to the [API documentation](https://www.scaleway.com/en/developers/api/managed-database-postgre-mysql/).
1010

11+
1112
## Example Usage
1213

14+
```terraform
1315
### Example Basic
1416
15-
```terraform
1617
resource "scaleway_rdb_instance" "main" {
1718
name = "test-rdb"
1819
node_type = "DB-DEV-S"
@@ -25,61 +26,9 @@ resource "scaleway_rdb_instance" "main" {
2526
}
2627
```
2728

28-
### Example Block Storage Low Latency
29-
3029
```terraform
31-
resource "scaleway_rdb_instance" "main" {
32-
name = "test-rdb-sbs"
33-
node_type = "db-play2-pico"
34-
engine = "PostgreSQL-15"
35-
is_ha_cluster = true
36-
disable_backup = true
37-
user_name = "my_initial_user"
38-
password = "thiZ_is_v&ry_s3cret"
39-
volume_type = "sbs_15k"
40-
volume_size_in_gb = 10
41-
}
42-
```
43-
44-
### Example with Settings
45-
46-
```terraform
47-
resource "scaleway_rdb_instance" "main" {
48-
name = "test-rdb"
49-
node_type = "db-dev-s"
50-
disable_backup = true
51-
engine = "MySQL-8"
52-
user_name = "my_initial_user"
53-
password = "thiZ_is_v&ry_s3cret"
54-
init_settings = {
55-
"lower_case_table_names" = 1
56-
}
57-
settings = {
58-
"max_connections" = "350"
59-
}
60-
}
61-
```
62-
63-
### Example with backup schedule
64-
65-
```terraform
66-
resource "scaleway_rdb_instance" "main" {
67-
name = "test-rdb"
68-
node_type = "DB-DEV-S"
69-
engine = "PostgreSQL-15"
70-
is_ha_cluster = true
71-
user_name = "my_initial_user"
72-
password = "thiZ_is_v&ry_s3cret"
73-
74-
disable_backup = false
75-
backup_schedule_frequency = 24 # every day
76-
backup_schedule_retention = 7 # keep it one week
77-
}
78-
```
79-
8030
### Example Engine Upgrade
8131
82-
```terraform
8332
# Initial creation with PostgreSQL 14
8433
resource "scaleway_rdb_instance" "main" {
8534
name = "my-database"
@@ -109,15 +58,61 @@ output "upgradable_versions" {
10958
# }
11059
```
11160

112-
~> **Warning** Provider versions prior to `2.61.0` did not support engine upgrades. Changing the `engine` value in these versions would recreate the Database Instance **empty**, resulting in **data loss**. Ensure you are using provider version `>= 2.61.0` before upgrading your Database Instance engine version.
61+
```terraform
62+
### Usage of ephemeral random_password for instance password without storing it in state
63+
64+
// Generate an ephemeral password (not stored in the state)
65+
ephemeral "random_password" "db_password" {
66+
length = 20
67+
special = true
68+
upper = true
69+
lower = true
70+
numeric = true
71+
min_upper = 1
72+
min_lower = 1
73+
min_numeric = 1
74+
min_special = 1
75+
# Exclude characters that might cause issues in some contexts
76+
override_special = "!@#$%^&*()_+-=[]{}|;:,.<>?"
77+
}
78+
79+
// Pass the ephemeral password with password_wo (not stored in the state)
80+
resource "scaleway_rdb_instance" "main" {
81+
name = "test-rdb"
82+
node_type = "DB-DEV-S"
83+
engine = "PostgreSQL-15"
84+
is_ha_cluster = true
85+
disable_backup = true
86+
user_name = "my_initial_user"
87+
password_wo = ephemeral.random_password.db_password.result
88+
password_wo_version = 1
89+
encryption_at_rest = true
90+
}
91+
```
92+
93+
```terraform
94+
#### 1 IPAM Private Network endpoint + 1 public endpoint
95+
96+
resource "scaleway_vpc_private_network" "pn" {}
11397
98+
resource "scaleway_rdb_instance" "main" {
99+
node_type = "DB-DEV-S"
100+
engine = "PostgreSQL-15"
101+
private_network {
102+
pn_id = scaleway_vpc_private_network.pn.id
103+
enable_ipam = true
104+
}
105+
load_balancer {}
106+
}
107+
```
108+
109+
```terraform
114110
### Examples of endpoint configuration
115111
116-
Database Instances can have a maximum of 1 public endpoint and 1 private endpoint. They can have both, or none.
112+
##### Database Instances can have a maximum of 1 public endpoint and 1 private endpoint. They can have both, or none.
117113
118114
#### 1 static Private Network endpoint
119115
120-
```terraform
121116
resource "scaleway_vpc_private_network" "pn" {
122117
ipv4_subnet {
123118
subnet = "172.16.20.0/22"
@@ -135,31 +130,70 @@ resource "scaleway_rdb_instance" "main" {
135130
}
136131
```
137132

138-
#### 1 IPAM Private Network endpoint + 1 public endpoint
139-
140133
```terraform
141-
resource "scaleway_vpc_private_network" "pn" {}
134+
#### Default: 1 public endpoint
142135
143136
resource "scaleway_rdb_instance" "main" {
144-
node_type = "DB-DEV-S"
137+
node_type = "db-dev-s"
145138
engine = "PostgreSQL-15"
146-
private_network {
147-
pn_id = scaleway_vpc_private_network.pn.id
148-
enable_ipam = true
149-
}
150-
load_balancer {}
151139
}
152140
```
153141

154-
#### Default: 1 public endpoint
142+
```terraform
143+
### Example Block Storage Low Latency
144+
145+
resource "scaleway_rdb_instance" "main" {
146+
name = "test-rdb-sbs"
147+
node_type = "db-play2-pico"
148+
engine = "PostgreSQL-15"
149+
is_ha_cluster = true
150+
disable_backup = true
151+
user_name = "my_initial_user"
152+
password = "thiZ_is_v&ry_s3cret"
153+
volume_type = "sbs_15k"
154+
volume_size_in_gb = 10
155+
}
156+
```
157+
158+
```terraform
159+
### Example with backup schedule
160+
161+
resource "scaleway_rdb_instance" "main" {
162+
name = "test-rdb"
163+
node_type = "DB-DEV-S"
164+
engine = "PostgreSQL-15"
165+
is_ha_cluster = true
166+
user_name = "my_initial_user"
167+
password = "thiZ_is_v&ry_s3cret"
168+
169+
disable_backup = false
170+
backup_schedule_frequency = 24 # every day
171+
backup_schedule_retention = 7 # keep it one week
172+
}
173+
```
155174

156175
```terraform
176+
### Example with Settings
177+
157178
resource "scaleway_rdb_instance" "main" {
158-
node_type = "db-dev-s"
159-
engine = "PostgreSQL-15"
179+
name = "test-rdb"
180+
node_type = "db-dev-s"
181+
disable_backup = true
182+
engine = "MySQL-8"
183+
user_name = "my_initial_user"
184+
password = "thiZ_is_v&ry_s3cret"
185+
init_settings = {
186+
"lower_case_table_names" = 1
187+
}
188+
settings = {
189+
"max_connections" = "350"
190+
}
160191
}
161192
```
162193

194+
195+
196+
163197
-> **Note** If nothing is defined, your Database Instance will have a default public load-balancer endpoint.
164198

165199
-> **Note** Managed PostgreSQL and MySQL Database Instances are compatible with the [VPC routing](https://www.scaleway.com/en/docs/network/vpc/concepts/#routing) feature, which allows you to connect one or more Database Instances in a Private Network to resources in other Private Networks of the same VPC. This feature is automatically enabled when your Database Instance is connected to a Private Network within a VPC that has routing enabled. Refer to the [How to manage routing](https://www.scaleway.com/en/docs/network/vpc/how-to/manage-routing/) documentation page for more information about VPC routing.
@@ -191,7 +225,11 @@ interruption.
191225

192226
~> **Important** Updates to `user_name` will recreate the Database Instance.
193227

194-
- `password` - (Optional) Password for the first user of the Database Instance.
228+
- `password` - (Optional) Password for the first user of the Database Instance. Only one of `password` or `password_wo` should be specified.
229+
230+
- `password_wo` - (Optional) Password for the first user of the Database Instance in [write-only](https://developer.hashicorp.com/terraform/language/manage-sensitive-data/write-only) mode. Only one of `password` or `password_wo` should be specified. `password_wo` will not be set in the Terraform state. To update the `password_wo`, you must also update the `password_wo_version`.
231+
232+
- `password_wo_version` - (Optional) The version of the [write-only](https://developer.hashicorp.com/terraform/language/manage-sensitive-data/write-only) password. To update the `password_wo`, you must also update the `password_wo_version`.
195233

196234
- `is_ha_cluster` - (Optional) Enable or disable high availability for the Database Instance.
197235

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
### Example Basic
2+
3+
resource "scaleway_rdb_instance" "main" {
4+
name = "test-rdb"
5+
node_type = "DB-DEV-S"
6+
engine = "PostgreSQL-15"
7+
is_ha_cluster = true
8+
disable_backup = true
9+
user_name = "my_initial_user"
10+
password = "thiZ_is_v&ry_s3cret"
11+
encryption_at_rest = true
12+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### Example Engine Upgrade
2+
3+
# Initial creation with PostgreSQL 14
4+
resource "scaleway_rdb_instance" "main" {
5+
name = "my-database"
6+
node_type = "DB-DEV-S"
7+
engine = "PostgreSQL-14"
8+
is_ha_cluster = false
9+
disable_backup = true
10+
user_name = "my_user"
11+
password = "thiZ_is_v&ry_s3cret"
12+
}
13+
14+
# Check available versions for upgrade
15+
output "upgradable_versions" {
16+
value = scaleway_rdb_instance.main.upgradable_versions
17+
}
18+
19+
# To upgrade to PostgreSQL 15, simply change the engine value
20+
# This will trigger a blue/green upgrade with automatic endpoint migration
21+
# resource "scaleway_rdb_instance" "main" {
22+
# name = "my-database"
23+
# node_type = "DB-DEV-S"
24+
# engine = "PostgreSQL-15" # Changed from PostgreSQL-14
25+
# is_ha_cluster = false
26+
# disable_backup = true
27+
# user_name = "my_user"
28+
# password = "thiZ_is_v&ry_s3cret"
29+
# }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### Usage of ephemeral random_password for instance password without storing it in state
2+
3+
// Generate an ephemeral password (not stored in the state)
4+
ephemeral "random_password" "db_password" {
5+
length = 20
6+
special = true
7+
upper = true
8+
lower = true
9+
numeric = true
10+
min_upper = 1
11+
min_lower = 1
12+
min_numeric = 1
13+
min_special = 1
14+
# Exclude characters that might cause issues in some contexts
15+
override_special = "!@#$%^&*()_+-=[]{}|;:,.<>?"
16+
}
17+
18+
// Pass the ephemeral password with password_wo (not stored in the state)
19+
resource "scaleway_rdb_instance" "main" {
20+
name = "test-rdb"
21+
node_type = "DB-DEV-S"
22+
engine = "PostgreSQL-15"
23+
is_ha_cluster = true
24+
disable_backup = true
25+
user_name = "my_initial_user"
26+
password_wo = ephemeral.random_password.db_password.result
27+
password_wo_version = 1
28+
encryption_at_rest = true
29+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#### 1 IPAM Private Network endpoint + 1 public endpoint
2+
3+
resource "scaleway_vpc_private_network" "pn" {}
4+
5+
resource "scaleway_rdb_instance" "main" {
6+
node_type = "DB-DEV-S"
7+
engine = "PostgreSQL-15"
8+
private_network {
9+
pn_id = scaleway_vpc_private_network.pn.id
10+
enable_ipam = true
11+
}
12+
load_balancer {}
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Examples of endpoint configuration
2+
3+
##### Database Instances can have a maximum of 1 public endpoint and 1 private endpoint. They can have both, or none.
4+
5+
#### 1 static Private Network endpoint
6+
7+
resource "scaleway_vpc_private_network" "pn" {
8+
ipv4_subnet {
9+
subnet = "172.16.20.0/22"
10+
}
11+
}
12+
13+
resource "scaleway_rdb_instance" "main" {
14+
node_type = "db-dev-s"
15+
engine = "PostgreSQL-15"
16+
private_network {
17+
pn_id = scaleway_vpc_private_network.pn.id
18+
ip_net = "172.16.20.4/22" # IP address within a given IP network
19+
# enable_ipam = false
20+
}
21+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#### Default: 1 public endpoint
2+
3+
resource "scaleway_rdb_instance" "main" {
4+
node_type = "db-dev-s"
5+
engine = "PostgreSQL-15"
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### Example Block Storage Low Latency
2+
3+
resource "scaleway_rdb_instance" "main" {
4+
name = "test-rdb-sbs"
5+
node_type = "db-play2-pico"
6+
engine = "PostgreSQL-15"
7+
is_ha_cluster = true
8+
disable_backup = true
9+
user_name = "my_initial_user"
10+
password = "thiZ_is_v&ry_s3cret"
11+
volume_type = "sbs_15k"
12+
volume_size_in_gb = 10
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### Example with backup schedule
2+
3+
resource "scaleway_rdb_instance" "main" {
4+
name = "test-rdb"
5+
node_type = "DB-DEV-S"
6+
engine = "PostgreSQL-15"
7+
is_ha_cluster = true
8+
user_name = "my_initial_user"
9+
password = "thiZ_is_v&ry_s3cret"
10+
11+
disable_backup = false
12+
backup_schedule_frequency = 24 # every day
13+
backup_schedule_retention = 7 # keep it one week
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### Example with Settings
2+
3+
resource "scaleway_rdb_instance" "main" {
4+
name = "test-rdb"
5+
node_type = "db-dev-s"
6+
disable_backup = true
7+
engine = "MySQL-8"
8+
user_name = "my_initial_user"
9+
password = "thiZ_is_v&ry_s3cret"
10+
init_settings = {
11+
"lower_case_table_names" = 1
12+
}
13+
settings = {
14+
"max_connections" = "350"
15+
}
16+
}

0 commit comments

Comments
 (0)