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

Revert "[AZINTS-2487] Update Azure integration terraform to support metric filitering" #2752

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
85 changes: 11 additions & 74 deletions datadog/fwprovider/resource_datadog_azure_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sync"

"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
frameworkPath "github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand All @@ -30,27 +29,18 @@ type integrationAzureResource struct {
Auth context.Context
}

type ResourceProviderConfigModel struct {
Namespace types.String `tfsdk:"namespace"`
MetricsEnabled types.Bool `tfsdk:"metrics_enabled"`
}

type integrationAzureModel struct {
ID types.String `tfsdk:"id"`
AppServicePlanFilters types.String `tfsdk:"app_service_plan_filters"`
Automute types.Bool `tfsdk:"automute"`
ClientId types.String `tfsdk:"client_id"`
ClientSecret types.String `tfsdk:"client_secret"`
ContainerAppFilters types.String `tfsdk:"container_app_filters"`
ResourceCollectionEnabled types.Bool `tfsdk:"resource_collection_enabled"`
CspmEnabled types.Bool `tfsdk:"cspm_enabled"`
CustomMetricsEnabled types.Bool `tfsdk:"custom_metrics_enabled"`
HostFilters types.String `tfsdk:"host_filters"`
TenantName types.String `tfsdk:"tenant_name"`
MetricsEnabled types.Bool `tfsdk:"metrics_enabled"`
MetricsEnabledDefault types.Bool `tfsdk:"metrics_enabled_default"`
UsageMetricsEnabled types.Bool `tfsdk:"usage_metrics_enabled"`
ResourceProviderConfigs []*ResourceProviderConfigModel `tfsdk:"resource_provider_configs"`
ID types.String `tfsdk:"id"`
AppServicePlanFilters types.String `tfsdk:"app_service_plan_filters"`
Automute types.Bool `tfsdk:"automute"`
ClientId types.String `tfsdk:"client_id"`
ClientSecret types.String `tfsdk:"client_secret"`
ContainerAppFilters types.String `tfsdk:"container_app_filters"`
ResourceCollectionEnabled types.Bool `tfsdk:"resource_collection_enabled"`
CspmEnabled types.Bool `tfsdk:"cspm_enabled"`
CustomMetricsEnabled types.Bool `tfsdk:"custom_metrics_enabled"`
HostFilters types.String `tfsdk:"host_filters"`
TenantName types.String `tfsdk:"tenant_name"`
}

