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
12 changes: 12 additions & 0 deletions docs/data-sources/postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ description: |-
- `high_availability_enabled` (Boolean) Whether high availability is enabled for this postgres
- `ip_allow_list` (Attributes Set) List of IP addresses that are allowed to connect to the Redis instance. If no IP addresses are provided, only connections via the private network will be allowed. (see [below for nested schema](#nestedatt--ip_allow_list))
- `name` (String) Descriptive name for this postgres
- `parameter_overrides` (Map of String) Parameter overrides for the postgres instance.
- `plan` (String) Plan to use for this postgres
- `read_replicas` (Attributes Set) List of read replicas. (see [below for nested schema](#nestedatt--read_replicas))
- `region` (String) Region the postgres instance in
Expand Down Expand Up @@ -80,4 +81,15 @@ Read-Only:
Read-Only:

- `id` (String) ID of the read replica.
- `log_stream_override` (Attributes) The [log stream override settings](https://render.com/docs/log-streams#overriding-defaults) for this replica. (see [below for nested schema](#nestedatt--read_replicas--log_stream_override))
- `name` (String) Name of the read replica.
- `parameter_overrides` (Map of String) Parameter overrides for the read replica.

<a id="nestedatt--read_replicas--log_stream_override"></a>
### Nested Schema for `read_replicas.log_stream_override`

Read-Only:

- `endpoint` (String) The endpoint logs are sent to.
- `setting` (String) Whether to send or drop logs for this replica.
- `token` (String, Sensitive) The token used when sending logs.
16 changes: 15 additions & 1 deletion docs/resources/postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ resource "render_postgres" "example" {
- `name` (String) Descriptive name for this postgres
- `plan` (String) Plan to use for this postgres. Must be `free`, a basic plan (like `basic_256mb`), a pro plan (like `pro_4gb`), an accelerated plan (like `accelerated_16gb`), `starter`, `standard`, `pro`, `pro_plus`, or a custom plan
- `region` (String) Region the postgres instance in
- `version` (String) The Postgres version. Currently Supported: `11`, `12`, `13`, `14`, `15`, `16`, `17`, and `18`
- `version` (String) The Postgres version. Currently supported: `11`, `12`, `13`, `14`, `15`, `16`, `17`, and `18`
Comment thread
tuckerchapin marked this conversation as resolved.

### Optional

Expand Down Expand Up @@ -101,12 +101,26 @@ Required:

Optional:

- `log_stream_override` (Attributes) Configure the [log stream override settings](https://render.com/docs/log-streams#overriding-defaults) for this replica. These take precedence over the workspace's default log stream and any setting on the primary. (see [below for nested schema](#nestedatt--read_replicas--log_stream_override))
- `parameter_overrides` (Map of String) Parameter overrides for the read replica.

Read-Only:

- `id` (String) ID of the read replica.

<a id="nestedatt--read_replicas--log_stream_override"></a>
### Nested Schema for `read_replicas.log_stream_override`

Required:

- `setting` (String) Whether to send or drop logs for this replica. Must be one of `send` or `drop`.

Optional:

- `endpoint` (String) The endpoint to send logs to.
- `token` (String, Sensitive) The token to use when sending logs.



<a id="nestedatt--connection_info"></a>
### Nested Schema for `connection_info`
Expand Down
12 changes: 7 additions & 5 deletions internal/provider/common/logstreamoverride.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package common
import (
"fmt"

"terraform-provider-render/internal/client/logs"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"terraform-provider-render/internal/client/logs"
)

var logStreamTypes = map[string]attr.Type{
Expand All @@ -25,9 +26,10 @@ func LogStreamOverrideFromClient(client *logs.ResourceLogStreamSetting, plan typ
setting = *client.Setting
}

endpoint := ""
if client.Endpoint != nil {
endpoint = *client.Endpoint
// endpoint being an empty string or null are functionally equivalent
endpoint := types.StringNull()
if client.Endpoint != nil && *client.Endpoint != "" {
endpoint = types.StringValue(*client.Endpoint)
}

planAttrs := plan.Attributes()
Expand All @@ -44,7 +46,7 @@ func LogStreamOverrideFromClient(client *logs.ResourceLogStreamSetting, plan typ
logStreamTypes,
map[string]attr.Value{
"setting": types.StringValue(string(setting)),
"endpoint": types.StringValue(endpoint),
"endpoint": endpoint,
"token": token,
},
)
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/postgres/datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,11 @@ func (d *postgresDataSource) Read(ctx context.Context, req datasource.ReadReques
return
}

resp.State.Set(ctx, postgres.ModelFromClient(&pg, &secrets, logStreamOverrides, plan, resp.Diagnostics))
replicaLogStreams, err := postgres.GetReplicaLogStreamOverrides(ctx, d.client, pg.ReadReplicas)
if err != nil {
resp.Diagnostics.AddError("unable to get replica log stream overrides", err.Error())
return
}

resp.State.Set(ctx, postgres.ModelFromClient(&pg, &secrets, logStreamOverrides, replicaLogStreams, plan, resp.Diagnostics))
}
6 changes: 5 additions & 1 deletion internal/provider/postgres/datasource/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ func TestAccPostgresDataSource(t *testing.T) {
}),
resource.TestCheckResourceAttr(resourceName, "database_user", "test_user"),
resource.TestCheckResourceAttr(resourceName, "high_availability_enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "plan", "basic_256mb"),
resource.TestCheckResourceAttr(resourceName, "plan", "pro_4gb"),
resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "20"),
resource.TestCheckResourceAttr(resourceName, "region", "oregon"),
resource.TestCheckResourceAttr(resourceName, "role", "primary"),
resource.TestCheckResourceAttr(resourceName, "version", "16"),

resource.TestCheckResourceAttr(resourceName, "log_stream_override.setting", "drop"),
resource.TestCheckResourceAttr(resourceName, "read_replicas.0.name", "read-replica"),
resource.TestCheckResourceAttr(resourceName, "read_replicas.0.log_stream_override.setting", "drop"),

resource.TestCheckResourceAttrWith(resourceName, "connection_info.password", func(value string) error {
if len(value) != 32 {
return fmt.Errorf("expected password to be 32 characters, got: %d", len(value))
Expand Down
1 change: 1 addition & 0 deletions internal/provider/postgres/datasource/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func PostgresDataSourceSchema(ctx context.Context) schema.Schema {
MarkdownDescription: "Parameter overrides for the read replica.",
Computed: true,
},
"log_stream_override": datasource.ReplicaLogStreamOverride,
},
},
Computed: true,
Expand Down
25 changes: 18 additions & 7 deletions internal/provider/postgres/datasource/testdata/postgres.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
resource "render_postgres" "test" {
name = "some-name"
database_name = "test_name_mnop"
database_user = "test_user"
name = "some-name"
database_name = "test_name_mnop"
database_user = "test_user"
high_availability_enabled = false
plan = "basic_256mb"
disk_size_gb = 20
region = "oregon"
version = "16"
plan = "pro_4gb"
disk_size_gb = 20
region = "oregon"
version = "16"

log_stream_override = {
setting = "drop"
}

read_replicas = [{
name = "read-replica"
log_stream_override = {
setting = "drop"
}
}]
}

data "render_postgres" "test" {
Expand Down
Loading
Loading