Skip to content

Commit 3d8a738

Browse files
author
Marcin Belczewski
committed
feat(aws_cloudwatch_log_delivery_destination): enable XRAY destination
1 parent 6259408 commit 3d8a738

File tree

5 files changed

+172
-6
lines changed

5 files changed

+172
-6
lines changed

.changelog/44995.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_cloudwatch_log_delivery_destination: Add support for `XRAY` delivery destination type
3+
```

internal/service/bedrockagentcore/gateway_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,41 @@ func TestAccBedrockAgentCoreGateway_basic(t *testing.T) {
7272
})
7373
}
7474

75+
func TestAccBedrockAgentCoreGateway_xrayDelivery(t *testing.T) {
76+
ctx := acctest.Context(t)
77+
var gateway bedrockagentcorecontrol.GetGatewayOutput
78+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
79+
resourceName := "aws_bedrockagentcore_gateway.test"
80+
deliveryResourceName := "aws_cloudwatch_log_delivery.test"
81+
82+
resource.ParallelTest(t, resource.TestCase{
83+
PreCheck: func() {
84+
acctest.PreCheck(ctx, t)
85+
acctest.PreCheckPartitionHasService(t, names.BedrockEndpointID)
86+
testAccPreCheckGateways(ctx, t)
87+
},
88+
ErrorCheck: acctest.ErrorCheck(t, names.BedrockAgentCoreServiceID),
89+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
90+
CheckDestroy: testAccCheckGatewayDestroy(ctx),
91+
Steps: []resource.TestStep{
92+
{
93+
Config: testAccGatewayConfig_xrayDelivery(rName),
94+
Check: resource.ComposeAggregateTestCheckFunc(
95+
testAccCheckGatewayExists(ctx, resourceName, &gateway),
96+
resource.TestCheckResourceAttrSet(deliveryResourceName, names.AttrID),
97+
resource.TestCheckResourceAttr(deliveryResourceName, "delivery_source_name", rName+"-source"),
98+
),
99+
ConfigPlanChecks: resource.ConfigPlanChecks{
100+
PreApply: []plancheck.PlanCheck{
101+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
102+
plancheck.ExpectResourceAction(deliveryResourceName, plancheck.ResourceActionCreate),
103+
},
104+
},
105+
},
106+
},
107+
})
108+
}
109+
75110
func TestAccBedrockAgentCoreGateway_disappears(t *testing.T) {
76111
ctx := acctest.Context(t)
77112
var gateway bedrockagentcorecontrol.GetGatewayOutput
@@ -492,6 +527,41 @@ resource "aws_bedrockagentcore_gateway" "test" {
492527
`, rName))
493528
}
494529

