Skip to content

Commit

Permalink
Merge branch 'master' into hanting.zhang-add-datadog_dashboard_list-d…
Browse files Browse the repository at this point in the history
…atasource-with-tf-framework
  • Loading branch information
HantingZhang2 committed Aug 2, 2023
2 parents 0d2dd05 + ece34c3 commit 334271c
Show file tree
Hide file tree
Showing 22 changed files with 1,694 additions and 10 deletions.
2 changes: 1 addition & 1 deletion datadog/fwprovider/data_source_datadog_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (d *datadogTeamDataSource) Read(ctx context.Context, req datasource.ReadReq
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r *datadogTeamDataSource) updateState(state *datadogTeamDataSourceModel, teamData *datadogV2.TeamData) {
func (r *datadogTeamDataSource) updateState(state *datadogTeamDataSourceModel, teamData *datadogV2.Team) {
state.ID = types.StringValue(teamData.GetId())
attributes := teamData.GetAttributes()

Expand Down
7 changes: 7 additions & 0 deletions datadog/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
var Resources = []func() resource.Resource{
NewAPIKeyResource,
NewDashboardListResource,
NewDowntimeScheduleResource,
NewIntegrationCloudflareAccountResource,
NewIntegrationConfluentAccountResource,
NewIntegrationConfluentResourceResource,
Expand Down Expand Up @@ -347,6 +348,12 @@ func defaultConfigureFunc(p *FrameworkProvider, request *provider.ConfigureReque
ddClientConfig.UserAgent = utils.GetUserAgentFramework(ddClientConfig.UserAgent, request.TerraformVersion)
ddClientConfig.Debug = logging.IsDebugOrHigher()

// Temp - enable Downtime v2 which is currently in private beta
ddClientConfig.SetUnstableOperationEnabled("v2.CancelDowntime", true)
ddClientConfig.SetUnstableOperationEnabled("v2.CreateDowntime", true)
ddClientConfig.SetUnstableOperationEnabled("v2.GetDowntime", true)
ddClientConfig.SetUnstableOperationEnabled("v2.UpdateDowntime", true)

if !config.ApiUrl.IsNull() && config.ApiUrl.ValueString() != "" {
parsedAPIURL, parseErr := url.Parse(config.ApiUrl.ValueString())
if parseErr != nil {
Expand Down
593 changes: 593 additions & 0 deletions datadog/fwprovider/resource_datadog_downtime_schedule.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package planmodifiers

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
)

type removeBlockModifier struct {
}

func RemoveBlockModifier() planmodifier.Object {
return removeBlockModifier{}
}

func (m removeBlockModifier) Description(context.Context) string {
return "Set removed block to null."
}

func (m removeBlockModifier) MarkdownDescription(ctx context.Context) string {
return m.Description(ctx)
}

func (m removeBlockModifier) PlanModifyObject(ctx context.Context, req planmodifier.ObjectRequest, resp *planmodifier.ObjectResponse) {
// Older versions of terraform have a bug where removing a block results in 'planned for existence but config wants absence'.
// To work around this we can set the block to null.
// Reference: https://github.com/hashicorp/terraform/issues/32460
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/603#issuecomment-1371358108
if req.ConfigValue.IsNull() {
resp.PlanValue = req.ConfigValue
}
}
9 changes: 9 additions & 0 deletions datadog/internal/utils/api_instances_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type ApiInstances struct {
cloudWorkloadSecurityApiV2 *datadogV2.CloudWorkloadSecurityApi
confluentCloudApiV2 *datadogV2.ConfluentCloudApi
dashboardListsApiV2 *datadogV2.DashboardListsApi
downtimesApiV2 *datadogV2.DowntimesApi
eventsApiV2 *datadogV2.EventsApi
fastlyIntegrationApiV2 *datadogV2.FastlyIntegrationApi
gcpStsIntegrationApiV2 *datadogV2.GCPIntegrationApi
Expand Down Expand Up @@ -351,6 +352,14 @@ func (i *ApiInstances) GetCloudWorkloadSecurityApiV2() *datadogV2.CloudWorkloadS
return i.cloudWorkloadSecurityApiV2
}

// GetDowntimesApiV2 get instance of DowntimesApi
func (i *ApiInstances) GetDowntimesApiV2() *datadogV2.DowntimesApi {
if i.downtimesApiV2 == nil {
i.downtimesApiV2 = datadogV2.NewDowntimesApi(i.HttpClient)
}
return i.downtimesApiV2
}

// GetDashboardListsApiV2 get instance of DashboardListsApi
func (i *ApiInstances) GetDashboardListsApiV2() *datadogV2.DashboardListsApi {
if i.dashboardListsApiV2 == nil {
Expand Down
38 changes: 38 additions & 0 deletions datadog/internal/validators/time_format_validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package validators

import (
"context"
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

type timeFormatValidator struct {
expectedFormat string
}

func (m timeFormatValidator) Description(context.Context) string {
return fmt.Sprintf("field is standardized to %v format", m.expectedFormat)
}

func (m timeFormatValidator) MarkdownDescription(ctx context.Context) string {
return m.Description(ctx)
}

func (m timeFormatValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) {
if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() {
return
}
if _, err := time.Parse(m.expectedFormat, req.ConfigValue.ValueString()); err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("property \"%s\" must be of the format %v", req.Path.String(), m.expectedFormat),
fmt.Sprintf("was %v", req.ConfigValue.ValueString()),
)
return
}
}

func TimeFormatValidator(expectedFormat string) validator.String {
return timeFormatValidator{expectedFormat}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-07-26T11:03:06.350353-07:00
110 changes: 110 additions & 0 deletions datadog/tests/cassettes/TestAccDowntimeScheduleBasicOneTime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
version: 1
interactions:
- request:
body: |
{"data":{"attributes":{"display_timezone":"","monitor_identifier":{"monitor_tags":["cat:hat","mat:sat"]},"mute_first_recovery_notification":false,"notify_end_types":[],"schedule":{"end":null,"start":"2050-01-02T03:04:05Z"},"scope":"env:(staging OR tf-TestAccDowntimeScheduleBasicOneTime-local-1690394586)"},"type":"downtime"}}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.datadoghq.com/api/v2/downtime
method: POST
response:
body: |
{"data":{"type":"downtime","id":"ae02f456-2bde-11ee-83e1-da7ad0900002","attributes":{"canceled":null,"mute_first_recovery_notification":false,"monitor_identifier":{"monitor_tags":["cat:hat","mat:sat"]},"message":null,"display_timezone":"UTC","created":"2023-07-26T18:03:09.722405+00:00","notify_end_types":[],"modified":"2023-07-26T18:03:09.722405+00:00","scope":"env:(staging OR tf-TestAccDowntimeScheduleBasicOneTime-local-1690394586)","schedule":{"start":"2050-01-02T03:04:05+00:00","end":null},"notify_end_states":["alert","warn","no data"],"status":"scheduled"},"relationships":{"created_by":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}},"monitor":{"data":null}}},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"handle":"[email protected]","created_at":"2019-10-02T08:15:39.795051+00:00","modified_at":"2020-06-15T12:33:12.884459+00:00","email":"[email protected]","icon":"https://secure.gravatar.com/avatar/28a16dfe36e73b60c1d55872cb0f1172?s=48&d=retro","title":null,"verified":true,"service_account":false,"disabled":false,"allowed_login_methods":[],"status":"Active"}}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/downtime/ae02f456-2bde-11ee-83e1-da7ad0900002
method: GET
response:
body: |
{"data":{"type":"downtime","id":"ae02f456-2bde-11ee-83e1-da7ad0900002","attributes":{"scope":"env:(staging OR tf-TestAccDowntimeScheduleBasicOneTime-local-1690394586)","created":"2023-07-26T18:03:09.722405+00:00","status":"scheduled","canceled":null,"modified":"2023-07-26T18:03:09.722405+00:00","notify_end_types":[],"notify_end_states":["warn","no data","alert"],"monitor_identifier":{"monitor_tags":["cat:hat","mat:sat"]},"display_timezone":"UTC","schedule":{"end":null,"start":"2050-01-02T03:04:05+00:00"},"mute_first_recovery_notification":false,"message":null}}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/downtime/ae02f456-2bde-11ee-83e1-da7ad0900002
method: GET
response:
body: |
{"data":{"type":"downtime","attributes":{"canceled":null,"scope":"env:(staging OR tf-TestAccDowntimeScheduleBasicOneTime-local-1690394586)","status":"scheduled","schedule":{"start":"2050-01-02T03:04:05+00:00","end":null},"modified":"2023-07-26T18:03:09.722405+00:00","mute_first_recovery_notification":false,"notify_end_types":[],"notify_end_states":["no data","alert","warn"],"created":"2023-07-26T18:03:09.722405+00:00","display_timezone":"UTC","message":null,"monitor_identifier":{"monitor_tags":["cat:hat","mat:sat"]}},"id":"ae02f456-2bde-11ee-83e1-da7ad0900002"}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: ""
- request:
body: |
{"data":{"attributes":{"display_timezone":"","message":"updated","monitor_identifier":{"monitor_tags":["vat:mat"]},"mute_first_recovery_notification":true,"notify_end_states":["alert"],"notify_end_types":["canceled"],"schedule":{"end":"2060-01-02T03:04:05Z","start":null},"scope":"env:(changed OR tf-TestAccDowntimeScheduleBasicOneTime-local-1690394586)"},"id":"","type":"downtime"}}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
url: https://api.datadoghq.com/api/v2/downtime/ae02f456-2bde-11ee-83e1-da7ad0900002
method: PATCH
response:
body: |
{"data":{"type":"downtime","attributes":{"schedule":{"start":"2023-07-26T18:03:11.486858+00:00","end":"2060-01-02T03:04:05+00:00"},"scope":"env:(changed OR tf-TestAccDowntimeScheduleBasicOneTime-local-1690394586)","canceled":null,"modified":"2023-07-26T18:03:11.529744+00:00","status":"active","notify_end_types":["canceled"],"monitor_identifier":{"monitor_tags":["vat:mat"]},"message":"updated","display_timezone":"UTC","notify_end_states":["alert"],"mute_first_recovery_notification":true,"created":"2023-07-26T18:03:09.722405+00:00"},"relationships":{"monitor":{"data":null},"created_by":{"data":{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0"}}},"id":"ae02f456-2bde-11ee-83e1-da7ad0900002"},"included":[{"type":"users","id":"3ad549bf-eba0-11e9-a77a-0705486660d0","attributes":{"name":null,"handle":"[email protected]","created_at":"2019-10-02T08:15:39.795051+00:00","modified_at":"2020-06-15T12:33:12.884459+00:00","email":"[email protected]","icon":"https://secure.gravatar.com/avatar/28a16dfe36e73b60c1d55872cb0f1172?s=48&d=retro","title":null,"verified":true,"service_account":false,"disabled":false,"allowed_login_methods":[],"status":"Active"}}]}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- application/json
url: https://api.datadoghq.com/api/v2/downtime/ae02f456-2bde-11ee-83e1-da7ad0900002
method: GET
response:
body: |
{"data":{"type":"downtime","attributes":{"message":"updated","modified":"2023-07-26T18:03:11.529744+00:00","monitor_identifier":{"monitor_tags":["vat:mat"]},"mute_first_recovery_notification":true,"schedule":{"end":"2060-01-02T03:04:05+00:00","start":"2023-07-26T18:03:11.486858+00:00"},"notify_end_states":["alert"],"created":"2023-07-26T18:03:09.722405+00:00","status":"active","display_timezone":"UTC","canceled":null,"notify_end_types":["canceled"],"scope":"env:(changed OR tf-TestAccDowntimeScheduleBasicOneTime-local-1690394586)"},"id":"ae02f456-2bde-11ee-83e1-da7ad0900002"}}
headers:
Content-Type:
- application/json
status: 200 OK
code: 200
duration: ""
- request:
body: ""
form: {}
headers:
Accept:
- '*/*'
url: https://api.datadoghq.com/api/v2/downtime/ae02f456-2bde-11ee-83e1-da7ad0900002
method: DELETE
response:
body: ""
headers:
Content-Type:
- text/html; charset=utf-8
status: 204 No Content
code: 204
duration: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-07-26T09:56:03.253368-07:00
Loading

0 comments on commit 334271c

Please sign in to comment.