@@ -11,7 +11,8 @@ import (
11
11
"github.com/hashicorp/terraform-plugin-framework/diag"
12
12
"github.com/hashicorp/terraform-plugin-framework/path"
13
13
"github.com/hashicorp/terraform-plugin-framework/resource"
14
- "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
14
+ "github.com/hashicorp/terraform-provider-aws/internal/conns"
15
+ fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
15
16
"github.com/hashicorp/terraform-provider-aws/internal/provider/interceptors"
16
17
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
17
18
"github.com/hashicorp/terraform-provider-aws/internal/types"
@@ -70,7 +71,7 @@ func (r tagsDataSourceInterceptor) read(ctx context.Context, opts interceptorOpt
70
71
71
72
tags := tagsInContext .TagsOut .UnwrapOrDefault ()
72
73
// Remove any provider configured ignore_tags and system tags from those returned from the service API.
73
- stateTags := flex .FlattenFrameworkStringValueMapLegacy (ctx , tags .IgnoreSystem (sp .ServicePackageName ()).IgnoreConfig (c .IgnoreTagsConfig (ctx )).Map ())
74
+ stateTags := fwflex .FlattenFrameworkStringValueMapLegacy (ctx , tags .IgnoreSystem (sp .ServicePackageName ()).IgnoreConfig (c .IgnoreTagsConfig (ctx )).Map ())
74
75
diags .Append (response .State .SetAttribute (ctx , path .Root (names .AttrTags ), tftags .NewMapFromMapValue (stateTags ))... )
75
76
if diags .HasError () {
76
77
return diags
@@ -125,7 +126,7 @@ func (r tagsResourceInterceptor) create(ctx context.Context, opts interceptorOpt
125
126
// Set values for unknowns.
126
127
// Remove any provider configured ignore_tags and system tags from those passed to the service API.
127
128
// Computed tags_all include any provider configured default_tags.
128
- stateTagsAll := flex .FlattenFrameworkStringValueMapLegacy (ctx , tagsInContext .TagsIn .MustUnwrap ().IgnoreSystem (sp .ServicePackageName ()).IgnoreConfig (c .IgnoreTagsConfig (ctx )).Map ())
129
+ stateTagsAll := fwflex .FlattenFrameworkStringValueMapLegacy (ctx , tagsInContext .TagsIn .MustUnwrap ().IgnoreSystem (sp .ServicePackageName ()).IgnoreConfig (c .IgnoreTagsConfig (ctx )).Map ())
129
130
diags .Append (response .State .SetAttribute (ctx , path .Root (names .AttrTagsAll ), tftags .NewMapFromMapValue (stateTagsAll ))... )
130
131
if diags .HasError () {
131
132
return diags
@@ -176,15 +177,15 @@ func (r tagsResourceInterceptor) read(ctx context.Context, opts interceptorOptio
176
177
// Remove any provider configured ignore_tags and system tags from those returned from the service API.
177
178
// The resource's configured tags do not include any provider configured default_tags.
178
179
if v := apiTags .IgnoreSystem (sp .ServicePackageName ()).IgnoreConfig (c .IgnoreTagsConfig (ctx )).ResolveDuplicatesFramework (ctx , c .DefaultTagsConfig (ctx ), c .IgnoreTagsConfig (ctx ), response , & diags ).Map (); len (v ) > 0 {
179
- stateTags = tftags .NewMapFromMapValue (flex .FlattenFrameworkStringValueMapLegacy (ctx , v ))
180
+ stateTags = tftags .NewMapFromMapValue (fwflex .FlattenFrameworkStringValueMapLegacy (ctx , v ))
180
181
}
181
182
diags .Append (response .State .SetAttribute (ctx , path .Root (names .AttrTags ), & stateTags )... )
182
183
if diags .HasError () {
183
184
return diags
184
185
}
185
186
186
187
// Computed tags_all do.
187
- stateTagsAll := flex .FlattenFrameworkStringValueMapLegacy (ctx , apiTags .IgnoreSystem (sp .ServicePackageName ()).IgnoreConfig (c .IgnoreTagsConfig (ctx )).Map ())
188
+ stateTagsAll := fwflex .FlattenFrameworkStringValueMapLegacy (ctx , apiTags .IgnoreSystem (sp .ServicePackageName ()).IgnoreConfig (c .IgnoreTagsConfig (ctx )).Map ())
188
189
diags .Append (response .State .SetAttribute (ctx , path .Root (names .AttrTagsAll ), tftags .NewMapFromMapValue (stateTagsAll ))... )
189
190
if diags .HasError () {
190
191
return diags
@@ -270,3 +271,24 @@ func (r tagsInterceptor) getIdentifier(ctx context.Context, d interface {
270
271
271
272
return identifier
272
273
}
274
+
275
+ // setTagsAll is a plan modifier that calculates the new value for the `tags_all` attribute.
276
+ func setTagsAll (ctx context.Context , meta * conns.AWSClient , request resource.ModifyPlanRequest , response * resource.ModifyPlanResponse ) {
277
+ // If the entire plan is null, the resource is planned for destruction.
278
+ if request .Plan .Raw .IsNull () {
279
+ return
280
+ }
281
+
282
+ var planTags tftags.Map
283
+ response .Diagnostics .Append (request .Plan .GetAttribute (ctx , path .Root (names .AttrTags ), & planTags )... )
284
+ if response .Diagnostics .HasError () {
285
+ return
286
+ }
287
+
288
+ if planTags .IsWhollyKnown () {
289
+ allTags := meta .DefaultTagsConfig (ctx ).MergeTags (tftags .New (ctx , planTags )).IgnoreConfig (meta .IgnoreTagsConfig (ctx ))
290
+ response .Diagnostics .Append (response .Plan .SetAttribute (ctx , path .Root (names .AttrTagsAll ), fwflex .FlattenFrameworkStringValueMapLegacy (ctx , allTags .Map ()))... )
291
+ } else {
292
+ response .Diagnostics .Append (response .Plan .SetAttribute (ctx , path .Root (names .AttrTagsAll ), tftags .Unknown )... )
293
+ }
294
+ }
0 commit comments