AWS Amazon EC2 Traffic Mirror Target
This page shows how to write Terraform and CloudFormation for Amazon EC2 Traffic Mirror Target and write them securely.
aws_ec2_traffic_mirror_target (Terraform)
The Traffic Mirror Target in Amazon EC2 can be configured in Terraform with the resource name aws_ec2_traffic_mirror_target
. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_ec2_traffic_mirror_target" "this" {
description = var.description
network_interface_id = var.network_interface_id
network_load_balancer_arn = var.network_load_balancer_arn
tags = var.tags
}
resource "aws_ec2_traffic_mirror_target" "target" {
description = var.mirror_target_description
network_load_balancer_arn = var.network_load_balancer_arn
#network_interface_id = var.network_interface_id
tags = var.common_tags
}
resource "aws_ec2_traffic_mirror_target" "suricata" {
network_interface_id = data.terraform_remote_state.suricata.outputs.suricata_interface_id
}
resource "aws_ec2_traffic_mirror_session" "demo_ec2" {
network_interface_id = data.terraform_remote_state.base.outputs.demo_ec2_interface_id
resource "aws_ec2_traffic_mirror_target" "zeek_target" {
provider = aws.region-master
description = "VPC Tap for Zeek"
network_load_balancer_arn = aws_lb.ise-nlb-zk.arn
tags = {
Name = "NLB Mirror Target for Zeek Cluster"
resource "aws_ec2_traffic_mirror_target" "module_target" {
description = var.mirror_targ_desc
network_load_balancer_arn = var.nlb_name
}
resource "aws_ec2_traffic_mirror_filter" "module_filter" {
description = var.mirror_filt_desc
Parameters
-
arn
optional computed - string -
description
optional - string -
id
optional computed - string -
network_interface_id
optional - string -
network_load_balancer_arn
optional - string -
owner_id
optional computed - string -
tags
optional - map from string to string
Explanation in Terraform Registry
Provides a Traffic mirror target.
Read limits and considerations for traffic mirroring
Tips: Best Practices for The Other AWS Amazon EC2 Resources
In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_default_vpc
Ensure to avoid using default VPC
It is better to define the own VPC and use it.
aws_network_acl_rule
Ensure your network ACL rule blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
aws_ebs_volume
Ensure to use a customer-managed key for EBS volume encryption
It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).
aws_instance
Ensure to avoid storing AWS access keys in user data
It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.
aws_security_group
Ensure your security group blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
AWS::EC2::TrafficMirrorTarget (CloudFormation)
The TrafficMirrorTarget in EC2 can be configured in CloudFormation with the resource name AWS::EC2::TrafficMirrorTarget
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::EC2::TrafficMirrorTarget
Properties:
Description: VPC Target
NetworkInterfaceId: !Ref EC2InstanceInterfaceId
Tags:
- Key: :"Name"
Type: AWS::EC2::TrafficMirrorTarget
Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html
Type: AWS::EC2::TrafficMirrorTarget
Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html
Type: AWS::EC2::TrafficMirrorTarget
Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html
Type: AWS::EC2::TrafficMirrorTarget
Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html
"Type": "AWS::EC2::TrafficMirrorTarget",
"DependsOn" : "DDInstance",
"Properties": {
"Description": "Traffic mirror target associated with a network interface",
"NetworkInterfaceId": { "Ref" : "DataPort" },
"Tags": [{"Key": "Name","Value": "NetworkInterfaceTarget"}]
"Type": "AWS::EC2::TrafficMirrorTarget",
"Properties": {
"NetworkLoadBalancerArn": { "Ref": "NLB" },
"Tags": [{
"Key": "Name",
"Value": {
"resourceType": "AWS::EC2::TrafficMirrorTarget",
"filePath": null
}
]
},
{
"AWS::EC2::TrafficMirrorTarget": {
"Type": "AWS::EC2::TrafficMirrorTarget",
"Properties": {}
},
"AWS::Config::StoredQuery": {
"Type": "AWS::Config::StoredQuery",
"AWS::EC2::TrafficMirrorTarget": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html",
"Properties": {
"NetworkLoadBalancerArn": {
"Required": false,
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html#cfn-ec2-trafficmirrortarget-networkloadbalancerarn",
Parameters
-
NetworkLoadBalancerArn
optional - String -
Description
optional - String -
NetworkInterfaceId
optional - String -
Tags
optional - List of Tag
Explanation in CloudFormation Registry
Specifies a target for your Traffic Mirror session.
A Traffic Mirror target is the destination for mirrored traffic. The Traffic Mirror source and the Traffic Mirror target (monitoring appliances) can be in the same VPC, or in different VPCs connected via VPC peering or a transit gateway.
A Traffic Mirror target can be a network interface, or a Network Load Balancer.
To use the target in a Traffic Mirror session, use AWS::EC2::TrafficMirrorSession.
Frequently asked questions
What is AWS Amazon EC2 Traffic Mirror Target?
AWS Amazon EC2 Traffic Mirror Target is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Amazon EC2 Traffic Mirror Target?
For Terraform, the niveklabs/aws, JamesWoolfenden/terraform-aws-trafficmirror and hands-on-cloud/amazon-vpc-traffic-inspection-and-monitoring source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the awsvpc/pycompliance, awslabs/aws-service-catalog-products and awslabs/aws-service-catalog-products source code examples are useful. See the CloudFormation Example section for further details.