Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[datadog_dashboard_list] Migrate to tf framework #2038

Merged
merged 22 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bbfd32b
Create dashboard_list data source for framework
HantingZhang2 Jul 28, 2023
0253f42
Merge branch 'master' into hanting.zhang-add-datadog_dashboard_list-d…
HantingZhang2 Jul 28, 2023
1042ec1
remove old datasource, migrate test, fix datasource
HantingZhang2 Jul 28, 2023
676551e
Remove datasource from old provider
HantingZhang2 Jul 31, 2023
304a88a
Use testAccCheckDatadogDashListDestroyWithFW
HantingZhang2 Jul 31, 2023
123efcd
Adds id in Datasource
HantingZhang2 Jul 31, 2023
9baeb26
Adding Create for Dashboard list resource
HantingZhang2 Jul 31, 2023
49fb44b
Finish resource methods
HantingZhang2 Aug 1, 2023
0e2c697
Update desc
HantingZhang2 Aug 1, 2023
60b06a2
Remove potential segfault
HantingZhang2 Aug 1, 2023
fc6bcc5
remove original resource
HantingZhang2 Aug 1, 2023
edbaa38
remove from old provider
HantingZhang2 Aug 1, 2023
a0b357b
Update dashboard list json test
HantingZhang2 Aug 1, 2023
ef969f6
simplify test
HantingZhang2 Aug 1, 2023
3ed8b07
update state and cassettes
HantingZhang2 Aug 1, 2023
0d2dd05
Update cassettes
HantingZhang2 Aug 2, 2023
334271c
Merge branch 'master' into hanting.zhang-add-datadog_dashboard_list-d…
HantingZhang2 Aug 2, 2023
983973a
update cassettes
HantingZhang2 Aug 2, 2023
d3f0764
update update_state
HantingZhang2 Aug 2, 2023
9093a5b
Merge branch 'master' into hanting.zhang-add-datadog_dashboard_list-d…
HantingZhang2 Aug 4, 2023
a22c47b
remove manually listed dashboard types
HantingZhang2 Aug 4, 2023
57aca63
remove space
HantingZhang2 Aug 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions datadog/data_source_datadog_dashboard_list.go

This file was deleted.

95 changes: 95 additions & 0 deletions datadog/fwprovider/data_source_datadog_dashboard_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package fwprovider

import (
"context"
"strconv"

"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"
)

var (
_ datasource.DataSource = &datadogDashboardListDatasource{}
)

func NewDatadogDashboardListDataSource() datasource.DataSource {
return &datadogDashboardListDatasource{}
}

type datadogDashboardListDatasourceModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
}

type datadogDashboardListDatasource struct {
Api *datadogV1.DashboardListsApi
Auth context.Context
}

func (d *datadogDashboardListDatasource) Configure(_ context.Context, request datasource.ConfigureRequest, response *datasource.ConfigureResponse) {
providerData, _ := request.ProviderData.(*FrameworkProvider)
d.Api = providerData.DatadogApiInstances.GetDashboardListsApiV1()
d.Auth = providerData.Auth
}

func (d *datadogDashboardListDatasource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "dashboard_list"
}

func (d *datadogDashboardListDatasource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Use this data source to retrieve information about an existing dashboard list, for use in other resources. In particular, it can be used in a dashboard to register it in the list.",
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
Description: "A dashboard list name to limit the search.",
Required: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
},
},
"id": utils.ResourceIDAttribute(),
},
}
}

func (d *datadogDashboardListDatasource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var state datadogDashboardListDatasourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}

listResponse, httpresp, err := d.Api.ListDashboardLists(d.Auth)
if err != nil {
resp.Diagnostics.Append(utils.FrameworkErrorDiag(utils.TranslateClientError(err, httpresp, ""), "error querying dashboard lists"))
return
}
if err := utils.CheckForUnparsed(listResponse); err != nil {
resp.Diagnostics.Append(utils.FrameworkErrorDiag(err, ""))
}

searchedName := state.Name.ValueString()
var foundList *datadogV1.DashboardList

for _, dashList := range listResponse.GetDashboardLists() {
if dashList.GetName() == searchedName {
foundList = &dashList
break
}
}

if foundList == nil {
errString := "Couldn't find a dashboard list named" + searchedName
resp.Diagnostics.AddError(errString, "")
return
}

id := foundList.GetId()
state.ID = types.StringValue(strconv.Itoa(int(id)))
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
2 changes: 2 additions & 0 deletions datadog/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (

var Resources = []func() resource.Resource{
NewAPIKeyResource,
NewDashboardListResource,
NewDowntimeScheduleResource,
NewIntegrationCloudflareAccountResource,
NewIntegrationConfluentAccountResource,
Expand All @@ -52,6 +53,7 @@ var Resources = []func() resource.Resource{

var Datasources = []func() datasource.DataSource{
NewAPIKeyDataSource,
NewDatadogDashboardListDataSource,
NewDatadogIntegrationAWSNamespaceRulesDatasource,
NewDatadogServiceAccountDatasource,
NewDatadogTeamDataSource,
Expand Down
Loading