func NewIntegrationAzureResource() resource.Resource {
Expand Down Expand Up @@ -125,35 +115,6 @@ func (r *integrationAzureResource) Schema(_ context.Context, _ resource.SchemaRe
Description: "This comma-separated list of tags (in the form `key:value,key:value`) defines a filter that Datadog uses when collecting metrics from Azure App Service Plans. Only App Service Plans that match one of the defined tags are imported into Datadog. The rest, including the apps and functions running on them, are ignored. This also filters the metrics for any App or Function running on the App Service Plan(s).",
Default: stringdefault.StaticString(""),
},
"metrics_enabled": schema.BoolAttribute{
Computed: true,
Default: booldefault.StaticBool(true),
Optional: true,
Description: "Enable Azure metrics for your organization.",
},
"metrics_enabled_default": schema.BoolAttribute{
Computed: true,
Default: booldefault.StaticBool(true),
Optional: true,
Description: "Enable Azure metrics for your organization for resource providers where no resource provider config is specified.",
},
"usage_metrics_enabled": schema.BoolAttribute{
Computed: true,
Default: booldefault.StaticBool(true),
Optional: true,
Description: "Enable azure.usage metrics for your organization.",
},
"resource_provider_configs": schema.ListAttribute{
Computed: true,
Optional: true,
Description: "Configuration settings applied to resources from the specified Azure resource providers.",
ElementType: types.ObjectType{
AttrTypes: map[string]attr.Type{
"namespace": types.StringType,
"metrics_enabled": types.BoolType,
},
},
},
"id": utils.ResourceIDAttribute(),
},
}
Expand Down Expand Up @@ -296,18 +257,6 @@ func (r *integrationAzureResource) updateState(ctx context.Context, state *integ
state.ResourceCollectionEnabled = types.BoolValue(account.GetResourceCollectionEnabled())
state.CspmEnabled = types.BoolValue(account.GetCspmEnabled())
state.CustomMetricsEnabled = types.BoolValue(account.GetCustomMetricsEnabled())
state.MetricsEnabled = types.BoolValue(account.GetMetricsEnabled())
state.MetricsEnabledDefault = types.BoolValue(account.GetMetricsEnabledDefault())
state.UsageMetricsEnabled = types.BoolValue(account.GetUsageMetricsEnabled())

resourceProviderConfigs := account.GetResourceProviderConfigs()
state.ResourceProviderConfigs = make([]*ResourceProviderConfigModel, len(resourceProviderConfigs))
for i, resourceProviderConfig := range resourceProviderConfigs {
state.ResourceProviderConfigs[i] = &ResourceProviderConfigModel{
Namespace: types.StringValue(resourceProviderConfig.GetNamespace()),
MetricsEnabled: types.BoolValue(resourceProviderConfig.GetMetricsEnabled()),
}
}

hostFilters, exists := account.GetHostFiltersOk()
if exists {
Expand Down Expand Up @@ -367,18 +316,6 @@ func (r *integrationAzureResource) buildIntegrationAzureRequestBody(ctx context.
}
datadogDefinition.SetCspmEnabled(state.CspmEnabled.ValueBool())
datadogDefinition.SetCustomMetricsEnabled(state.CustomMetricsEnabled.ValueBool())
datadogDefinition.SetMetricsEnabled(state.MetricsEnabled.ValueBool())
datadogDefinition.SetMetricsEnabledDefault(state.MetricsEnabledDefault.ValueBool())
datadogDefinition.SetUsageMetricsEnabled(state.UsageMetricsEnabled.ValueBool())

resourceProviderConfigsPayload := make([]datadogV1.ResourceProviderConfig, len(state.ResourceProviderConfigs))
for _, resourceProviderConfig := range state.ResourceProviderConfigs {
resourceProviderConfigsPayload = append(resourceProviderConfigsPayload, datadogV1.ResourceProviderConfig{
Namespace: resourceProviderConfig.Namespace.ValueStringPointer(),
MetricsEnabled: resourceProviderConfig.MetricsEnabled.ValueBoolPointer(),
})
}
datadogDefinition.SetResourceProviderConfigs(resourceProviderConfigsPayload)

if !state.ClientSecret.IsNull() {
datadogDefinition.SetClientSecret(state.ClientSecret.ValueString())
Expand Down
12 changes: 0 additions & 12 deletions docs/resources/integration_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,12 @@ resource "datadog_integration_azure" "sandbox" {
Note: This requires `resource_collection_enabled` to be set to true. Defaults to `false`.
- `custom_metrics_enabled` (Boolean) Enable custom metrics for your organization. Defaults to `false`.
- `host_filters` (String) String of host tag(s) (in the form `key:value,key:value`) defines a filter that Datadog will use when collecting metrics from Azure. Limit the Azure instances that are pulled into Datadog by using tags. Only hosts that match one of the defined tags are imported into Datadog. e.x. `env:production,deploymentgroup:red` Defaults to `""`.
- `metrics_enabled` (Boolean) Enable Azure metrics for your organization. Defaults to `true`.
- `metrics_enabled_default` (Boolean) Enable Azure metrics for your organization for resource providers where no resource provider config is specified. Defaults to `true`.
- `resource_collection_enabled` (Boolean) When enabled, Datadog collects metadata and configuration info from cloud resources (such as compute instances, databases, and load balancers) monitored by this app registration.
- `resource_provider_configs` (List of Object) Configuration settings applied to resources from the specified Azure resource providers. (see [below for nested schema](#nestedatt--resource_provider_configs))
- `usage_metrics_enabled` (Boolean) Enable azure.usage metrics for your organization. Defaults to `true`.

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedatt--resource_provider_configs"></a>
### Nested Schema for `resource_provider_configs`

Optional:

- `metrics_enabled` (Boolean)
- `namespace` (String)

## Import

Import is supported using the following syntax:
Expand Down
Loading