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

main.tf#L7
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
}
aws_ec2_traffic_mirror_target.target.tf#L1
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
}
main.tf#L54
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
ise-trf-mir-zk.tf#L2
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"
main.tf#L1
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

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

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).

risk-label

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.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

VPCMirrorCFT.yml#L11
    Type: AWS::EC2::TrafficMirrorTarget
    Properties:
      Description: VPC Target
      NetworkInterfaceId: !Ref EC2InstanceInterfaceId
      Tags:
      - Key: :"Name"
product.template-ap-southeast-1.yaml#L5
    Type: AWS::EC2::TrafficMirrorTarget
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html
product.template-us-east-1.yaml#L5
    Type: AWS::EC2::TrafficMirrorTarget
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html
product.template-sa-east-1.yaml#L5
    Type: AWS::EC2::TrafficMirrorTarget
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html
product.template-ap-northeast-2.yaml#L5
    Type: AWS::EC2::TrafficMirrorTarget
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrortarget.html
DDI.json#L86
         "Type": "AWS::EC2::TrafficMirrorTarget",
         "DependsOn" : "DDInstance",
         "Properties": {
            "Description": "Traffic mirror target associated with a network interface",
            "NetworkInterfaceId": { "Ref" : "DataPort" },
            "Tags": [{"Key": "Name","Value": "NetworkInterfaceTarget"}]
trafficMirrorMonitor_CFTemplate.json#L526
            "Type": "AWS::EC2::TrafficMirrorTarget",
            "Properties": {
                "NetworkLoadBalancerArn": { "Ref": "NLB" },
                "Tags": [{
                    "Key": "Name",
                    "Value": {
awsResouceIconMatches.json#L310
        "resourceType": "AWS::EC2::TrafficMirrorTarget",
        "filePath": null
      }
    ]
  },
  {
template.json#L3043
    "AWS::EC2::TrafficMirrorTarget": {
      "Type": "AWS::EC2::TrafficMirrorTarget",
      "Properties": {}
    },
    "AWS::Config::StoredQuery": {
      "Type": "AWS::Config::StoredQuery",
EC2TrafficMirrorTargetSpecification.json#L22
    "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

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.