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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/ec2_traffic_mirror_session - add arn attribute #13849

Merged
merged 2 commits into from Jun 22, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion aws/resource_aws_ec2_traffic_mirror_session.go
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/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand All @@ -21,6 +22,10 @@ func resourceAwsEc2TrafficMirrorSession() *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 @@ -92,7 +97,7 @@ func resourceAwsEc2TrafficMirrorSessionCreate(d *schema.ResourceData, meta inter
return fmt.Errorf("Error creating traffic mirror session %v", err)
}

d.SetId(*out.TrafficMirrorSession.TrafficMirrorSessionId)
d.SetId(aws.StringValue(out.TrafficMirrorSession.TrafficMirrorSessionId))
return resourceAwsEc2TrafficMirrorSessionRead(d, meta)
}

Expand Down Expand Up @@ -212,6 +217,16 @@ func resourceAwsEc2TrafficMirrorSessionRead(d *schema.ResourceData, meta interfa
return fmt.Errorf("error setting tags: %s", err)
}

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

d.Set("arn", arn)

return nil
}

Expand Down
14 changes: 2 additions & 12 deletions aws/resource_aws_ec2_traffic_mirror_session_test.go
Expand Up @@ -42,6 +42,7 @@ func TestAccAWSEc2TrafficMirrorSession_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "session_number", strconv.Itoa(session)),
resource.TestMatchResourceAttr(resourceName, "virtual_network_id", regexp.MustCompile(`\d+`)),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`traffic-mirror-session/tms-.+`)),
),
},
// update of description, packet length and VNI
Expand Down Expand Up @@ -142,7 +143,7 @@ func TestAccAWSEc2TrafficMirrorSession_disappears(t *testing.T) {
Config: testAccTrafficMirrorSessionConfig(rName, session),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TrafficMirrorSessionExists(resourceName, &v),
testAccCheckAWSEc2TrafficMirrorSessionDisappears(&v),
testAccCheckResourceDisappears(testAccProvider, resourceAwsEc2TrafficMirrorSession(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down Expand Up @@ -181,17 +182,6 @@ func testAccCheckAWSEc2TrafficMirrorSessionExists(name string, session *ec2.Traf
}
}

func testAccCheckAWSEc2TrafficMirrorSessionDisappears(session *ec2.TrafficMirrorSession) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
_, err := conn.DeleteTrafficMirrorSession(&ec2.DeleteTrafficMirrorSessionInput{
TrafficMirrorSessionId: session.TrafficMirrorSessionId,
})

return err
}
}

func testAccTrafficMirrorSessionConfigBase(rName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "azs" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/index.html.markdown
Expand Up @@ -249,6 +249,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_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)
- [`aws_ecs_capacity_provider` resource (import)](/docs/providers/aws/r/ecs_capacity_provider.html)
- [`aws_ecs_cluster` resource (import)](/docs/providers/aws/r/ecs_cluster.html)
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ec2_traffic_mirror_session.html.markdown
Expand Up @@ -50,6 +50,7 @@ The following arguments are supported:

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

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

## Import
Expand Down