AWS Amazon EC2 Traffic Mirror Filter Rule
This page shows how to write Terraform and CloudFormation for Amazon EC2 Traffic Mirror Filter Rule and write them securely.
aws_ec2_traffic_mirror_filter_rule (Terraform)
The Traffic Mirror Filter Rule in Amazon EC2 can be configured in Terraform with the resource name aws_ec2_traffic_mirror_filter_rule
. The following sections describe 3 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_ec2_traffic_mirror_filter_rule" "zeek_outbound" {
provider = aws.region-master
description = "Zeek Outbound Rule"
traffic_mirror_filter_id = aws_ec2_traffic_mirror_filter.zeek_filter.id
destination_cidr_block = "0.0.0.0/0"
source_cidr_block = "0.0.0.0/0"
resource "aws_ec2_traffic_mirror_filter_rule" "module_outbound" {
description = "Capture all outbound"
traffic_mirror_filter_id = aws_ec2_traffic_mirror_filter.module_filter.id
destination_cidr_block = "0.0.0.0/0"
source_cidr_block = "0.0.0.0/0"
rule_number = 1
resource "aws_ec2_traffic_mirror_filter_rule" "module_outbound" {
description = "Capture all outbound"
traffic_mirror_filter_id = aws_ec2_traffic_mirror_filter.module_filter.id
destination_cidr_block = "0.0.0.0/0"
source_cidr_block = "0.0.0.0/0"
rule_number = 1
Parameters
-
arn
optional computed - string -
description
optional - string -
destination_cidr_block
required - string -
id
optional computed - string -
protocol
optional - number -
rule_action
required - string -
rule_number
required - number -
source_cidr_block
required - string -
traffic_direction
required - string -
traffic_mirror_filter_id
required - string -
destination_port_range
list block -
source_port_range
list block
Explanation in Terraform Registry
Provides an Traffic mirror filter rule.
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::TrafficMirrorFilterRule (CloudFormation)
The TrafficMirrorFilterRule in EC2 can be configured in CloudFormation with the resource name AWS::EC2::TrafficMirrorFilterRule
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: "AWS::EC2::TrafficMirrorFilterRule"
Properties:
Description: "Accept RDP"
TrafficMirrorFilterId: !Ref VPCTrafficMirrorFilter
TrafficDirection: "ingress"
RuleNumber: 10
Type: AWS::EC2::TrafficMirrorFilterRule
Properties:
Description: Mirror all TCP ingress traffic.
DestinationCidrBlock: 0.0.0.0/0
DestinationPortRange:
FromPort: 0
Type: AWS::EC2::TrafficMirrorFilterRule
Properties:
Description: Mirror all TCP ingress traffic.
DestinationCidrBlock: 0.0.0.0/0
DestinationPortRange:
FromPort: 0
Type: AWS::EC2::TrafficMirrorFilterRule
Properties:
Description: !Sub "Created by ${AWS::StackName}"
TrafficMirrorFilterId: !Ref TrafficMirrorFilter
TrafficDirection: "ingress"
RuleNumber: 11
Type: "AWS::EC2::TrafficMirrorFilterRule"
Properties:
Description: "Filter for ALL ingress traffic"
TrafficMirrorFilterId: !Ref WiresharkTrafficMirrorFilter
TrafficDirection: "ingress"
RuleNumber: 10
"Type": "AWS::EC2::TrafficMirrorFilterRule",
"Properties": {
"TrafficMirrorFilterId": { "Ref": "TrafficMirrorFilter1" },
"TrafficDirection": "ingress",
"RuleAction": "accept",
"Protocol": 6,
"AWS::EC2::TrafficMirrorFilterRule.TrafficMirrorPortRange": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-trafficmirrorfilterrule-trafficmirrorportrange.html",
"Properties": {
"FromPort": {
"Required": true,
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-trafficmirrorfilterrule-trafficmirrorportrange.html#cfn-ec2-trafficmirrorfilterrule-trafficmirrorportrange-fromport",
"Type" : "AWS::EC2::TrafficMirrorFilterRule",
"Properties" : {
"Description" : "Ingress",
"DestinationCidrBlock" : "0.0.0.0/0",
"RuleAction" : "accept",
"RuleNumber" : "100",
"resourceType": "AWS::EC2::TrafficMirrorFilterRule",
"filePath": null
},
{
"resourceType": "AWS::EC2::VPC",
"filePath": "icons/aws/Service/Arch_Networking-Content/64/Arch_Amazon-Virtual-Private-Cloud_64@5x.png"
"AWS::EC2::TrafficMirrorFilterRule": {
"Type": "AWS::EC2::TrafficMirrorFilterRule",
"Properties": {}
},
"AWS::ApiGateway::RestApi": {
"Type": "AWS::ApiGateway::RestApi",
Parameters
-
DestinationPortRange
optional - TrafficMirrorPortRange -
Description
optional - String -
SourcePortRange
optional - TrafficMirrorPortRange -
RuleAction
required - String -
SourceCidrBlock
required - String -
RuleNumber
required - Integer -
DestinationCidrBlock
required - String -
TrafficMirrorFilterId
required - String -
TrafficDirection
required - String -
Protocol
optional - Integer
Explanation in CloudFormation Registry
Creates a Traffic Mirror filter rule.
A Traffic Mirror rule defines the Traffic Mirror source traffic to mirror.
You need the Traffic Mirror filter ID when you create the rule.
Frequently asked questions
What is AWS Amazon EC2 Traffic Mirror Filter Rule?
AWS Amazon EC2 Traffic Mirror Filter Rule 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 Filter Rule?
For Terraform, the jazhans/zeek_terransible_aws, jazhans/terraform_modules and jazhans/terraform_modules source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the awsvpc/pycompliance, seek-ret/installation and sjakthol/aws-vpc-traffic-mirroring source code examples are useful. See the CloudFormation Example section for further details.