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

r/ec2_traffic_mirror_filter - add arn attribute #13948

Merged
merged 5 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all 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/13948.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ec2_traffic_mirror_filter: Add `arn` attribute.
```
15 changes: 15 additions & 0 deletions aws/resource_aws_ec2_traffic_mirror_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand All @@ -21,6 +22,10 @@ func resourceAwsEc2TrafficMirrorFilter() *schema.Resource {
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -150,6 +155,16 @@ func resourceAwsEc2TrafficMirrorFilterRead(d *schema.ResourceData, meta interfac
return fmt.Errorf("error setting network_services for filter %v: %s", d.Id(), err)
}

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "ec2",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("traffic-mirror-filter/%s", d.Id()),
}.String()

d.Set("arn", arn)

return nil
}

Expand Down
15 changes: 3 additions & 12 deletions aws/resource_aws_ec2_traffic_mirror_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -28,6 +29,7 @@ func TestAccAWSEc2TrafficMirrorFilter_basic(t *testing.T) {
Config: testAccTrafficMirrorFilterConfig(description),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TrafficMirrorFilterExists(resourceName, &v),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`traffic-mirror-filter/tmf-.+`)),
resource.TestCheckResourceAttr(resourceName, "description", description),
resource.TestCheckResourceAttr(resourceName, "network_services.#", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down Expand Up @@ -122,7 +124,7 @@ func TestAccAWSEc2TrafficMirrorFilter_disappears(t *testing.T) {
Config: testAccTrafficMirrorFilterConfig(description),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TrafficMirrorFilterExists(resourceName, &v),
testAccCheckAWSEc2TrafficMirrorFilterDisappears(&v),
testAccCheckResourceDisappears(testAccProvider, resourceAwsEc2TrafficMirrorFilter(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down Expand Up @@ -161,17 +163,6 @@ func testAccCheckAWSEc2TrafficMirrorFilterExists(name string, traffic *ec2.Traff
}
}

func testAccCheckAWSEc2TrafficMirrorFilterDisappears(traffic *ec2.TrafficMirrorFilter) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
_, err := conn.DeleteTrafficMirrorFilter(&ec2.DeleteTrafficMirrorFilterInput{
TrafficMirrorFilterId: traffic.TrafficMirrorFilterId,
})

return err
}
}

func testAccTrafficMirrorFilterConfig(description string) string {
return fmt.Sprintf(`
resource "aws_ec2_traffic_mirror_filter" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ for more information about connecting to alternate AWS endpoints or AWS compatib
- [`aws_ebs_volume` data source](/docs/providers/aws/d/ebs_volume.html)
- [`aws_ec2_capacity_reservation` resource](/docs/providers/aws/r/ec2_capacity_reservation.html)
- [`aws_ec2_client_vpn_endpoint` resource](/docs/providers/aws/r/ec2_client_vpn_endpoint.html)
- [`aws_ec2_traffic_mirror_filter` resource](/docs/providers/aws/r/ec2_traffic_mirror_filter.html)
- [`aws_ec2_traffic_mirror_filter_rule` resource](/docs/providers/aws/r/ec2_traffic_mirror_filter_rule.html)
- [`aws_ec2_traffic_mirror_session` resource](/docs/providers/aws/r/ec2_traffic_mirror_session.html)
- [`aws_ec2_traffic_mirror_target` resource](/docs/providers/aws/r/ec2_traffic_mirror_target.html)
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ec2_traffic_mirror_filter.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The following arguments are supported:

In addition to all arguments above, the following attributes are exported:

* `arn` - The ARN of the traffic mirror filter.
* `id` - The name of the filter.

## Import
Expand Down