Skip to content

Commit 542711d

Browse files
committed
feat: Add resource filtering support to aws_oam_link
1 parent a486a44 commit 542711d

13 files changed

+752
-25
lines changed

.changelog/38277.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/aws_oam_link: Add `link_configuration` argument
3+
```
4+
5+
```release-note:enhancement
6+
data-source/aws_oam_link: Add `link_configuration` attribute
7+
```

internal/service/oam/link.go

+140-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1616
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1717
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1819
"github.com/hashicorp/terraform-provider-aws/internal/conns"
1920
"github.com/hashicorp/terraform-provider-aws/internal/create"
2021
"github.com/hashicorp/terraform-provider-aws/internal/enum"
@@ -58,6 +59,43 @@ func ResourceLink() *schema.Resource {
5859
Required: true,
5960
ForceNew: true,
6061
},
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+
},
6199
"link_id": {
62100
Type: schema.TypeString,
63101
Computed: true,
@@ -98,10 +136,11 @@ func resourceLinkCreate(ctx context.Context, d *schema.ResourceData, meta interf
98136
conn := meta.(*conns.AWSClient).ObservabilityAccessManagerClient(ctx)
99137

100138
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),
105144
}
106145

107146
out, err := conn.CreateLink(ctx, in)
@@ -137,6 +176,7 @@ func resourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interfac
137176
d.Set(names.AttrARN, out.Arn)
138177
d.Set("label", out.Label)
139178
d.Set("label_template", out.LabelTemplate)
179+
d.Set("link_configuration", flattenLinkConfiguration(out.LinkConfiguration))
140180
d.Set("link_id", out.Id)
141181
d.Set("resource_types", flex.FlattenStringValueList(out.ResourceTypes))
142182
d.Set("sink_arn", out.SinkArn)
@@ -155,8 +195,13 @@ func resourceLinkUpdate(ctx context.Context, d *schema.ResourceData, meta interf
155195
Identifier: aws.String(d.Id()),
156196
}
157197

158-
if d.HasChanges("resource_types") {
198+
if d.HasChanges("resource_types", "link_configuration") {
159199
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+
160205
update = true
161206
}
162207

@@ -216,3 +261,93 @@ func findLinkByID(ctx context.Context, conn *oam.Client, id string) (*oam.GetLin
216261

217262
return out, nil
218263
}
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+
}

internal/service/oam/link_data_source.go

+40-7
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,54 @@ func DataSourceLink() *schema.Resource {
2626
Type: schema.TypeString,
2727
Computed: true,
2828
},
29-
"link_id": {
29+
"label": {
3030
Type: schema.TypeString,
3131
Computed: true,
3232
},
33-
"link_identifier": {
33+
"label_template": {
3434
Type: schema.TypeString,
35-
Required: true,
35+
Computed: true,
3636
},
37-
"label": {
38-
Type: schema.TypeString,
37+
"link_configuration": {
38+
Type: schema.TypeList,
3939
Computed: true,
40+
Elem: &schema.Resource{
41+
Schema: map[string]*schema.Schema{
42+
"log_group_configuration": {
43+
Type: schema.TypeList,
44+
Computed: true,
45+
Elem: &schema.Resource{
46+
Schema: map[string]*schema.Schema{
47+
names.AttrFilter: {
48+
Type: schema.TypeString,
49+
Computed: true,
50+
},
51+
},
52+
},
53+
},
54+
"metric_configuration": {
55+
Type: schema.TypeList,
56+
Computed: true,
57+
Elem: &schema.Resource{
58+
Schema: map[string]*schema.Schema{
59+
names.AttrFilter: {
60+
Type: schema.TypeString,
61+
Computed: true,
62+
},
63+
},
64+
},
65+
},
66+
},
67+
},
4068
},
41-
"label_template": {
69+
"link_id": {
4270
Type: schema.TypeString,
4371
Computed: true,
4472
},
73+
"link_identifier": {
74+
Type: schema.TypeString,
75+
Required: true,
76+
},
4577
"resource_types": {
4678
Type: schema.TypeSet,
4779
Computed: true,
@@ -76,9 +108,10 @@ func dataSourceLinkRead(ctx context.Context, d *schema.ResourceData, meta interf
76108
d.SetId(aws.ToString(out.Arn))
77109

78110
d.Set(names.AttrARN, out.Arn)
79-
d.Set("link_id", out.Id)
80111
d.Set("label", out.Label)
81112
d.Set("label_template", out.LabelTemplate)
113+
d.Set("link_configuration", flattenLinkConfiguration(out.LinkConfiguration))
114+
d.Set("link_id", out.Id)
82115
d.Set("resource_types", flex.FlattenStringValueList(out.ResourceTypes))
83116
d.Set("sink_arn", out.SinkArn)
84117

0 commit comments

Comments
 (0)