Skip to content

Commit

Permalink
service/ec2: Refactor VPC Endpoint (Service) data sources and resourc…
Browse files Browse the repository at this point in the history
…e to use keyvaluetags package (#11931)

Reference: #10688

Output from acceptance testing:

```
--- PASS: TestAccAWSVpcEndpointService_removed (402.00s)
--- PASS: TestAccAWSVpcEndpointService_basic (496.96s)
--- PASS: TestAccAWSVpcEndpointService_AllowedPrincipalsAndTags (552.52s)

--- PASS: TestAccDataSourceAwsVpcEndpoint_byId (42.27s)
--- PASS: TestAccDataSourceAwsVpcEndpoint_byFilter (42.46s)
--- PASS: TestAccDataSourceAwsVpcEndpoint_gatewayBasic (42.52s)
--- PASS: TestAccDataSourceAwsVpcEndpoint_byTags (47.33s)
--- PASS: TestAccDataSourceAwsVpcEndpoint_gatewayWithRouteTableAndTags (53.17s)
--- PASS: TestAccDataSourceAwsVpcEndpoint_interface (198.80s)

--- PASS: TestAccDataSourceAwsVpcEndpointService_interface (15.12s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_gateway (15.52s)
--- PASS: TestAccDataSourceAwsVpcEndpointService_custom (275.50s)
```
  • Loading branch information
bflad authored Mar 3, 2020
1 parent 506c9ba commit c516dcd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions aws/data_source_aws_vpc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/structure"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func dataSourceAwsVpcEndpoint() *schema.Resource {
Expand Down Expand Up @@ -127,7 +128,7 @@ func dataSourceAwsVpcEndpointRead(d *schema.ResourceData, meta interface{}) erro
},
)
req.Filters = append(req.Filters, buildEC2TagFilterList(
tagsFromMap(d.Get("tags").(map[string]interface{})),
keyvaluetags.New(d.Get("tags").(map[string]interface{})).Ec2Tags(),
)...)
req.Filters = append(req.Filters, buildEC2CustomFilterList(
d.Get("filter").(*schema.Set),
Expand Down Expand Up @@ -207,7 +208,7 @@ func dataSourceAwsVpcEndpointRead(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return fmt.Errorf("error setting subnet_ids: %s", err)
}
err = d.Set("tags", tagsToMap(vpce.Tags))
err = d.Set("tags", keyvaluetags.Ec2KeyValueTags(vpce.Tags).IgnoreAws().Map())
if err != nil {
return fmt.Errorf("error setting tags: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion aws/data_source_aws_vpc_endpoint_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/helper/hashcode"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func dataSourceAwsVpcEndpointService() *schema.Resource {
Expand Down Expand Up @@ -137,7 +138,7 @@ func dataSourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{
d.Set("private_dns_name", sd.PrivateDnsName)
d.Set("service_id", sd.ServiceId)
d.Set("service_type", sd.ServiceType[0].ServiceType)
err = d.Set("tags", tagsToMap(sd.Tags))
err = d.Set("tags", keyvaluetags.Ec2KeyValueTags(sd.Tags).IgnoreAws().Map())
if err != nil {
return fmt.Errorf("error setting tags: %s", err)
}
Expand Down
12 changes: 8 additions & 4 deletions aws/resource_aws_vpc_endpoint_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"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"
)

func resourceAwsVpcEndpointService() *schema.Resource {
Expand Down Expand Up @@ -139,7 +140,7 @@ func resourceAwsVpcEndpointServiceRead(d *schema.ResourceData, meta interface{})
d.Set("service_name", svcCfg.ServiceName)
d.Set("service_type", svcCfg.ServiceType[0].ServiceType)
d.Set("state", svcCfg.ServiceState)
err = d.Set("tags", tagsToMap(svcCfg.Tags))
err = d.Set("tags", keyvaluetags.Ec2KeyValueTags(svcCfg.Tags).IgnoreAws().Map())
if err != nil {
return fmt.Errorf("error setting tags: %s", err)
}
Expand Down Expand Up @@ -202,10 +203,13 @@ func resourceAwsVpcEndpointServiceUpdate(d *schema.ResourceData, meta interface{
d.SetPartial("allowed_principals")
}

if err := setTags(conn, d); err != nil {
return err
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 VPC Endpoint Service (%s) tags: %s", d.Id(), err)
}
}
d.SetPartial("tags")

d.Partial(false)
return resourceAwsVpcEndpointServiceRead(d, meta)
Expand Down

0 comments on commit c516dcd

Please sign in to comment.