From cc1920f28fc1e0aecd3e9a9c580daa16df090b2c Mon Sep 17 00:00:00 2001 From: Katie McKew <5915468+ktmq@users.noreply.github.com> Date: Fri, 3 Jan 2025 12:42:03 -0500 Subject: [PATCH] [datadog_integration_aws_account] Fix panic when resources_config is omitted (#2749) --- .../resource_datadog_integration_aws_account.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/datadog/fwprovider/resource_datadog_integration_aws_account.go b/datadog/fwprovider/resource_datadog_integration_aws_account.go index 1d1328168..590708c3a 100644 --- a/datadog/fwprovider/resource_datadog_integration_aws_account.go +++ b/datadog/fwprovider/resource_datadog_integration_aws_account.go @@ -37,6 +37,7 @@ var ( authConfigRolePath = authConfigPath.AtName("aws_auth_config_role") xrayServicesConfigPath = path.MatchRoot("traces_config").AtName("xray_services") lambdaForwarderPath = path.MatchRoot("logs_config").AtName("lambda_forwarder") + resourcesConfigPath = path.MatchRoot("resources_config") ) type integrationAwsAccountResource struct { @@ -176,6 +177,9 @@ func (r *integrationAwsAccountResource) ConfigValidators(ctx context.Context) [] xrayServicesConfigPath.AtName("include_all"), xrayServicesConfigPath.AtName("include_only"), ), + resourcevalidator.ExactlyOneOf( + resourcesConfigPath, + ), } } @@ -859,11 +863,13 @@ func buildRequestMetricsConfig(ctx context.Context, state *integrationAwsAccount func buildRequestResourcesConfig(state *integrationAwsAccountModel) datadogV2.AWSResourcesConfig { var resourcesConfig datadogV2.AWSResourcesConfig - if !state.ResourcesConfig.CloudSecurityPostureManagementCollection.IsNull() { - resourcesConfig.SetCloudSecurityPostureManagementCollection(state.ResourcesConfig.CloudSecurityPostureManagementCollection.ValueBool()) - } - if !state.ResourcesConfig.ExtendedCollection.IsNull() { - resourcesConfig.SetExtendedCollection(state.ResourcesConfig.ExtendedCollection.ValueBool()) + if state.ResourcesConfig != nil { + if !state.ResourcesConfig.CloudSecurityPostureManagementCollection.IsNull() { + resourcesConfig.SetCloudSecurityPostureManagementCollection(state.ResourcesConfig.CloudSecurityPostureManagementCollection.ValueBool()) + } + if !state.ResourcesConfig.ExtendedCollection.IsNull() { + resourcesConfig.SetExtendedCollection(state.ResourcesConfig.ExtendedCollection.ValueBool()) + } } return resourcesConfig