Skip to content

Commit 15bd667

Browse files
authored
[datadog_cloud_configuration_rule] reverting the tags field type change and default tags support (#3010)
* Revert "[datadog_cloud_configuration_rule] Add default tag support (#2969)" This reverts commit ca50052. * Revert "[datadog_cloud_configuration_rule] Changed tags field type to Set (#2997)" This reverts commit e76989f.
1 parent 19ba61c commit 15bd667

15 files changed

+155
-1076
lines changed

datadog/fwprovider/framework_provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
223223
Validators: []validator.List{
224224
listvalidator.SizeAtMost(1),
225225
},
226-
Description: "[Experimental - Cloud Configuration Rules, Logs Pipelines, Monitors and Security Monitoring Rules only] Configuration block containing settings to apply default resource tags across all resources.",
226+
Description: "[Experimental - Logs Pipelines, Monitors and Security Monitoring Rules only] Configuration block containing settings to apply default resource tags across all resources.",
227227
NestedObject: schema.NestedBlockObject{
228228
Attributes: map[string]schema.Attribute{
229229
"tags": schema.MapAttribute{
230230
ElementType: types.StringType,
231231
Optional: true,
232-
Description: "[Experimental - Cloud Configuration Rules, Logs Pipelines, Monitors and Security Monitoring Rules only] Resource tags to be applied by default across all resources.",
232+
Description: "[Experimental - Logs Pipelines, Monitors and Security Monitoring Rules only] Resource tags to be applied by default across all resources.",
233233
},
234234
},
235235
},

datadog/internal/utils/utils.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,6 @@ func GetStringSlice(d Resource, key string) []string {
349349
return []string{}
350350
}
351351

352-
// GetStringSliceFromSet returns a string slice for a given schema.Set
353-
func GetStringSliceFromSet(set *schema.Set) []string {
354-
values := set.List()
355-
stringValues := make([]string, len(values))
356-
for i, value := range values {
357-
stringValues[i] = value.(string)
358-
}
359-
return stringValues
360-
}
361-
362352
// GetMultiEnvVar returns first matching env var
363353
func GetMultiEnvVar(envVars ...string) (string, error) {
364354
for _, value := range envVars {

datadog/provider.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ func Provider() *schema.Provider {
159159
Type: schema.TypeList,
160160
Optional: true,
161161
MaxItems: 1,
162-
Description: "[Experimental - Cloud Configuration Rules, Logs Pipelines, Monitors and Security Monitoring Rules only] Configuration block containing settings to apply default resource tags across all resources.",
162+
Description: "[Experimental - Logs Pipelines, Monitors and Security Monitoring Rules only] Configuration block containing settings to apply default resource tags across all resources.",
163163
Elem: &schema.Resource{
164164
Schema: map[string]*schema.Schema{
165165
"tags": {
166166
Type: schema.TypeMap,
167167
Optional: true,
168168
Elem: &schema.Schema{Type: schema.TypeString},
169-
Description: "[Experimental - Cloud Configuration Rules, Logs Pipelines, Monitors and Security Monitoring Rules only] Resource tags to be applied by default across all resources.",
169+
Description: "[Experimental - Logs Pipelines, Monitors and Security Monitoring Rules only] Resource tags to be applied by default across all resources.",
170170
},
171171
},
172172
},
@@ -451,7 +451,6 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
451451
}
452452

453453
// custom diff function that changes plan to take default tags into account
454-
// This is used for when the `tags` attribute is a set
455454
func tagDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{}) error {
456455
providerConf := meta.(*ProviderConfiguration)
457456
if len(providerConf.DefaultTags) == 0 {

datadog/resource_datadog_cloud_configuration_rule.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1110
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1211

1312
"github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils"
@@ -42,7 +41,6 @@ func resourceDatadogCloudConfigurationRule() *schema.Resource {
4241
SchemaFunc: func() map[string]*schema.Schema {
4342
return cloudConfigurationRuleSchema()
4443
},
45-
CustomizeDiff: customdiff.All(tagDiff),
4644
}
4745
}
4846

@@ -100,10 +98,9 @@ func cloudConfigurationRuleSchema() map[string]*schema.Schema {
10098
Elem: &schema.Schema{Type: schema.TypeString},
10199
},
102100
tagsField: {
103-
Type: schema.TypeSet,
101+
Type: schema.TypeList,
104102
Optional: true,
105-
Computed: true,
106-
Description: "Tags of the rule, propagated to findings and signals. Defaults to empty list. **Note**: if default tags are present at the provider level, they will be added to this resource.",
103+
Description: "Tags of the rule, propagated to findings and signals. Defaults to empty list.",
107104
Elem: &schema.Schema{Type: schema.TypeString},
108105
},
109106
filterField: {
@@ -161,7 +158,7 @@ func buildRuleCreatePayload(d *schema.ResourceData) *datadogV2.SecurityMonitorin
161158
payload.SetOptions(buildRuleCreationOptions(d))
162159
payload.SetComplianceSignalOptions(*buildComplianceSignalOptions(d))
163160
payload.SetCases(*buildRuleCreationCases(d))
164-
payload.SetTags(utils.GetStringSliceFromSet(d.Get(tagsField).(*schema.Set)))
161+
payload.SetTags(utils.GetStringSlice(d, tagsField))
165162
payload.SetType(datadogV2.CLOUDCONFIGURATIONRULETYPE_CLOUD_CONFIGURATION)
166163
payload.SetFilters(buildFiltersFromResourceData(d))
167164

@@ -222,7 +219,7 @@ func buildRuleUpdatePayload(d *schema.ResourceData) *datadogV2.SecurityMonitorin
222219
payload.SetOptions(buildRuleUpdateOptions(d))
223220
payload.SetComplianceSignalOptions(*buildComplianceSignalOptions(d))
224221
payload.SetCases(*buildRuleUpdateCases(d))
225-
payload.SetTags(utils.GetStringSliceFromSet(d.Get(tagsField).(*schema.Set)))
222+
payload.SetTags(utils.GetStringSlice(d, tagsField))
226223
payload.SetFilters(buildFiltersFromResourceData(d))
227224
return &payload
228225
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025-05-13T10:03:28.99193+02:00
1+
2024-10-23T09:39:41.380247+02:00

0 commit comments

Comments
 (0)