-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[datadog_integration_aws_available_namespaces] Create AWS Integration…
…s V2 datasources `datadog_integration_aws_available_logs_services/namespaces` (#2709) * Create v2 data_source_datadog_integration_aws_logs_services * Rename resource * Fix datasource typename and set state * Add datadog_integration_aws_available_namespaces datasource and test * make docs * Reference data sources from account resource * typo * Update docs --------- Co-authored-by: Anika Maskara <anika.maskara@datadoghq.com>
- Loading branch information
1 parent
993b0b2
commit 33b80ca
Showing
16 changed files
with
754 additions
and
12 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
datadog/fwprovider/data_source_datadog_integration_aws_available_logs_services.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package fwprovider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
|
||
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils" | ||
) | ||
|
||
var ( | ||
_ datasource.DataSource = &awsLogsServicesDataSource{} | ||
) | ||
|
||
func NewAwsLogsServicesDataSource() datasource.DataSource { | ||
return &awsLogsServicesDataSource{} | ||
} | ||
|
||
type awsLogsServicesDataSourceModel struct { | ||
ID types.String `tfsdk:"id"` | ||
LogsServices []string `tfsdk:"aws_logs_services"` | ||
} | ||
|
||
type awsLogsServicesDataSource struct { | ||
Api *datadogV2.AWSLogsIntegrationApi | ||
Auth context.Context | ||
} | ||
|
||
func (r *awsLogsServicesDataSource) Configure(_ context.Context, request datasource.ConfigureRequest, response *datasource.ConfigureResponse) { | ||
providerData, _ := request.ProviderData.(*FrameworkProvider) | ||
r.Api = providerData.DatadogApiInstances.GetAWSLogsIntegrationApiV2() | ||
r.Auth = providerData.Auth | ||
} | ||
|
||
func (d *awsLogsServicesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = "integration_aws_available_logs_services" | ||
} | ||
|
||
func (d *awsLogsServicesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Description: "Use this data source to retrieve all AWS log ready services. This is the list of allowed values for `logs_config.lambda_forwarder.sources` in [`datadog_integration_aws_account` resource](https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/integration_aws_account).", | ||
Attributes: map[string]schema.Attribute{ | ||
// Datasource ID | ||
"id": utils.ResourceIDAttribute(), | ||
// Datasource Parameters | ||
"aws_logs_services": schema.ListAttribute{ | ||
Description: "List of AWS log ready services.", | ||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *awsLogsServicesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var state awsLogsServicesDataSourceModel | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
awsLogsServicesResp, httpResp, err := d.Api.ListAWSLogsServices(d.Auth) | ||
if err != nil { | ||
resp.Diagnostics.Append(utils.FrameworkErrorDiag(utils.TranslateClientError(err, httpResp, "error querying AWS Logs Services"), "")) | ||
return | ||
} | ||
|
||
state.ID = types.StringValue("integration-aws-available-logs-services") | ||
|
||
d.updateState(&state, &awsLogsServicesResp) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) | ||
|
||
} | ||
|
||
func (d *awsLogsServicesDataSource) updateState(state *awsLogsServicesDataSourceModel, resp *datadogV2.AWSLogsServicesResponse) { | ||
logsServicesDd := resp.Data.GetAttributes().LogsServices | ||
state.LogsServices = append(state.LogsServices, logsServicesDd...) | ||
} |
80 changes: 80 additions & 0 deletions
80
datadog/fwprovider/data_source_datadog_integration_aws_available_namespaces.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package fwprovider | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
|
||
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils" | ||
) | ||
|
||
var ( | ||
_ datasource.DataSource = &awsAvailableNamespacesDataSource{} | ||
) | ||
|
||
func NewAwsAvailableNamespacesDataSource() datasource.DataSource { | ||
return &awsAvailableNamespacesDataSource{} | ||
} | ||
|
||
type awsAvailableNamespacesDataSourceModel struct { | ||
ID types.String `tfsdk:"id"` | ||
AvailableNamespaces []string `tfsdk:"aws_namespaces"` | ||
} | ||
|
||
type awsAvailableNamespacesDataSource struct { | ||
Api *datadogV2.AWSIntegrationApi | ||
Auth context.Context | ||
} | ||
|
||
func (r *awsAvailableNamespacesDataSource) Configure(_ context.Context, request datasource.ConfigureRequest, response *datasource.ConfigureResponse) { | ||
providerData, _ := request.ProviderData.(*FrameworkProvider) | ||
r.Api = providerData.DatadogApiInstances.GetAWSIntegrationApiV2() | ||
r.Auth = providerData.Auth | ||
} | ||
|
||
func (d *awsAvailableNamespacesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = "integration_aws_available_namespaces" | ||
} | ||
|
||
func (d *awsAvailableNamespacesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Description: "Use this data source to retrieve all available AWS namespaces. This is the list of allowed values for `metrics_config.namespace_filters` `include_only` or `exclude_only` in [`datadog_integration_aws_account` resource](https://registry.terraform.io/providers/DataDog/datadog/latest/docs/resources/integration_aws_account).", | ||
Attributes: map[string]schema.Attribute{ | ||
// Datasource ID | ||
"id": utils.ResourceIDAttribute(), | ||
// Datasource Parameters | ||
"aws_namespaces": schema.ListAttribute{ | ||
Description: "List of available AWS namespaces.", | ||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *awsAvailableNamespacesDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var state awsAvailableNamespacesDataSourceModel | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
awsAvailableNamespacesResp, httpResp, err := d.Api.ListAWSNamespaces(d.Auth) | ||
if err != nil { | ||
resp.Diagnostics.Append(utils.FrameworkErrorDiag(utils.TranslateClientError(err, httpResp, "error querying AWS Namespaces"), "")) | ||
return | ||
} | ||
|
||
state.ID = types.StringValue("integration-aws-available-namespaces") | ||
|
||
d.updateState(&state, &awsAvailableNamespacesResp) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) | ||
|
||
} | ||
|
||
func (d *awsAvailableNamespacesDataSource) updateState(state *awsAvailableNamespacesDataSourceModel, resp *datadogV2.AWSNamespacesResponse) { | ||
namespacesDd := resp.Data.GetAttributes().Namespaces | ||
state.AvailableNamespaces = append(state.AvailableNamespaces, namespacesDd...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
datadog/tests/cassettes/TestAccDatadogIntegrationAWSAvailableLogsServicesDatasource.freeze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2024-12-09T10:54:13.353546-05:00 |
Oops, something went wrong.