Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f-aws_ec2_traffic_mirror_target #26864

Merged
merged 6 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/26767.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ec2_traffic_mirror_target: Add `gateway_load_balancer_endpoint_id` argument
```
17 changes: 17 additions & 0 deletions internal/service/ec2/vpc_traffic_mirror_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,22 @@ func ResourceTrafficMirrorTarget() *schema.Resource {
Optional: true,
ForceNew: true,
},
"gateway_load_balancer_endpoint_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ExactlyOneOf: []string{
"gateway_load_balancer_endpoint_id",
"network_interface_id",
"network_load_balancer_arn",
},
},
"network_interface_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ExactlyOneOf: []string{
"gateway_load_balancer_endpoint_id",
"network_interface_id",
"network_load_balancer_arn",
},
Expand All @@ -50,6 +61,7 @@ func ResourceTrafficMirrorTarget() *schema.Resource {
Optional: true,
ForceNew: true,
ExactlyOneOf: []string{
"gateway_load_balancer_endpoint_id",
"network_interface_id",
"network_load_balancer_arn",
},
Expand All @@ -76,6 +88,10 @@ func resourceTrafficMirrorTargetCreate(d *schema.ResourceData, meta interface{})
input.Description = aws.String(v.(string))
}

if v, ok := d.GetOk("gateway_load_balancer_endpoint_id"); ok {
input.GatewayLoadBalancerEndpointId = aws.String(v.(string))
}

if v, ok := d.GetOk("network_interface_id"); ok {
input.NetworkInterfaceId = aws.String(v.(string))
}
Expand Down Expand Up @@ -141,6 +157,7 @@ func resourceTrafficMirrorTargetRead(d *schema.ResourceData, meta interface{}) e

target := out.TrafficMirrorTargets[0]
d.Set("description", target.Description)
d.Set("gateway_load_balancer_endpoint_id", target.GatewayLoadBalancerEndpointId)
d.Set("network_interface_id", target.NetworkInterfaceId)
d.Set("network_load_balancer_arn", target.NetworkLoadBalancerArn)

Expand Down
44 changes: 44 additions & 0 deletions internal/service/ec2/vpc_traffic_mirror_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,37 @@ func TestAccVPCTrafficMirrorTarget_disappears(t *testing.T) {
})
}

func TestAccVPCTrafficMirrorTarget_gwlb(t *testing.T) {

resourceName := "aws_ec2_traffic_mirror_target.test"
rName := fmt.Sprintf("tf-acc-test-%s", sdkacctest.RandString(10))
description := "test gwlb endpoint target"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(t)
testAccPreCheckTrafficMirrorTarget(t)
},
ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckTrafficMirrorTargetDestroy,
Steps: []resource.TestStep{
{
Config: testAccVPCTrafficMirrorTargetConfig_gwlb(rName, description),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "description", description),
resource.TestMatchResourceAttr(resourceName, "gateway_load_balancer_endpoint_id", regexp.MustCompile("vpce-.*")),
meetreks marked this conversation as resolved.
Show resolved Hide resolved
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckTrafficMirrorTargetExists(name string, target *ec2.TrafficMirrorTarget) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down Expand Up @@ -332,6 +363,19 @@ resource "aws_ec2_traffic_mirror_target" "test" {
`, rName, description, tagKey1, tagValue1, tagKey2, tagValue2))
}

func testAccVPCTrafficMirrorTargetConfig_gwlb(rName, description string) string {
return acctest.ConfigCompose(
//testAccTrafficMirrorTargetConfigBase(rName),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this unused comment as well

Suggested change
//testAccTrafficMirrorTargetConfigBase(rName),

testAccVPCEndpointConfig_gatewayLoadBalancer(rName),
fmt.Sprintf(`
resource "aws_ec2_traffic_mirror_target" "test" {
description = %[2]q
gateway_load_balancer_endpoint_id = aws_vpc_endpoint.test.id
depends_on = [aws_vpc_endpoint.test]
}
`, rName, description))
}

func testAccPreCheckTrafficMirrorTarget(t *testing.T) {
conn := acctest.Provider.Meta().(*conns.AWSClient).EC2Conn

Expand Down
6 changes: 6 additions & 0 deletions website/docs/r/ec2_traffic_mirror_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ resource "aws_ec2_traffic_mirror_target" "eni" {
description = "ENI target"
network_interface_id = aws_instance.test.primary_network_interface_id
}

resource "aws_ec2_traffic_mirror_target" "gwlb" {
description = "GWLB target"
gateway_load_balancer_endpoint_id = aws_lb.lb.arn
meetreks marked this conversation as resolved.
Show resolved Hide resolved
}
```

## Argument Reference
Expand All @@ -34,6 +39,7 @@ The following arguments are supported:
* `description` - (Optional, Forces new) A description of the traffic mirror session.
* `network_interface_id` - (Optional, Forces new) The network interface ID that is associated with the target.
* `network_load_balancer_arn` - (Optional, Forces new) The Amazon Resource Name (ARN) of the Network Load Balancer that is associated with the target.
* `gateway_load_balancer_endpoint_id` - (Optional, Forces new) The VPC Endpoint Id of the Gateway Load Balancer that is associated with the target.
* `tags` - (Optional) Key-value map of resource tags. 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.

**NOTE:** Either `network_interface_id` or `network_load_balancer_arn` should be specified and both should not be specified together
Expand Down