-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
service/ec2: New Resources for EC2 Traffic Mirroring (#9372)
Output from acceptance testing: ``` --- PASS: TestAccAWSEc2TrafficMirrorFilter_basic (19.81s) --- PASS: TestAccAWSEc2TrafficMirrorFilterRule_basic (20.82s) --- PASS: TestAccAWSEc2TrafficMirrorTarget_eni (63.62s) --- PASS: TestAccAWSEc2TrafficMirrorTarget_nlb (240.87s) --- PASS: TestAccAWSEc2TrafficMirrorSession_basic (282.32s) ```
- v5.82.2
- v5.82.1
- v5.82.0
- v5.81.0
- v5.80.0
- v5.79.0
- v5.78.0
- v5.77.0
- v5.76.0
- v5.75.1
- v5.75.0
- v5.74.0
- v5.73.0
- v5.72.1
- v5.72.0
- v5.71.0
- v5.70.0
- v5.69.0
- v5.68.0
- v5.67.0
- v5.66.0
- v5.65.0
- v5.64.0
- v5.63.1
- v5.63.0
- v5.62.0
- v5.61.0
- v5.60.0
- v5.59.0
- v5.58.0
- v5.57.0
- v5.56.1
- v5.56.0
- v5.55.0
- v5.54.1
- v5.54.0
- v5.53.0
- v5.52.0
- v5.51.1
- v5.51.0
- v5.50.0
- v5.49.0
- v5.48.0
- v5.47.0
- v5.46.0
- v5.45.0
- v5.44.0
- v5.43.0
- v5.42.0
- v5.41.0
- v5.40.0
- v5.39.1
- v5.39.0
- v5.38.0
- v5.37.0
- v5.36.0
- v5.35.0
- v5.34.0
- v5.33.0
- v5.32.1
- v5.32.0
- v5.31.0
- v5.30.0
- v5.29.0
- v5.28.0
- v5.27.0
- v5.26.0
- v5.25.0
- v5.24.0
- v5.23.1
- v5.23.0
- v5.22.0
- v5.21.0
- v5.20.1
- v5.20.0
- v5.19.0
- v5.18.1
- v5.18.0
- v5.17.0
- v5.16.2
- v5.16.1
- v5.16.0
- v5.15.0
- v5.14.0
- v5.13.1
- v5.13.0
- v5.12.0
- v5.11.0
- v5.10.0
- v5.9.0
- v5.8.0
- v5.7.0
- v5.6.2
- v5.6.1
- v5.6.0
- v5.5.0
- v5.4.0
- v5.3.0
- v5.2.0
- v5.1.0
- v5.0.1
- v5.0.0
- v4.67.0
- v4.66.1
- v4.66.0
- v4.65.0
- v4.64.0
- v4.63.0
- v4.62.0
- v4.61.0
- v4.60.0
- v4.59.0
- v4.58.0
- v4.57.1
- v4.57.0
- v4.56.0
- v4.55.0
- v4.54.0
- v4.53.0
- v4.52.0
- v4.51.0
- v4.50.0
- v4.49.0
- v4.48.0
- v4.47.0
- v4.46.0
- v4.45.0
- v4.44.0
- v4.43.0
- v4.42.0
- v4.41.0
- v4.40.0
- v4.39.0
- v4.38.0
- v4.37.0
- v4.36.1
- v4.36.0
- v4.35.0
- v4.34.0
- v4.33.0
- v4.32.0
- v4.31.0
- v4.30.0
- v4.29.0
- v4.28.0
- v4.27.0
- v4.26.0
- v4.25.0
- v4.24.0
- v4.23.0
- v4.22.0
- v4.21.0
- v4.20.1
- v4.20.0
- v4.19.0
- v4.18.0
- v4.17.1
- v4.17.0
- v4.16.0
- v4.15.1
- v4.15.0
- v4.14.0
- v4.13.0
- v4.12.1
- v4.12.0
- v4.11.0
- v4.10.0
- v4.9.0
- v4.8.0
- v4.7.0
- v4.6.0
- v4.5.0
- v4.4.0
- v4.3.0
- v4.2.0
- v4.1.0
- v4.0.0
- v3.76.1
- v3.76.0
- v3.75.2
- v3.75.1
- v3.75.0
- v3.74.3
- v3.74.2
- v3.74.1
- v3.74.0
- v3.73.0
- v3.72.0
- v3.71.0
- v3.70.0
- v3.69.0
- v3.68.0
- v3.67.0
- v3.66.0
- v3.65.0
- v3.64.3
- v3.64.2
- v3.64.1
- v3.64.0
- v3.63.0
- v3.62.0
- v3.61.0
- v3.60.0
- v3.59.0
- v3.58.0
- v3.57.0
- v3.56.0
- v3.55.0
- v3.54.0
- v3.53.0
- v3.52.0
- v3.51.0
- v3.50.0
- v3.49.0
- v3.48.0
- v3.47.0
- v3.46.0
- v3.45.0
- v3.44.0
- v3.43.0
- v3.42.0
- v3.41.0
- v3.40.0
- v3.39.0
- v3.38.0
- v3.37.0
- v3.36.0
- v3.35.0
- v3.34.0
- v3.33.0
- v3.32.0
- v3.31.0
- v3.30.0
- v3.29.1
- v3.29.0
- v3.28.0
- v3.27.0
- v3.26.18
- v3.26.17
- v3.26.16
- v3.26.10
- v3.26.5
- v3.26.3
- v3.26.2
- v3.26.1
- v3.26.0
- v3.25.0
- v3.24.1
- v3.24.0
- v3.23.0
- v3.22.0
- v3.21.0
- v3.20.0
- v3.19.0
- v3.18.0
- v3.17.0
- v3.16.0
- v3.15.0
- v3.14.1
- v3.14.0
- v3.13.0
- v3.12.0
- v3.11.0
- v3.10.0
- v3.9.0
- v3.8.0
- v3.7.0
- v3.6.0
- v3.5.0
- v3.4.0
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.0
- v2.70.4
- v2.70.3
- v2.70.2
- v2.70.1
- v2.70.0
- v2.69.0
- v2.68.0
- v2.67.0
- v2.66.0
- v2.65.0
- v2.64.0
- v2.63.0
- v2.62.0
- v2.61.0
- v2.60.0
- v2.59.0
- v2.58.0
- v2.57.0
- v2.56.0
- v2.55.0
- v2.54.0
- v2.53.0
- v2.52.0
- v2.51.0
1 parent
286667c
commit 473cfe9
Showing
14 changed files
with
1,975 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ec2" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceAwsEc2TrafficMirrorFilter() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAwsEc2TrafficMirrorinFilterCreate, | ||
Read: resourceAwsEc2TrafficMirrorFilterRead, | ||
Update: resourceAwsEc2TrafficMirrorFilterUpdate, | ||
Delete: resourceAwsEc2TrafficMirrorFilterDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"description": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"network_services": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
"amazon-dns", | ||
}, false), | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAwsEc2TrafficMirrorinFilterCreate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
|
||
input := &ec2.CreateTrafficMirrorFilterInput{} | ||
|
||
if description, ok := d.GetOk("description"); ok { | ||
input.Description = aws.String(description.(string)) | ||
} | ||
|
||
out, err := conn.CreateTrafficMirrorFilter(input) | ||
if err != nil { | ||
return fmt.Errorf("Error while creating traffic filter %s", err) | ||
} | ||
|
||
d.SetId(*out.TrafficMirrorFilter.TrafficMirrorFilterId) | ||
|
||
return resourceAwsEc2TrafficMirrorFilterUpdate(d, meta) | ||
} | ||
|
||
func resourceAwsEc2TrafficMirrorFilterUpdate(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
|
||
if d.HasChange("network_services") { | ||
input := &ec2.ModifyTrafficMirrorFilterNetworkServicesInput{ | ||
TrafficMirrorFilterId: aws.String(d.Id()), | ||
} | ||
|
||
o, n := d.GetChange("network_services") | ||
newServices := n.(*schema.Set).Difference(o.(*schema.Set)).List() | ||
if len(newServices) > 0 { | ||
input.AddNetworkServices = expandStringList(newServices) | ||
} | ||
|
||
removeServices := o.(*schema.Set).Difference(n.(*schema.Set)).List() | ||
if len(removeServices) > 0 { | ||
input.RemoveNetworkServices = expandStringList(removeServices) | ||
} | ||
|
||
_, err := conn.ModifyTrafficMirrorFilterNetworkServices(input) | ||
if err != nil { | ||
return fmt.Errorf("error modifying EC2 Traffic Mirror Filter (%s) network services: %w", d.Id(), err) | ||
} | ||
} | ||
|
||
return resourceAwsEc2TrafficMirrorFilterRead(d, meta) | ||
} | ||
|
||
func resourceAwsEc2TrafficMirrorFilterRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
|
||
input := &ec2.DescribeTrafficMirrorFiltersInput{ | ||
TrafficMirrorFilterIds: aws.StringSlice([]string{d.Id()}), | ||
} | ||
|
||
out, err := conn.DescribeTrafficMirrorFilters(input) | ||
if err != nil { | ||
return fmt.Errorf("Error describing traffic mirror filter %v: %v", d.Id(), err) | ||
} | ||
|
||
if len(out.TrafficMirrorFilters) == 0 { | ||
log.Printf("[WARN] EC2 Traffic Mirror Filter (%s) not found, removing from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
d.SetId(*out.TrafficMirrorFilters[0].TrafficMirrorFilterId) | ||
d.Set("description", out.TrafficMirrorFilters[0].Description) | ||
|
||
if err := d.Set("network_services", aws.StringValueSlice(out.TrafficMirrorFilters[0].NetworkServices)); err != nil { | ||
return fmt.Errorf("error setting network_services for filter %v: %s", d.Id(), err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func resourceAwsEc2TrafficMirrorFilterDelete(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).ec2conn | ||
|
||
input := &ec2.DeleteTrafficMirrorFilterInput{ | ||
TrafficMirrorFilterId: aws.String(d.Id()), | ||
} | ||
|
||
_, err := conn.DeleteTrafficMirrorFilter(input) | ||
if err != nil { | ||
return fmt.Errorf("Error deleting traffic mirror filter %v: %v", d.Id(), err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.