Skip to content

Commit

Permalink
Merge pull request #692 from ovh/dev/aamstutz/dbaas-logs-stream-defin…
Browse files Browse the repository at this point in the history
…e-retention

doc: Explain how to define a retention period on resource ovh_dbaas_logs_output_graylog_stream
  • Loading branch information
amstuta committed Jul 19, 2024
2 parents 3f09437 + 9cd776e commit bde0453
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 27 deletions.
91 changes: 76 additions & 15 deletions ovh/data_dbaas_logs_output_graylog_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,22 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const testAccDataSourceDbaasLogsOutputGraylogStream_basic = `
resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = "%s"
title = "%s"
description = "%s"
}
data "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = ovh_dbaas_logs_output_graylog_stream.stream.service_name
title = ovh_dbaas_logs_output_graylog_stream.stream.title
}
`

func TestAccDataSourceDbaasLogsOutputGraylogStream_basic(t *testing.T) {
serviceName := os.Getenv("OVH_DBAAS_LOGS_SERVICE_TEST")
title := acctest.RandomWithPrefix(test_prefix)
desc := acctest.RandomWithPrefix(test_prefix)

config := fmt.Sprintf(
testAccDataSourceDbaasLogsOutputGraylogStream_basic,
config := fmt.Sprintf(`
resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = "%s"
title = "%s"
description = "%s"
}
data "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = ovh_dbaas_logs_output_graylog_stream.stream.service_name
title = ovh_dbaas_logs_output_graylog_stream.stream.title
}`,
serviceName,
title,
desc,
Expand Down Expand Up @@ -61,3 +57,68 @@ func TestAccDataSourceDbaasLogsOutputGraylogStream_basic(t *testing.T) {
},
})
}

func TestAccDataSourceDbaasLogsOutputGraylogStream_with_retention(t *testing.T) {
serviceName := os.Getenv("OVH_DBAAS_LOGS_SERVICE_TEST")
clusterId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_ID")
retentionId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_RETENTION_ID")
title := acctest.RandomWithPrefix(test_prefix)
desc := acctest.RandomWithPrefix(test_prefix)

config := fmt.Sprintf(`
data "ovh_dbaas_logs_cluster_retention" "retention" {
service_name = "%s"
cluster_id = "%s"
duration = "P1Y"
}
resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = "%s"
title = "%s"
description = "%s"
retention_id = data.ovh_dbaas_logs_cluster_retention.retention.retention_id
}
data "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = ovh_dbaas_logs_output_graylog_stream.stream.service_name
title = ovh_dbaas_logs_output_graylog_stream.stream.title
}`,
serviceName,
clusterId,
serviceName,
title,
desc,
)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckDbaasLogsClusterRetention(t) },

ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.ovh_dbaas_logs_output_graylog_stream.stream",
"description",
desc,
),
resource.TestCheckResourceAttr(
"data.ovh_dbaas_logs_output_graylog_stream.stream",
"title",
title,
),
resource.TestCheckResourceAttrSet(
"data.ovh_dbaas_logs_output_graylog_stream.stream",
"write_token",
),
resource.TestCheckResourceAttr(
"data.ovh_dbaas_logs_output_graylog_stream.stream",
"retention_id",
retentionId,
),
),
},
},
})
}
78 changes: 68 additions & 10 deletions ovh/resource_dbaas_logs_output_graylog_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const testAccResourceDbaasLogsOutputGraylogStream_basic = `
resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = "%s"
title = "%s"
description = "%s"
}
`

func init() {
resource.AddTestSweepers("ovh_dbaas_logs_output_graylog_stream", &resource.Sweeper{
Name: "ovh_dbaas_logs_output_graylog_stream",
Expand Down Expand Up @@ -102,8 +94,13 @@ func TestAccResourceDbaasLogsOutputGraylogStream_basic(t *testing.T) {
title := acctest.RandomWithPrefix(test_prefix)
desc := acctest.RandomWithPrefix(test_prefix)

config := fmt.Sprintf(
testAccResourceDbaasLogsOutputGraylogStream_basic,
config := fmt.Sprintf(`
resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = "%s"
title = "%s"
description = "%s"
}
`,
serviceName,
title,
desc,
Expand Down Expand Up @@ -136,3 +133,64 @@ func TestAccResourceDbaasLogsOutputGraylogStream_basic(t *testing.T) {
},
})
}

func TestAccResourceDbaasLogsOutputGraylogStream_with_retention(t *testing.T) {
serviceName := os.Getenv("OVH_DBAAS_LOGS_SERVICE_TEST")
clusterId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_ID")
retentionId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_RETENTION_ID")
title := acctest.RandomWithPrefix(test_prefix)
desc := acctest.RandomWithPrefix(test_prefix)

config := fmt.Sprintf(`
data "ovh_dbaas_logs_cluster_retention" "retention" {
service_name = "%s"
cluster_id = "%s"
duration = "P1Y"
}
resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = "%s"
title = "%s"
description = "%s"
retention_id = data.ovh_dbaas_logs_cluster_retention.retention.retention_id
}
`,
serviceName,
clusterId,
serviceName,
title,
desc,
)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckDbaasLogsClusterRetention(t) },

ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"ovh_dbaas_logs_output_graylog_stream.stream",
"description",
desc,
),
resource.TestCheckResourceAttr(
"ovh_dbaas_logs_output_graylog_stream.stream",
"title",
title,
),
resource.TestCheckResourceAttrSet(
"ovh_dbaas_logs_output_graylog_stream.stream",
"write_token",
),
resource.TestCheckResourceAttr(
"ovh_dbaas_logs_output_graylog_stream.stream",
"retention_id",
retentionId,
),
),
},
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
subcategory : "Logs Data Platform"
---

# ovh_dbaas_logs_graylog_output_stream
# ovh_dbaas_logs_output_graylog_stream

Creates a dbaas logs graylog output stream.
Creates a DBaaS Logs Graylog output stream.

## Example Usage

Expand All @@ -16,6 +16,23 @@ resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
}
```

To define the retention of the stream, you can use the following configuration:

```hcl
data "ovh_dbaas_logs_cluster_retention" "retention" {
service_name = "ldp-xx-xxxxx"
cluster_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
duration = "P14D"
}
resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
service_name = "...."
title = "my stream"
description = "my graylog stream"
retention_id = data.ovh_dbaas_logs_cluster_retention.retention.retention_id
}
```

## Argument Reference

The following arguments are supported:
Expand Down

0 comments on commit bde0453

Please sign in to comment.