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

add tagging support to ec2 traffic mirror target #12135

Merged
merged 2 commits into from
Mar 9, 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
26 changes: 26 additions & 0 deletions aws/resource_aws_ec2_traffic_mirror_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"github.com/aws/aws-sdk-go/aws"
"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"
)

func resourceAwsEc2TrafficMirrorTarget() *schema.Resource {
return &schema.Resource{
Create: resourceAwsEc2TrafficMirrorTargetCreate,
Read: resourceAwsEc2TrafficMirrorTargetRead,
Update: resourceAwsEc2TrafficMirrorTargetUpdate,
Delete: resourceAwsEc2TrafficMirrorTargetDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
Expand Down Expand Up @@ -40,7 +42,9 @@ func resourceAwsEc2TrafficMirrorTarget() *schema.Resource {
"network_interface_id",
"network_load_balancer_arn",
},
ValidateFunc: validateArn,
},
"tags": tagsSchema(),
},
}
}
Expand All @@ -61,6 +65,10 @@ func resourceAwsEc2TrafficMirrorTargetCreate(d *schema.ResourceData, meta interf
input.NetworkLoadBalancerArn = aws.String(v.(string))
}

if v, ok := d.GetOk("tags"); ok {
input.TagSpecifications = ec2TagSpecificationsFromMap(v.(map[string]interface{}), ec2.ResourceTypeTrafficMirrorTarget)
}

out, err := conn.CreateTrafficMirrorTarget(input)
if err != nil {
return fmt.Errorf("Error creating traffic mirror target %v", err)
Expand All @@ -71,6 +79,20 @@ func resourceAwsEc2TrafficMirrorTargetCreate(d *schema.ResourceData, meta interf
return resourceAwsEc2TrafficMirrorTargetRead(d, meta)
}

func resourceAwsEc2TrafficMirrorTargetUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

if d.HasChange("tags") {
o, n := d.GetChange("tags")

if err := keyvaluetags.Ec2UpdateTags(conn, d.Id(), o, n); err != nil {
return fmt.Errorf("error updating EC2 Traffic Mirror Target (%s) tags: %s", d.Id(), err)
}
}

return resourceAwsEc2TrafficMirrorTargetRead(d, meta)
}

func resourceAwsEc2TrafficMirrorTargetRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

Expand Down Expand Up @@ -101,6 +123,10 @@ func resourceAwsEc2TrafficMirrorTargetRead(d *schema.ResourceData, meta interfac
d.Set("network_interface_id", target.NetworkInterfaceId)
d.Set("network_load_balancer_arn", target.NetworkLoadBalancerArn)

if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(target.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

return nil
}

Expand Down
Loading