Skip to content

Commit

Permalink
Revert "[AZINTS-2487] Update Azure integration terraform to support m…
Browse files Browse the repository at this point in the history
…etric fi…" (#2752)

This reverts commit 0509c7c.
  • Loading branch information
jack-edmonds-dd authored Jan 6, 2025
1 parent 0509c7c commit 5bb6c85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 86 deletions.
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

0 comments on commit 5bb6c85

Please sign in to comment.