Skip to content

Commit bcdb630

Browse files
committed
Update terraform provider
1 parent c866ddf commit bcdb630

19 files changed

+248
-733
lines changed

datadog/fwprovider/data_source_datadog_deployment_gate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (d *datadogDeploymentGateDataSource) Read(ctx context.Context, request data
152152
}
153153

154154
func (d *datadogDeploymentGateDataSource) updateState(ctx context.Context, state *datadogDeploymentGateDataSourceModel, deploymentGateData *datadogV2.DeploymentGateResponse) {
155-
state.ID = types.StringValue(*deploymentGateData.Data.Id)
155+
state.ID = types.StringValue(deploymentGateData.Data.Id)
156156

157157
attributes := deploymentGateData.Data.GetAttributes()
158158

datadog/fwprovider/data_source_datadog_deployment_rule.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ type createdByModel struct {
4242
}
4343

4444
type deploymentRuleOptionsModel struct {
45-
OperationName types.String `tfsdk:"operation_name"`
46-
WaitTime types.Int64 `tfsdk:"wait_time"`
4745
ExcludedResources types.List `tfsdk:"excluded_resources"`
4846
Duration types.Int64 `tfsdk:"duration"`
4947
Query types.String `tfsdk:"query"`
@@ -107,11 +105,7 @@ func (d *datadogDeploymentRuleDataSource) Schema(_ context.Context, _ datasource
107105
Blocks: map[string]schema.Block{
108106
"deployment_rule_options_faulty_deployment_detection": schema.SingleNestedBlock{
109107
Attributes: map[string]schema.Attribute{
110-
"operation_name": schema.StringAttribute{
111-
Computed: true,
112-
Description: "The operation name for faulty deployment detection.",
113-
},
114-
"wait_time": schema.Int64Attribute{
108+
"duration": schema.Int64Attribute{
115109
Computed: true,
116110
Description: "The wait time for faulty deployment detection.",
117111
},
@@ -171,14 +165,13 @@ func (d *datadogDeploymentRuleDataSource) updateState(ctx context.Context, state
171165
state.DryRun = types.BoolValue(attributes.GetDryRun())
172166
state.GateId = types.StringValue(attributes.GetGateId())
173167
state.Name = types.StringValue(attributes.GetName())
174-
state.Type = types.StringValue(attributes.GetType())
168+
state.Type = types.StringValue(string(attributes.GetType()))
175169
state.UpdatedAt = types.StringValue(attributes.GetUpdatedAt().String())
176170
if attributes.GetType() == "faulty_deployment_detection" {
177171
options := attributes.GetOptions().DeploymentRuleOptionsFaultyDeploymentDetection
178172
state.Options = &deploymentRuleOptionsModel{
179173
ExcludedResources: stringSliceToTerraformList(options.ExcludedResources),
180-
WaitTime: types.Int64Value(options.GetWaitTime()),
181-
OperationName: types.StringValue(options.GetOperationName()),
174+
Duration: types.Int64Value(options.GetDuration()),
182175
}
183176
} else {
184177
options := attributes.GetOptions().DeploymentRuleOptionsMonitor

datadog/fwprovider/resource_datadog_deployment_gate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (r *deploymentGateResource) buildDeploymentGateRequestBody(ctx context.Cont
249249
}
250250

251251
req := datadogV2.NewCreateDeploymentGateParamsWithDefaults()
252-
req.Data = datadogV2.NewCreateDeploymentGateParamsDataWithDefaults()
252+
req.Data = *datadogV2.NewCreateDeploymentGateParamsDataWithDefaults()
253253
req.Data.SetAttributes(*attributes)
254254

255255
return req, diags
@@ -264,7 +264,7 @@ func (r *deploymentGateResource) buildDeploymentGateUpdateRequestBody(ctx contex
264264
}
265265

266266
req := datadogV2.NewUpdateDeploymentGateParamsWithDefaults()
267-
req.Data = datadogV2.NewUpdateDeploymentGateParamsDataWithDefaults()
267+
req.Data = *datadogV2.NewUpdateDeploymentGateParamsDataWithDefaults()
268268
req.Data.SetAttributes(*attributes)
269269

270270
return req, diags

datadog/fwprovider/resource_datadog_deployment_rule.go

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ func (r *deploymentRuleResource) Schema(_ context.Context, _ resource.SchemaRequ
8484
Optional: true,
8585
Description: "The duration for the rule.",
8686
},
87-
"operation_name": schema.StringAttribute{
88-
Optional: true,
89-
Description: "The operation name for faulty deployment detection.",
90-
},
91-
"wait_time": schema.Int64Attribute{
92-
Optional: true,
93-
Description: "The wait time for faulty deployment detection.",
94-
},
9587
"query": schema.StringAttribute{
9688
Optional: true,
9789
Description: "The query for monitor rules.",
@@ -253,15 +245,13 @@ func (r *deploymentRuleResource) updateState(ctx context.Context, state *deploym
253245
}
254246

255247
if typeVar, ok := attributes.GetTypeOk(); ok {
256-
state.Type = types.StringValue(*typeVar)
248+
state.Type = types.StringValue(string(*typeVar))
257249
}
258250

259251
// Handle options from the response
260252
if options, ok := attributes.GetOptionsOk(); ok {
261253
if state.Options == nil {
262254
state.Options = &deploymentRuleOptionsModel{
263-
OperationName: types.StringNull(),
264-
WaitTime: types.Int64Null(),
265255
ExcludedResources: types.ListNull(types.StringType),
266256
Duration: types.Int64Null(),
267257
Query: types.StringNull(),
@@ -271,11 +261,8 @@ func (r *deploymentRuleResource) updateState(ctx context.Context, state *deploym
271261
// Handle options based on rule type like the data source does
272262
if state.Type.ValueString() == "faulty_deployment_detection" {
273263
if fddOptions := options.DeploymentRuleOptionsFaultyDeploymentDetection; fddOptions != nil {
274-
if operationName, ok := fddOptions.GetOperationNameOk(); ok {
275-
state.Options.OperationName = types.StringPointerValue(operationName)
276-
}
277-
if waitTime, ok := fddOptions.GetWaitTimeOk(); ok {
278-
state.Options.WaitTime = types.Int64PointerValue(waitTime)
264+
if duration, ok := fddOptions.GetDurationOk(); ok {
265+
state.Options.Duration = types.Int64PointerValue(duration)
279266
}
280267
if excludedResources, ok := fddOptions.GetExcludedResourcesOk(); ok {
281268
if excludedResources != nil && len(*excludedResources) > 0 {
@@ -317,17 +304,14 @@ func (r *deploymentRuleResource) buildDeploymentRuleRequestBody(ctx context.Cont
317304

318305
// Handle options based on rule type
319306
if state.Options != nil {
320-
options := datadogV2.CreateDeploymentRuleParamsDataAttributesOptions{}
307+
options := datadogV2.DeploymentRulesOptions{}
321308

322309
if state.Type.ValueString() == "faulty_deployment_detection" {
323310
fddOptions := state.Options
324311
options.DeploymentRuleOptionsFaultyDeploymentDetection = &datadogV2.DeploymentRuleOptionsFaultyDeploymentDetection{}
325312

326-
if !fddOptions.OperationName.IsNull() {
327-
options.DeploymentRuleOptionsFaultyDeploymentDetection.OperationName = fddOptions.OperationName.ValueStringPointer()
328-
}
329-
if !fddOptions.WaitTime.IsNull() {
330-
options.DeploymentRuleOptionsFaultyDeploymentDetection.WaitTime = fddOptions.WaitTime.ValueInt64Pointer()
313+
if !fddOptions.Duration.IsNull() {
314+
options.DeploymentRuleOptionsFaultyDeploymentDetection.Duration = fddOptions.Duration.ValueInt64Pointer()
331315
}
332316
if !fddOptions.ExcludedResources.IsNull() {
333317
var excludedResources []string
@@ -371,17 +355,14 @@ func (r *deploymentRuleResource) buildDeploymentRuleUpdateRequestBody(ctx contex
371355

372356
// Handle options based on rule type
373357
if state.Options != nil {
374-
options := datadogV2.UpdateDeploymentRuleParamsDataAttributesOptions{}
358+
options := datadogV2.DeploymentRulesOptions{}
375359

376360
if state.Type.ValueString() == "faulty_deployment_detection" {
377361
fddOptions := state.Options
378362
options.DeploymentRuleOptionsFaultyDeploymentDetection = &datadogV2.DeploymentRuleOptionsFaultyDeploymentDetection{}
379363

380-
if !fddOptions.OperationName.IsNull() {
381-
options.DeploymentRuleOptionsFaultyDeploymentDetection.OperationName = fddOptions.OperationName.ValueStringPointer()
382-
}
383-
if !fddOptions.WaitTime.IsNull() {
384-
options.DeploymentRuleOptionsFaultyDeploymentDetection.WaitTime = fddOptions.WaitTime.ValueInt64Pointer()
364+
if !fddOptions.Duration.IsNull() {
365+
options.DeploymentRuleOptionsFaultyDeploymentDetection.Duration = fddOptions.Duration.ValueInt64Pointer()
385366
}
386367
if !fddOptions.ExcludedResources.IsNull() {
387368
var excludedResources []string
@@ -406,7 +387,7 @@ func (r *deploymentRuleResource) buildDeploymentRuleUpdateRequestBody(ctx contex
406387
}
407388

408389
req := datadogV2.NewUpdateDeploymentRuleParamsWithDefaults()
409-
req.Data = datadogV2.NewUpdateDeploymentRuleParamsDataWithDefaults()
390+
req.Data = *datadogV2.NewUpdateDeploymentRuleParamsDataWithDefaults()
410391
req.Data.SetAttributes(*attributes)
411392

412393
return req, diags
@@ -422,24 +403,22 @@ func (r *deploymentRuleResource) validateTypeOptionsMatch(ctx context.Context, s
422403
ruleType := state.Type.ValueString()
423404

424405
// Check for faulty_deployment_detection specific options
425-
hasFddOptions := (!state.Options.OperationName.IsNull() ||
426-
!state.Options.WaitTime.IsNull() ||
427-
!state.Options.ExcludedResources.IsNull())
406+
hasFddOptions :=
407+
!state.Options.ExcludedResources.IsNull()
428408

429409
// Check for monitor specific options
430-
hasMonitorOptions := (!state.Options.Duration.IsNull() ||
431-
!state.Options.Query.IsNull())
410+
hasMonitorOptions := !state.Options.Query.IsNull()
432411

433412
if ruleType == "faulty_deployment_detection" && hasMonitorOptions {
434413
diags.AddError(
435414
"Invalid options for deployment rule type",
436-
"Rule type 'faulty_deployment_detection' cannot use monitor options (duration, query). "+
437-
"Use faulty deployment detection options instead: operation_name, wait_time, excluded_resources.",
415+
"Rule type 'faulty_deployment_detection' cannot use monitor options (query). "+
416+
"Use faulty deployment detection options instead: duration, excluded_resources.",
438417
)
439418
} else if ruleType == "monitor" && hasFddOptions {
440419
diags.AddError(
441420
"Invalid options for deployment rule type",
442-
"Rule type 'monitor' cannot use faulty deployment detection options (operation_name, wait_time, excluded_resources). "+
421+
"Rule type 'monitor' cannot use faulty deployment detection options (excluded_resources). "+
443422
"Use monitor options instead: duration, query.",
444423
)
445424
}

datadog/tests/provider_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ var testFiles2EndpointTags = map[string]string{
301301
"tests/data_source_datadog_incident_notification_template_test": "incidents",
302302
"tests/resource_datadog_incident_notification_rule_test": "incidents",
303303
"tests/data_source_datadog_incident_notification_rule_test": "incidents",
304+
"tests/data_source_datadog_deployment_gate_test": "deployment-gates",
305+
"tests/data_source_datadog_deployment_rule_test": "deployment-gates",
306+
"tests/resource_datadog_deployment_rule_test": "deployment-gates",
307+
"tests/resource_datadog_deployment_gate_test": "deployment-gates",
304308
}
305309

306310
// getEndpointTagValue traverses callstack frames to find the test function that invoked this call;

datadog/tests/resource_datadog_deployment_gate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestAccDeploymentGateBasic(t *testing.T) {
2626
Check: resource.ComposeTestCheckFunc(
2727
testAccCheckDatadogDeploymentGateExists(providers.frameworkProvider),
2828
resource.TestCheckResourceAttr(
29-
"datadog_deployment_gate.foo", "dry_run", "UPDATE ME"),
29+
"datadog_deployment_gate.foo", "dry_run", "false"),
3030
resource.TestCheckResourceAttr(
3131
"datadog_deployment_gate.foo", "env", "production"),
3232
resource.TestCheckResourceAttr(
@@ -42,9 +42,9 @@ func TestAccDeploymentGateBasic(t *testing.T) {
4242
func testAccCheckDatadogDeploymentGate(uniq string) string {
4343
// Update me to make use of the unique value
4444
return fmt.Sprintf(`resource "datadog_deployment_gate" "foo" {
45-
dry_run = "UPDATE ME"
45+
dry_run = "false"
4646
env = "production"
47-
identifier = "my-gate"
47+
identifier = %s
4848
service = "my-service"
4949
}`, uniq)
5050
}

datadog/tests/resource_datadog_deployment_rule_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func TestAccDeploymentRuleBasic(t *testing.T) {
4141
func testAccCheckDatadogDeploymentRule(uniq string) string {
4242
// Update me to make use of the unique value
4343
return fmt.Sprintf(`resource "datadog_deployment_rule" "foo" {
44-
gate_id = "UPDATE ME"
45-
dry_run = "UPDATE ME"
44+
gate_id = %s
45+
dry_run = "false"
4646
name = "My deployment rule"
4747
type = "faulty_deployment_detection"
4848
}`, uniq)

docs/data-sources/custom_allocation_rule.md

Lines changed: 0 additions & 120 deletions
This file was deleted.

0 commit comments

Comments
 (0)