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

resource/aws_vpn_connection: Refactor to use keyvaluetags package #11932

Merged
merged 1 commit into from
Mar 3, 2020
Merged
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
25 changes: 15 additions & 10 deletions aws/resource_aws_vpn_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"

"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

type XmlVpnConnectionConfig struct {
Expand Down Expand Up @@ -322,9 +322,10 @@ func resourceAwsVpnConnectionCreate(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("error waiting for VPN connection (%s) to become available: %s", d.Id(), err)
}

// Create tags.
if err := setTags(conn, d); err != nil {
return err
if v := d.Get("tags").(map[string]interface{}); len(v) > 0 {
if err := keyvaluetags.Ec2UpdateTags(conn, d.Id(), nil, v); err != nil {
return fmt.Errorf("error adding EC2 VPN Connection (%s) tags: %s", d.Id(), err)
}
}

// Read off the API to populate our RO fields.
Expand Down Expand Up @@ -430,7 +431,10 @@ func resourceAwsVpnConnectionRead(d *schema.ResourceData, meta interface{}) erro
d.Set("customer_gateway_id", vpnConnection.CustomerGatewayId)
d.Set("transit_gateway_id", vpnConnection.TransitGatewayId)
d.Set("type", vpnConnection.Type)
d.Set("tags", tagsToMap(vpnConnection.Tags))

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

if vpnConnection.Options != nil {
if err := d.Set("static_routes_only", vpnConnection.Options.StaticRoutesOnly); err != nil {
Expand Down Expand Up @@ -477,12 +481,13 @@ func resourceAwsVpnConnectionRead(d *schema.ResourceData, meta interface{}) erro
func resourceAwsVpnConnectionUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn

// Update tags if required.
if err := setTags(conn, d); err != nil {
return err
}
if d.HasChange("tags") {
o, n := d.GetChange("tags")

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

return resourceAwsVpnConnectionRead(d, meta)
}
Expand Down