530+
func testAccGatewayConfig_xrayDelivery(rName string) string {
531+
return acctest.ConfigCompose(testAccGatewayConfig_iamRole(rName), fmt.Sprintf(`
532+
resource "aws_bedrockagentcore_gateway" "test" {
533+
name = %[1]q
534+
role_arn = aws_iam_role.test.arn
535+
536+
authorizer_type = "CUSTOM_JWT"
537+
authorizer_configuration {
538+
custom_jwt_authorizer {
539+
discovery_url = "https://accounts.google.com/.well-known/openid-configuration"
540+
allowed_audience = ["test1", "test2"]
541+
}
542+
}
543+
544+
protocol_type = "MCP"
545+
}
546+
547+
resource "aws_cloudwatch_log_delivery_source" "test" {
548+
name = "%[1]s-source"
549+
log_type = "TRACES"
550+
resource_arn = aws_bedrockagentcore_gateway.test.gateway_arn
551+
}
552+
553+
resource "aws_cloudwatch_log_delivery_destination" "test" {
554+
name = "%[1]s-destination"
555+
delivery_destination_type = "XRAY"
556+
}
557+
558+
resource "aws_cloudwatch_log_delivery" "test" {
559+
delivery_source_name = aws_cloudwatch_log_delivery_source.test.name
560+
delivery_destination_arn = aws_cloudwatch_log_delivery_destination.test.arn
561+
}
562+
`, rName))
563+
}
564+
495565
func testAccGatewayConfig_protocolConfiguration(rName, instructions string) string {
496566
return acctest.ConfigCompose(testAccGatewayConfig_iamRole(rName), fmt.Sprintf(`
497567
resource "aws_bedrockagentcore_gateway" "test" {

internal/service/logs/delivery_destination.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (r *deliveryDestinationResource) Schema(ctx context.Context, request resour
5050
names.AttrARN: framework.ARNAttributeComputedOnly(),
5151
"delivery_destination_type": schema.StringAttribute{
5252
CustomType: fwtypes.StringEnumType[awstypes.DeliveryDestinationType](),
53+
Optional: true,
5354
Computed: true,
5455
},
5556
names.AttrName: schema.StringAttribute{
@@ -75,15 +76,13 @@ func (r *deliveryDestinationResource) Schema(ctx context.Context, request resour
7576
"delivery_destination_configuration": schema.ListNestedBlock{
7677
CustomType: fwtypes.NewListNestedObjectTypeOf[deliveryDestinationConfigurationModel](ctx),
7778
Validators: []validator.List{
78-
listvalidator.IsRequired(),
79-
listvalidator.SizeAtLeast(1),
8079
listvalidator.SizeAtMost(1),
8180
},
8281
NestedObject: schema.NestedBlockObject{
8382
Attributes: map[string]schema.Attribute{
8483
"destination_resource_arn": schema.StringAttribute{
8584
CustomType: fwtypes.ARNType,
86-
Required: true,
85+
Optional: true,
8786
PlanModifiers: []planmodifier.String{
8887
stringplanmodifier.RequiresReplaceIf(requiresReplaceIfARNServiceChanges, "", ""),
8988
},
@@ -95,6 +94,34 @@ func (r *deliveryDestinationResource) Schema(ctx context.Context, request resour
9594
}
9695
}
9796

97+
func (r *deliveryDestinationResource) ValidateConfig(ctx context.Context, request resource.ValidateConfigRequest, response *resource.ValidateConfigResponse) {
98+
var data deliveryDestinationResourceModel
99+
response.Diagnostics.Append(request.Config.Get(ctx, &data)...)
100+
if response.Diagnostics.HasError() {
101+
return
102+
}
103+
104+
isXray := !data.DeliveryDestinationType.IsNull() && !data.DeliveryDestinationType.IsUnknown() &&
105+
data.DeliveryDestinationType.ValueString() == string(awstypes.DeliveryDestinationTypeXray)
106+
hasConfig := !data.DeliveryDestinationConfiguration.IsNull() && !data.DeliveryDestinationConfiguration.IsUnknown()
107+
108+
if isXray && hasConfig {
109+
response.Diagnostics.AddAttributeError(
110+
path.Root("delivery_destination_configuration"),
111+
"Invalid Configuration",
112+
"delivery_destination_configuration must not be set when delivery_destination_type is XRAY",
113+
)
114+
}
115+
116+
if !isXray && !hasConfig && !data.DeliveryDestinationType.IsUnknown() && !data.DeliveryDestinationConfiguration.IsUnknown() {
117+
response.Diagnostics.AddAttributeError(
118+
path.Root("delivery_destination_configuration"),
119+
"Missing Configuration",
120+
"delivery_destination_configuration is required when delivery_destination_type is not XRAY",
121+
)
122+
}
123+
}
124+
98125
func (r *deliveryDestinationResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) {
99126
var data deliveryDestinationResourceModel
100127
response.Diagnostics.Append(request.Plan.Get(ctx, &data)...)
@@ -152,6 +179,13 @@ func (r *deliveryDestinationResource) Read(ctx context.Context, request resource
152179
return
153180
}
154181

182+
// Handle empty destination_resource_arn for XRAY type destinations
183+
// Clear it before flattening to avoid ARN validation error
184+
if output.DeliveryDestinationConfiguration != nil &&
185+
aws.ToString(output.DeliveryDestinationConfiguration.DestinationResourceArn) == "" {
186+
output.DeliveryDestinationConfiguration = nil
187+
}
188+
155189
// Set attributes for import.
156190
response.Diagnostics.Append(fwflex.Flatten(ctx, output, &data)...)
157191
if response.Diagnostics.HasError() {

internal/service/logs/delivery_destination_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,47 @@ func TestAccLogsDeliveryDestination_disappears(t *testing.T) {
9090
})
9191
}
9292

93+
func TestAccLogsDeliveryDestination_XRAY(t *testing.T) {
94+
ctx := acctest.Context(t)
95+
var v awstypes.DeliveryDestination
96+
rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix)
97+
resourceName := "aws_cloudwatch_log_delivery_destination.test"
98+
99+
acctest.ParallelTest(ctx, t, resource.TestCase{
100+
PreCheck: func() {
101+
acctest.PreCheck(ctx, t)
102+
},
103+
ErrorCheck: acctest.ErrorCheck(t, names.LogsServiceID),
104+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
105+
CheckDestroy: testAccCheckDeliveryDestinationDestroy(ctx, t),
106+
Steps: []resource.TestStep{
107+
{
108+
Config: testAccDeliveryDestinationConfig_xray(rName),
109+
Check: resource.ComposeTestCheckFunc(
110+
testAccCheckDeliveryDestinationExists(ctx, t, resourceName, &v),
111+
),
112+
ConfigPlanChecks: resource.ConfigPlanChecks{
113+
PreApply: []plancheck.PlanCheck{
114+
plancheck.ExpectResourceAction(resourceName, plancheck.ResourceActionCreate),
115+
},
116+
},
117+
ConfigStateChecks: []statecheck.StateCheck{
118+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrARN), knownvalue.NotNull()),
119+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New("delivery_destination_type"), knownvalue.StringExact("XRAY")),
120+
statecheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrName), knownvalue.StringExact(rName)),
121+
},
122+
},
123+
{
124+
ResourceName: resourceName,
125+
ImportState: true,
126+
ImportStateVerify: true,
127+
ImportStateIdFunc: testAccDeliveryDestinationImportStateIDFunc(resourceName),
128+
ImportStateVerifyIdentifierAttribute: names.AttrName,
129+
},
130+
},
131+
})
132+
}
133+
93134
func TestAccLogsDeliveryDestination_tags(t *testing.T) {
94135
ctx := acctest.Context(t)
95136
var v awstypes.DeliveryDestination
@@ -456,6 +497,15 @@ resource "aws_cloudwatch_log_delivery_destination" "test" {
456497
`, rName)
457498
}
458499

500+
func testAccDeliveryDestinationConfig_xray(rName string) string {
501+
return fmt.Sprintf(`
502+
resource "aws_cloudwatch_log_delivery_destination" "test" {
503+
name = %[1]q
504+
delivery_destination_type = "XRAY"
505+
}
506+
`, rName)
507+
}
508+
459509
func testAccDeliveryDestinationConfig_tags1(rName, tag1Key, tag1Value string) string {
460510
return fmt.Sprintf(`
461511
resource "aws_cloudwatch_log_group" "test" {

website/docs/r/cloudwatch_log_delivery_destination.html.markdown

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,23 @@ resource "aws_cloudwatch_log_delivery_destination" "example" {
2424
}
2525
```
2626

27+
### X-Ray Trace Delivery
28+
29+
```terraform
30+
resource "aws_cloudwatch_log_delivery_destination" "xray" {
31+
name = "xray-traces"
32+
delivery_destination_type = "XRAY"
33+
}
34+
```
35+
2736
## Argument Reference
2837

2938
This resource supports the following arguments:
3039

3140
* `region` - (Optional) Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
32-
* `delivery_destination_configuration` - (Required) The AWS resource that will receive the logs.
33-
* `destination_resource_arn` - (Required) The ARN of the AWS destination that this delivery destination represents.
41+
* `delivery_destination_configuration` - (Optional) The AWS resource that will receive the logs. Required for CloudWatch Logs, Amazon S3, and Firehose destinations. Not required for X-Ray trace delivery destinations.
42+
* `destination_resource_arn` - (Optional) The ARN of the AWS destination that this delivery destination represents. Required when `delivery_destination_configuration` is specified.
43+
* `delivery_destination_type` - (Optional) The type of delivery destination. Valid values: `S3`, `CWL`, `FH`, `XRAY`. Required for X-Ray trace delivery destinations. For other destination types, this is computed from the `destination_resource_arn`.
3444
* `name` - (Required) The name for this delivery destination.
3545
* `output_format` - (Optional) The format of the logs that are sent to this delivery destination. Valid values: `json`, `plain`, `w3c`, `raw`, `parquet`.
3646
* `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
@@ -40,7 +50,6 @@ This resource supports the following arguments:
4050
This resource exports the following attributes in addition to the arguments above:
4151

4252
* `arn` - The Amazon Resource Name (ARN) of the delivery destination.
43-
* `delivery_destination_type` - Whether this delivery destination is CloudWatch Logs, Amazon S3, or Firehose.
4453
* `tags_all` - A map of tags assigned to the resource, including those inherited from the provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block).
4554

4655
## Import

0 commit comments

Comments
 (0)