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_tarffic_mirror_target - add arn attribute #13649

Merged
merged 2 commits into from
Jun 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion aws/resource_aws_ec2_traffic_mirror_target.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/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
Expand Down Expand Up @@ -45,6 +46,10 @@ func resourceAwsEc2TrafficMirrorTarget() *schema.Resource {
ValidateFunc: validateArn,
},
"tags": tagsSchema(),
"arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -74,7 +79,7 @@ func resourceAwsEc2TrafficMirrorTargetCreate(d *schema.ResourceData, meta interf
return fmt.Errorf("Error creating traffic mirror target %v", err)
}

d.SetId(*out.TrafficMirrorTarget.TrafficMirrorTargetId)
d.SetId(aws.StringValue(out.TrafficMirrorTarget.TrafficMirrorTargetId))

return resourceAwsEc2TrafficMirrorTargetRead(d, meta)
}
Expand Down Expand Up @@ -128,6 +133,16 @@ func resourceAwsEc2TrafficMirrorTargetRead(d *schema.ResourceData, meta interfac
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-target/%s", d.Id()),
}.String()

d.Set("arn", arn)

return nil
}

Expand Down
14 changes: 2 additions & 12 deletions aws/resource_aws_ec2_traffic_mirror_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestAccAWSEc2TrafficMirrorTarget_nlb(t *testing.T) {
Config: testAccTrafficMirrorTargetConfigNlb(rName, description),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TrafficMirrorTargetExists(resourceName, &v),
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"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
Expand Down Expand Up @@ -144,7 +145,7 @@ func TestAccAWSEc2TrafficMirrorTarget_disappears(t *testing.T) {
Config: testAccTrafficMirrorTargetConfigNlb(rName, description),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TrafficMirrorTargetExists(resourceName, &v),
testAccCheckAWSEc2TrafficMirrorTargetDisappears(&v),
testAccCheckResourceDisappears(testAccProvider, resourceAwsEc2TrafficMirrorTarget(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down Expand Up @@ -183,17 +184,6 @@ func testAccCheckAWSEc2TrafficMirrorTargetExists(name string, target *ec2.Traffi
}
}

func testAccCheckAWSEc2TrafficMirrorTargetDisappears(target *ec2.TrafficMirrorTarget) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
_, err := conn.DeleteTrafficMirrorTarget(&ec2.DeleteTrafficMirrorTargetInput{
TrafficMirrorTargetId: target.TrafficMirrorTargetId,
})

return err
}
}

func testAccTrafficMirrorTargetConfigBase(rName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "azs" {
Expand Down
3 changes: 2 additions & 1 deletion website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ for more information about connecting to alternate AWS endpoints or AWS compatib
- [`aws_dx_public_virtual_interface` resource](/docs/providers/aws/r/dx_public_virtual_interface.html)
- [`aws_dx_transit_virtual_interface` resource](/docs/providers/aws/r/dx_transit_virtual_interface.html)
- [`aws_ebs_volume` data source](/docs/providers/aws/d/ebs_volume.html)
- [`aws_ec2_client_vpn_endpoint` resource](/docs/providers/aws/r/ec2_client_vpn_endpoint.html)
- [`aws_ec2_client_vpn_endpoint` resource](/docs/providers/aws/r/ec2_client_vpn_endpoint.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)
- [`aws_ecs_service` resource (import)](/docs/providers/aws/r/ecs_service.html)
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/ec2_traffic_mirror_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ The following arguments are supported:

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

* `id` - The name of the traffic mirror target.
* `id` - The ID of the Traffic Mirror target.
* `arn` - The ARN of the traffic mirror target.

## Import

Expand Down