diff --git a/ovh/data_dbaas_logs_output_graylog_stream_test.go b/ovh/data_dbaas_logs_output_graylog_stream_test.go index 152f4f0a9..c989f0d7c 100644 --- a/ovh/data_dbaas_logs_output_graylog_stream_test.go +++ b/ovh/data_dbaas_logs_output_graylog_stream_test.go @@ -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, @@ -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, + ), + ), + }, + }, + }) +} diff --git a/ovh/resource_dbaas_logs_output_graylog_stream_test.go b/ovh/resource_dbaas_logs_output_graylog_stream_test.go index 35c0c7a8d..23e4052fe 100644 --- a/ovh/resource_dbaas_logs_output_graylog_stream_test.go +++ b/ovh/resource_dbaas_logs_output_graylog_stream_test.go @@ -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", @@ -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, @@ -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, + ), + ), + }, + }, + }) +} diff --git a/website/docs/r/dbaas_logs_graylog_output_stream.html.markdown b/website/docs/r/dbaas_logs_output_graylog_stream.html.markdown similarity index 76% rename from website/docs/r/dbaas_logs_graylog_output_stream.html.markdown rename to website/docs/r/dbaas_logs_output_graylog_stream.html.markdown index d06a68f1a..4c35ac3ae 100644 --- a/website/docs/r/dbaas_logs_graylog_output_stream.html.markdown +++ b/website/docs/r/dbaas_logs_output_graylog_stream.html.markdown @@ -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 @@ -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: