Skip to content

Commit 98b4ae1

Browse files
authored
Merge pull request #806 from ovh/dev/aamstutz/update-ldp-retention
feat: Add retention_type to datasource ovh_dbaas_logs_cluster_retention
2 parents e8c00aa + 4220436 commit 98b4ae1

12 files changed

+343
-22
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
77
github.com/hashicorp/go-version v1.7.0
88
github.com/hashicorp/terraform-plugin-framework v1.13.0
9-
github.com/hashicorp/terraform-plugin-framework-validators v0.15.0
9+
github.com/hashicorp/terraform-plugin-framework-validators v0.16.0
1010
github.com/hashicorp/terraform-plugin-go v0.25.0
1111
github.com/hashicorp/terraform-plugin-log v0.9.0
1212
github.com/hashicorp/terraform-plugin-mux v0.16.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7
7878
github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A=
7979
github.com/hashicorp/terraform-plugin-framework v1.13.0 h1:8OTG4+oZUfKgnfTdPTJwZ532Bh2BobF4H+yBiYJ/scw=
8080
github.com/hashicorp/terraform-plugin-framework v1.13.0/go.mod h1:j64rwMGpgM3NYXTKuxrCnyubQb/4VKldEKlcG8cvmjU=
81-
github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 h1:RXMmu7JgpFjnI1a5QjMCBb11usrW2OtAG+iOTIj5c9Y=
82-
github.com/hashicorp/terraform-plugin-framework-validators v0.15.0/go.mod h1:Bh89/hNmqsEWug4/XWKYBwtnw3tbz5BAy1L1OgvbIaY=
81+
github.com/hashicorp/terraform-plugin-framework-validators v0.16.0 h1:O9QqGoYDzQT7lwTXUsZEtgabeWW96zUBh47Smn2lkFA=
82+
github.com/hashicorp/terraform-plugin-framework-validators v0.16.0/go.mod h1:Bh89/hNmqsEWug4/XWKYBwtnw3tbz5BAy1L1OgvbIaY=
8383
github.com/hashicorp/terraform-plugin-go v0.25.0 h1:oi13cx7xXA6QciMcpcFi/rwA974rdTxjqEhXJjbAyks=
8484
github.com/hashicorp/terraform-plugin-go v0.25.0/go.mod h1:+SYagMYadJP86Kvn+TGeV+ofr/R3g4/If0O5sO96MVw=
8585
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=

ovh/data_dbaas_logs_cluster_retention.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"strings"
88

99
"github.com/hashicorp/terraform-plugin-framework/datasource"
10+
"github.com/hashicorp/terraform-plugin-log/tflog"
11+
ovhtypes "github.com/ovh/terraform-provider-ovh/ovh/types"
1012
)
1113

1214
var _ datasource.DataSourceWithConfigure = (*dbaasLogsClusterRetentionDataSource)(nil)
@@ -75,7 +77,7 @@ func (d *dbaasLogsClusterRetentionDataSource) Read(ctx context.Context, req data
7577
return
7678
}
7779

78-
// No retention ID given, try to fetch a retention with given duration
80+
// No retention ID given, try to fetch a retention with given type and duration
7981
var (
8082
retentionIDs []string
8183
availableDurations []string
@@ -87,6 +89,12 @@ func (d *dbaasLogsClusterRetentionDataSource) Read(ctx context.Context, req data
8789
return
8890
}
8991

92+
// If no retention_type given, default on LOGS_INDEXING value
93+
if data.RetentionType.IsNull() {
94+
tflog.Info(ctx, "no retention type defined, defaulting to LOGS_INDEXING")
95+
data.RetentionType = ovhtypes.NewTfStringValue("LOGS_INDEXING")
96+
}
97+
9098
for _, id := range retentionIDs {
9199
var (
92100
retentionData DbaasLogsClusterRetentionModel
@@ -98,6 +106,16 @@ func (d *dbaasLogsClusterRetentionDataSource) Read(ctx context.Context, req data
98106
return
99107
}
100108

109+
if !data.RetentionType.Equal(retentionData.RetentionType) {
110+
tflog.Info(ctx, fmt.Sprintf("skipping retention %s with wrong type %s", retentionData.RetentionId, retentionData.RetentionType))
111+
continue
112+
}
113+
114+
if !retentionData.IsSupported.ValueBool() {
115+
tflog.Info(ctx, fmt.Sprintf("skipping retention %s as it is not supported", retentionData.RetentionId))
116+
continue
117+
}
118+
101119
availableDurations = append(availableDurations, retentionData.Duration.ValueString())
102120
if data.Duration.Equal(retentionData.Duration) {
103121
data.MergeWith(&retentionData)
@@ -108,7 +126,11 @@ func (d *dbaasLogsClusterRetentionDataSource) Read(ctx context.Context, req data
108126
}
109127
}
110128

111-
// No retention found with given duration, error
129+
// No retention found with given duration and type, error
130+
errorDetails := ""
131+
if len(availableDurations) > 0 {
132+
errorDetails = ", available values are: " + strings.Join(availableDurations, ",")
133+
}
112134
resp.Diagnostics.AddError("retention not found",
113-
fmt.Sprintf("no retention was found with duration %s, available values are: %s", data.Duration.ValueString(), strings.Join(availableDurations, ",")))
135+
fmt.Sprintf("no retention was found with duration %s and type %s%s", data.Duration.ValueString(), data.RetentionType.ValueString(), errorDetails))
114136
}

ovh/data_dbaas_logs_cluster_retention_gen.go

+40-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ovh/data_dbaas_logs_cluster_retention_test.go

+116-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func TestAccDataSourceDbaasLogsClusterRetention_basic(t *testing.T) {
4747
"is_supported",
4848
"true",
4949
),
50+
resource.TestCheckResourceAttr(
51+
"data.ovh_dbaas_logs_cluster_retention.ret",
52+
"retention_type",
53+
"LOGS_INDEXING",
54+
),
5055
),
5156
},
5257
},
@@ -90,6 +95,60 @@ func TestAccDataSourceDbaasLogsClusterRetention_by_duration(t *testing.T) {
9095
"is_supported",
9196
"true",
9297
),
98+
resource.TestCheckResourceAttr(
99+
"data.ovh_dbaas_logs_cluster_retention.ret",
100+
"retention_type",
101+
"LOGS_INDEXING",
102+
),
103+
),
104+
},
105+
},
106+
})
107+
}
108+
109+
func TestAccDataSourceDbaasLogsClusterRetention_by_duration_and_type(t *testing.T) {
110+
serviceName := os.Getenv("OVH_DBAAS_LOGS_SERVICE_TEST")
111+
clusterId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_ID")
112+
retentionId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_RETENTION_ID")
113+
114+
config := fmt.Sprintf(`
115+
data "ovh_dbaas_logs_cluster_retention" "ret" {
116+
service_name = "%s"
117+
cluster_id = "%s"
118+
duration = "P1Y"
119+
retention_type = "LOGS_INDEXING"
120+
}`,
121+
serviceName,
122+
clusterId,
123+
)
124+
125+
resource.Test(t, resource.TestCase{
126+
PreCheck: func() { testAccPreCheckDbaasLogsClusterRetention(t) },
127+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
128+
Steps: []resource.TestStep{
129+
{
130+
Config: config,
131+
Check: resource.ComposeTestCheckFunc(
132+
resource.TestCheckResourceAttr(
133+
"data.ovh_dbaas_logs_cluster_retention.ret",
134+
"service_name",
135+
serviceName,
136+
),
137+
resource.TestCheckResourceAttr(
138+
"data.ovh_dbaas_logs_cluster_retention.ret",
139+
"retention_id",
140+
retentionId,
141+
),
142+
resource.TestCheckResourceAttr(
143+
"data.ovh_dbaas_logs_cluster_retention.ret",
144+
"is_supported",
145+
"true",
146+
),
147+
resource.TestCheckResourceAttr(
148+
"data.ovh_dbaas_logs_cluster_retention.ret",
149+
"retention_type",
150+
"LOGS_INDEXING",
151+
),
93152
),
94153
},
95154
},
@@ -116,7 +175,34 @@ func TestAccDataSourceDbaasLogsClusterRetention_by_duration_not_found(t *testing
116175
Steps: []resource.TestStep{
117176
{
118177
Config: config,
119-
ExpectError: regexp.MustCompile("no retention was found with duration P1000Y"),
178+
ExpectError: regexp.MustCompile("no retention was found with duration P1000Y and type LOGS_INDEXING"),
179+
},
180+
},
181+
})
182+
}
183+
184+
func TestAccDataSourceDbaasLogsClusterRetention_by_duration_and_type_not_found(t *testing.T) {
185+
serviceName := os.Getenv("OVH_DBAAS_LOGS_SERVICE_TEST")
186+
clusterId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_ID")
187+
188+
config := fmt.Sprintf(`
189+
data "ovh_dbaas_logs_cluster_retention" "ret" {
190+
service_name = "%s"
191+
cluster_id = "%s"
192+
duration = "P1Y"
193+
retention_type = "METRICS_TENANT"
194+
}`,
195+
serviceName,
196+
clusterId,
197+
)
198+
199+
resource.Test(t, resource.TestCase{
200+
PreCheck: func() { testAccPreCheckDbaasLogsClusterRetention(t) },
201+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
202+
Steps: []resource.TestStep{
203+
{
204+
Config: config,
205+
ExpectError: regexp.MustCompile("no retention was found with duration P1Y and type METRICS_TENANT"),
120206
},
121207
},
122208
})
@@ -146,3 +232,32 @@ func TestAccDataSourceDbaasLogsClusterRetention_missing_params(t *testing.T) {
146232
},
147233
})
148234
}
235+
236+
func TestAccDataSourceDbaasLogsClusterRetention_invalid_params(t *testing.T) {
237+
serviceName := os.Getenv("OVH_DBAAS_LOGS_SERVICE_TEST")
238+
clusterId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_ID")
239+
retentionId := os.Getenv("OVH_DBAAS_LOGS_CLUSTER_RETENTION_ID")
240+
241+
config := fmt.Sprintf(`
242+
data "ovh_dbaas_logs_cluster_retention" "ret" {
243+
service_name = "%s"
244+
cluster_id = "%s"
245+
retention_id = "%s"
246+
retention_type = "LOGS_INDEXING"
247+
}`,
248+
serviceName,
249+
clusterId,
250+
retentionId,
251+
)
252+
253+
resource.Test(t, resource.TestCase{
254+
PreCheck: func() { testAccPreCheckDbaasLogsCluster(t) },
255+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
256+
Steps: []resource.TestStep{
257+
{
258+
Config: config,
259+
ExpectError: regexp.MustCompile(`Attribute \"retention_type\" cannot be specified when \"retention_id\"`),
260+
},
261+
},
262+
})
263+
}

vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/also_requires.go

+17-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/at_least_one_of.go

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)