Skip to content
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

Databases: Add Logsink Support #1210

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
508 changes: 508 additions & 0 deletions digitalocean/database/resource_database_logsink.go

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions digitalocean/database/resource_database_logsink_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package database_test

import (
"fmt"
"testing"

"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/acceptance"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDigitalOceanDatabaseLogsink_Basic(t *testing.T) {
name := acceptance.RandomTestName()
dbConfig := fmt.Sprintf(testAccCheckDigitalOceanDatabaseClusterPostgreSQL, name, "15")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanDatabaseClusterDestroy,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseLogsinkBasic, dbConfig, "lname", "opensearch", "https://user:[email protected]:25060", "logs", 5),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("digitalocean_database_logsink.logsink", "opensearch_config.0.url", "https://user:[email protected]:25060"),
resource.TestCheckResourceAttr("digitalocean_database_logsink.logsink", "opensearch_config.0.index_prefix", "logs"),
resource.TestCheckResourceAttr("digitalocean_database_logsink.logsink", "opensearch_config.0.index_days_max", "5"),
resource.TestCheckResourceAttr("digitalocean_database_logsink.logsink", "sink_type", "opensearch"),
resource.TestCheckResourceAttr("digitalocean_database_logsink.logsink", "sink_name", "lname"),
),
},
{
Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseLogsinkBasic, dbConfig, "new-lname", "opensearch", "https://user:[email protected]:25060", "logs", 4),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("digitalocean_database_logsink.logsink", "sink_name", "new-lname"),
resource.TestCheckResourceAttr("digitalocean_database_logsink.logsink", "opensearch_config.0.index_days_max", "4"),
),
},
},
})
}

const testAccCheckDigitalOceanDatabaseLogsinkBasic = `
%s
resource "digitalocean_database_logsink" "logsink" {
cluster_id = digitalocean_database_cluster.foobar.id
sink_name = "%s"
sink_type = "%s"
opensearch_config {
url = "%s"
index_prefix = "%s"
index_days_max = %d
timeout = 10
}
}`
1 change: 1 addition & 0 deletions digitalocean/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func Provider() *schema.Provider {
"digitalocean_database_kafka_config": database.ResourceDigitalOceanDatabaseKafkaConfig(),
"digitalocean_database_opensearch_config": database.ResourceDigitalOceanDatabaseOpensearchConfig(),
"digitalocean_database_kafka_topic": database.ResourceDigitalOceanDatabaseKafkaTopic(),
"digitalocean_database_logsink": database.ResourceDigitalOceanDatabaseLogsink(),
"digitalocean_domain": domain.ResourceDigitalOceanDomain(),
"digitalocean_droplet": droplet.ResourceDigitalOceanDroplet(),
"digitalocean_droplet_snapshot": snapshot.ResourceDigitalOceanDropletSnapshot(),
Expand Down
104 changes: 104 additions & 0 deletions docs/resources/database_logsink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
page_title: "DigitalOcean: digitalocean_database_logsink"
---

# digitalocean\_database\_logsink

Provides a DigitalOcean database logsink capabilities. Can be configured with rsyslog, elasticsearch, and opensearch.

## Example Usage

```hcl
resource "digitalocean_database_logsink" "logsink-01" {
cluster_id = digitalocean_database_cluster.doby.id
sink_name = "sinkexample1"
sink_type = "opensearch"
opensearch_config {
url = "https://user:[email protected]:25060"
index_prefix = "opensearch-logs"
index_days_max = 5
}
}
resource "digitalocean_database_logsink" "logsink-02" {
cluster_id = digitalocean_database_cluster.dotest.id
sink_name = "sinkexample2"
sink_type = "rsyslog"
rsyslog_config {
server = "192.168.10.2"
port = 514
tls = "true"
format = "rfc5424"
logline = "msg"
sd = "test-2"
}
}
resource "digitalocean_database_logsink" "logsink-03" {
cluster_id = digitalocean_database_cluster.doby.id
sink_name = "sinkexample3"
sink_type = "elasticsearch"
opensearch_config {
url = "https://user:[email protected]:25060"
index_prefix = "opensearch-logs"
index_days_max = 3
}
}
resource "digitalocean_database_cluster" "doby" {
name = "dobydb"
engine = "pg"
version = "15"
size = "db-s-1vcpu-2gb"
region = "nyc1"
node_count = 1
tags = ["production"]
}
```

## Argument Reference

The following arguments are supported. See the [DigitalOcean API documentation](https://docs.digitalocean.com/reference/api/api-reference/#operation/databases_create_logsink)
for additional details on each option.

* `cluster_id` - (Required) The ID of the target MySQL cluster.
* `sink_name` - (Required) The name of the Logsink.
* `sink_type` - (Required) Sink type. Enum: `rsyslog` `elasticsearch` `opensearch`
* `config` - (Required) Logsink configurations.
- `rsyslog` configuration options:
- `server` - (Required) The DNS name or IPv4 address of the rsyslog server.
- `port` - (Required) An integer of the internal port on which the rsyslog server is listening.
- `tls` - (Required) A boolean to use TLS (as the messages are not filtered and may contain sensitive information, it is highly recommended to set this to true if the remote server supports it).
- `format` - (Required) A message format used by the server, this can be either rfc3164 (the old BSD style message format), rfc5424 (current syslog message format) or custom. Enum: `rfc5424`, `rfc3164`, or `custom`.
- `logline` - (Optional) Only required if format == custom. Syslog log line template for a custom format, supporting limited rsyslog style templating (using %tag%). Supported tags are: HOSTNAME, app-name, msg, msgid, pri, procid, structured-data, timestamp and timestamp:::date-rfc3339.
- `sd` - (Optional) content of the structured data block of rfc5424 message.
- `ca` - (Optional) PEM encoded CA certificate.
- `key` - (Optional) (PEM format) client key if the server requires client authentication
- `cert` - (Optional) (PEM format) client cert to use
- `elasticsearch` configuration options:
- `url` - (Required) Elasticsearch connection URL.
- `index_prefix` - (Required) Elasticsearch index prefix.
- `index_days_max` - (Optional) Maximum number of days of logs to keep.
- `timeout` - (Optional) Elasticsearch request timeout limit.
- `ca` - (Optional) PEM encoded CA certificate.
- `opensearch` configuration options:
- `url` - (Required) Opensearch connection URL.
- `index_prefix` - (Required) Opensearch index prefix.
- `index_days_max` - (Optional) Maximum number of days of logs to keep.
- `timeout` - (Optional) Opensearch request timeout limit.
- `ca` - (Optional) PEM encoded CA certificate.

## Attributes Reference

All above attributes are exported. If an attribute was set outside of Terraform, it will be computed.

## Import

A MySQL database cluster's configuration can be imported using the `id` the parent cluster, e.g.

```
terraform import digitalocean_database_mysql_config.example 4b62829a-9c42-465b-aaa3-84051048e712
```
36 changes: 36 additions & 0 deletions examples/logsink/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.8.0"
}
}
}

provider "digitalocean" {
# You need to set this in your .bashrc
# export DIGITALOCEAN_TOKEN="Your API TOKEN"
#
}

resource "digitalocean_database_logsink" "logsink-01" {
cluster_id = digitalocean_database_cluster.doby.id
sink_name = "fox2"
sink_type = "opensearch"

opensearch_config {
url = "https://user:[email protected]:25060"
index_prefix = "opensearch-logs"
index_days_max = 5
}
}

resource "digitalocean_database_cluster" "doby" {
name = "dobydb"
engine = "pg"
version = "15"
size = "db-s-1vcpu-2gb"
region = "nyc1"
node_count = 1
tags = ["production"]
}
22 changes: 22 additions & 0 deletions examples/tutorial/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = ">= 2.8.0"
}
}
}

provider "digitalocean" {
# You need to set this in your .bashrc
# export DIGITALOCEAN_TOKEN="Your API TOKEN"
#
}


resource "digitalocean_droplet" "web" {
image = "ubuntu-20-04-x64"
name = "web2"
region = "nyc2"
size = "s-1vcpu-1gb"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/digitalocean/terraform-provider-digitalocean

require (
github.com/aws/aws-sdk-go v1.42.18
github.com/digitalocean/godo v1.126.1-0.20241004175533-dfe74ef3d8bb
github.com/digitalocean/godo v1.126.1-0.20241015182733-2c2e059f2ea4
github.com/hashicorp/awspolicyequivalence v1.5.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-uuid v1.0.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.126.1-0.20241004175533-dfe74ef3d8bb h1:D6/pJ6+5wMkpwaF2HMJqvhlPlxWdlbpKx6bOpy8sbBg=
github.com/digitalocean/godo v1.126.1-0.20241004175533-dfe74ef3d8bb/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc=
github.com/digitalocean/godo v1.126.1-0.20241015182733-2c2e059f2ea4 h1:7CBSVopixDaCNKGsRZjSvs9vPa/3IZ9gTwAIV4gWpO4=
github.com/digitalocean/godo v1.126.1-0.20241015182733-2c2e059f2ea4/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down
39 changes: 22 additions & 17 deletions vendor/github.com/digitalocean/godo/databases.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ github.com/aws/aws-sdk-go/service/sts/stsiface
# github.com/davecgh/go-spew v1.1.1
## explicit
github.com/davecgh/go-spew/spew
# github.com/digitalocean/godo v1.126.1-0.20241004175533-dfe74ef3d8bb
# github.com/digitalocean/godo v1.126.1-0.20241015182733-2c2e059f2ea4
## explicit; go 1.22
github.com/digitalocean/godo
github.com/digitalocean/godo/metrics
Expand Down
Loading