@@ -15,6 +15,7 @@ import (
15
15
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
16
16
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
17
17
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
18
19
"github.com/hashicorp/terraform-provider-aws/internal/conns"
19
20
"github.com/hashicorp/terraform-provider-aws/internal/create"
20
21
"github.com/hashicorp/terraform-provider-aws/internal/enum"
@@ -58,6 +59,43 @@ func ResourceLink() *schema.Resource {
58
59
Required : true ,
59
60
ForceNew : true ,
60
61
},
62
+ "link_configuration" : {
63
+ Type : schema .TypeList ,
64
+ Optional : true ,
65
+ MaxItems : 1 ,
66
+ Elem : & schema.Resource {
67
+ Schema : map [string ]* schema.Schema {
68
+ "log_group_configuration" : {
69
+ Type : schema .TypeList ,
70
+ Optional : true ,
71
+ MaxItems : 1 ,
72
+ Elem : & schema.Resource {
73
+ Schema : map [string ]* schema.Schema {
74
+ names .AttrFilter : {
75
+ Type : schema .TypeString ,
76
+ Required : true ,
77
+ ValidateFunc : validation .StringLenBetween (1 , 2000 ),
78
+ },
79
+ },
80
+ },
81
+ },
82
+ "metric_configuration" : {
83
+ Type : schema .TypeList ,
84
+ Optional : true ,
85
+ MaxItems : 1 ,
86
+ Elem : & schema.Resource {
87
+ Schema : map [string ]* schema.Schema {
88
+ names .AttrFilter : {
89
+ Type : schema .TypeString ,
90
+ Required : true ,
91
+ ValidateFunc : validation .StringLenBetween (1 , 2000 ),
92
+ },
93
+ },
94
+ },
95
+ },
96
+ },
97
+ },
98
+ },
61
99
"link_id" : {
62
100
Type : schema .TypeString ,
63
101
Computed : true ,
@@ -98,10 +136,11 @@ func resourceLinkCreate(ctx context.Context, d *schema.ResourceData, meta interf
98
136
conn := meta .(* conns.AWSClient ).ObservabilityAccessManagerClient (ctx )
99
137
100
138
in := & oam.CreateLinkInput {
101
- LabelTemplate : aws .String (d .Get ("label_template" ).(string )),
102
- ResourceTypes : flex.ExpandStringyValueSet [types.ResourceType ](d .Get ("resource_types" ).(* schema.Set )),
103
- SinkIdentifier : aws .String (d .Get ("sink_identifier" ).(string )),
104
- Tags : getTagsIn (ctx ),
139
+ LabelTemplate : aws .String (d .Get ("label_template" ).(string )),
140
+ LinkConfiguration : expandLinkConfiguration (d .Get ("link_configuration" ).([]interface {})),
141
+ ResourceTypes : flex.ExpandStringyValueSet [types.ResourceType ](d .Get ("resource_types" ).(* schema.Set )),
142
+ SinkIdentifier : aws .String (d .Get ("sink_identifier" ).(string )),
143
+ Tags : getTagsIn (ctx ),
105
144
}
106
145
107
146
out , err := conn .CreateLink (ctx , in )
@@ -137,6 +176,7 @@ func resourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interfac
137
176
d .Set (names .AttrARN , out .Arn )
138
177
d .Set ("label" , out .Label )
139
178
d .Set ("label_template" , out .LabelTemplate )
179
+ d .Set ("link_configuration" , flattenLinkConfiguration (out .LinkConfiguration ))
140
180
d .Set ("link_id" , out .Id )
141
181
d .Set ("resource_types" , flex .FlattenStringValueList (out .ResourceTypes ))
142
182
d .Set ("sink_arn" , out .SinkArn )
@@ -155,8 +195,13 @@ func resourceLinkUpdate(ctx context.Context, d *schema.ResourceData, meta interf
155
195
Identifier : aws .String (d .Id ()),
156
196
}
157
197
158
- if d .HasChanges ("resource_types" ) {
198
+ if d .HasChanges ("resource_types" , "link_configuration" ) {
159
199
in .ResourceTypes = flex.ExpandStringyValueSet [types.ResourceType ](d .Get ("resource_types" ).(* schema.Set ))
200
+
201
+ if d .HasChanges ("link_configuration" ) {
202
+ in .LinkConfiguration = expandLinkConfiguration (d .Get ("link_configuration" ).([]interface {}))
203
+ }
204
+
160
205
update = true
161
206
}
162
207
@@ -216,3 +261,93 @@ func findLinkByID(ctx context.Context, conn *oam.Client, id string) (*oam.GetLin
216
261
217
262
return out , nil
218
263
}
264
+
265
+ func expandLinkConfiguration (l []interface {}) * types.LinkConfiguration {
266
+ if len (l ) == 0 || l [0 ] == nil {
267
+ return nil
268
+ }
269
+
270
+ config := & types.LinkConfiguration {}
271
+
272
+ m := l [0 ].(map [string ]interface {})
273
+ if v , ok := m ["log_group_configuration" ]; ok {
274
+ config .LogGroupConfiguration = expandLogGroupConfiguration (v .([]interface {}))
275
+ }
276
+ if v , ok := m ["metric_configuration" ]; ok {
277
+ config .MetricConfiguration = expandMetricConfiguration (v .([]interface {}))
278
+ }
279
+
280
+ return config
281
+ }
282
+
283
+ func expandLogGroupConfiguration (l []interface {}) * types.LogGroupConfiguration {
284
+ if len (l ) == 0 || l [0 ] == nil {
285
+ return nil
286
+ }
287
+
288
+ config := & types.LogGroupConfiguration {}
289
+
290
+ m := l [0 ].(map [string ]interface {})
291
+ if v , ok := m [names .AttrFilter ]; ok && v != "" {
292
+ config .Filter = aws .String (v .(string ))
293
+ }
294
+
295
+ return config
296
+ }
297
+
298
+ func expandMetricConfiguration (l []interface {}) * types.MetricConfiguration {
299
+ if len (l ) == 0 || l [0 ] == nil {
300
+ return nil
301
+ }
302
+
303
+ config := & types.MetricConfiguration {}
304
+
305
+ m := l [0 ].(map [string ]interface {})
306
+ if v , ok := m [names .AttrFilter ]; ok && v != "" {
307
+ config .Filter = aws .String (v .(string ))
308
+ }
309
+
310
+ return config
311
+ }
312
+
313
+ func flattenLinkConfiguration (a * types.LinkConfiguration ) []interface {} {
314
+ if a == nil {
315
+ return []interface {}{}
316
+ }
317
+ m := map [string ]interface {}{}
318
+
319
+ if a .LogGroupConfiguration != nil {
320
+ m ["log_group_configuration" ] = flattenLogGroupConfiguration (a .LogGroupConfiguration )
321
+ }
322
+ if a .MetricConfiguration != nil {
323
+ m ["metric_configuration" ] = flattenMetricConfiguration (a .MetricConfiguration )
324
+ }
325
+
326
+ return []interface {}{m }
327
+ }
328
+
329
+ func flattenLogGroupConfiguration (a * types.LogGroupConfiguration ) []interface {} {
330
+ if a == nil {
331
+ return []interface {}{}
332
+ }
333
+ m := map [string ]interface {}{}
334
+
335
+ if a .Filter != nil {
336
+ m [names .AttrFilter ] = aws .ToString (a .Filter )
337
+ }
338
+
339
+ return []interface {}{m }
340
+ }
341
+
342
+ func flattenMetricConfiguration (a * types.MetricConfiguration ) []interface {} {
343
+ if a == nil {
344
+ return []interface {}{}
345
+ }
346
+ m := map [string ]interface {}{}
347
+
348
+ if a .Filter != nil {
349
+ m [names .AttrFilter ] = aws .ToString (a .Filter )
350
+ }
351
+
352
+ return []interface {}{m }
353
+ }
0 commit comments