diff --git a/aws/resource_aws_ec2_traffic_mirror_target.go b/aws/resource_aws_ec2_traffic_mirror_target.go index b712d361838..023500b832d 100644 --- a/aws/resource_aws_ec2_traffic_mirror_target.go +++ b/aws/resource_aws_ec2_traffic_mirror_target.go @@ -21,6 +21,10 @@ func resourceAwsEc2TrafficMirrorTarget() *schema.Resource { State: schema.ImportStatePassthrough, }, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, "description": { Type: schema.TypeString, Optional: true, @@ -45,11 +49,11 @@ func resourceAwsEc2TrafficMirrorTarget() *schema.Resource { }, ValidateFunc: validateArn, }, - "tags": tagsSchema(), - "arn": { + "owner_id": { Type: schema.TypeString, Computed: true, }, + "tags": tagsSchema(), }, } } @@ -133,11 +137,13 @@ func resourceAwsEc2TrafficMirrorTargetRead(d *schema.ResourceData, meta interfac return fmt.Errorf("error setting tags: %s", err) } + d.Set("owner_id", target.OwnerId) + arn := arn.ARN{ Partition: meta.(*AWSClient).partition, Service: ec2.ServiceName, Region: meta.(*AWSClient).region, - AccountID: meta.(*AWSClient).accountid, + AccountID: aws.StringValue(target.OwnerId), Resource: fmt.Sprintf("traffic-mirror-target/%s", d.Id()), }.String() diff --git a/aws/resource_aws_ec2_traffic_mirror_target_test.go b/aws/resource_aws_ec2_traffic_mirror_target_test.go index 6c39895493d..385dbec107d 100644 --- a/aws/resource_aws_ec2_traffic_mirror_target_test.go +++ b/aws/resource_aws_ec2_traffic_mirror_target_test.go @@ -30,6 +30,7 @@ func TestAccAWSEc2TrafficMirrorTarget_nlb(t *testing.T) { Config: testAccTrafficMirrorTargetConfigNlb(rName, description), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEc2TrafficMirrorTargetExists(resourceName, &v), + testAccCheckResourceAttrAccountID(resourceName, "owner_id"), testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`traffic-mirror-target/tmt-.+`)), resource.TestCheckResourceAttr(resourceName, "description", description), resource.TestCheckResourceAttrPair(resourceName, "network_load_balancer_arn", "aws_lb.lb", "arn"), diff --git a/website/docs/r/ec2_traffic_mirror_target.html.markdown b/website/docs/r/ec2_traffic_mirror_target.html.markdown index cc185772723..26bd67d350b 100644 --- a/website/docs/r/ec2_traffic_mirror_target.html.markdown +++ b/website/docs/r/ec2_traffic_mirror_target.html.markdown @@ -44,6 +44,7 @@ In addition to all arguments above, the following attributes are exported: * `id` - The ID of the Traffic Mirror target. * `arn` - The ARN of the traffic mirror target. +* `owner_id` - The ID of the AWS account that owns the traffic mirror target. ## Import