Skip to content

Commit

Permalink
Merge pull request #37042 from ph-l/f-aws_appmesh-mesh-service-discovery
Browse files Browse the repository at this point in the history
Add MeshServiceDiscovery to MeshSpec in App Mesh
  • Loading branch information
ewbankkit authored Apr 24, 2024
2 parents 80ae7b1 + 33ac30f commit 1180ab8
Show file tree
Hide file tree
Showing 23 changed files with 735 additions and 581 deletions.
3 changes: 3 additions & 0 deletions .changelog/37042.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_appmesh_mesh: Add `spec.service_discovery` argument
```
1 change: 1 addition & 0 deletions internal/service/appmesh/appmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestAccAppMesh_serial(t *testing.T) {
"basic": testAccMesh_basic,
"disappears": testAccMesh_disappears,
"egressFilter": testAccMesh_egressFilter,
"serviceDiscovery": testAccMesh_serviceDiscovery,
"tags": testAccMesh_tags,
"dataSourceBasic": testAccMeshDataSource_basic,
"dataSourceMeshOwner": testAccMeshDataSource_meshOwner,
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions internal/service/appmesh/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package appmesh

// Exports for use in tests only.
var (
ResourceGatewayRoute = resourceGatewayRoute
ResourceMesh = resourceMesh
ResourceRoute = resourceRoute
ResourceVirtualGateway = resourceVirtualGateway
ResourceVirtualNode = resourceVirtualNode
ResourceVirtualRouter = resourceVirtualRouter
ResourceVirtualService = resourceVirtualService

FindGatewayRouteByFourPartKey = findGatewayRouteByFourPartKey
FindMeshByTwoPartKey = findMeshByTwoPartKey
FindRouteByFourPartKey = findRouteByFourPartKey
FindVirtualGatewayByThreePartKey = findVirtualGatewayByThreePartKey
FindVirtualNodeByThreePartKey = findVirtualNodeByThreePartKey
FindVirtualRouterByThreePartKey = findVirtualRouterByThreePartKey
FindVirtualServiceByThreePartKey = findVirtualServiceByThreePartKey
)
18 changes: 18 additions & 0 deletions internal/service/appmesh/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,16 @@ func expandMeshSpec(vSpec []interface{}) *appmesh.MeshSpec {
}
}

if vServiceDiscovery, ok := mSpec["service_discovery"].([]interface{}); ok && len(vServiceDiscovery) > 0 && vServiceDiscovery[0] != nil {
mServiceDiscovery := vServiceDiscovery[0].(map[string]interface{})

if vIpPreference, ok := mServiceDiscovery["ip_preference"].(string); ok && vIpPreference != "" {
spec.ServiceDiscovery = &appmesh.MeshServiceDiscovery{
IpPreference: aws.String(vIpPreference),
}
}
}

return spec
}

Expand Down Expand Up @@ -1545,6 +1555,14 @@ func flattenMeshSpec(spec *appmesh.MeshSpec) []interface{} {
}
}

if spec.ServiceDiscovery != nil {
mSpec["service_discovery"] = []interface{}{
map[string]interface{}{
"ip_preference": aws.StringValue(spec.ServiceDiscovery.IpPreference),
},
}
}

return []interface{}{mSpec}
}

Expand Down
100 changes: 51 additions & 49 deletions internal/service/appmesh/gateway_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// @SDKResource("aws_appmesh_gateway_route", name="Gateway Route")
// @Tags(identifierAttribute="arn")
func ResourceGatewayRoute() *schema.Resource {
func resourceGatewayRoute() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceGatewayRouteCreate,
ReadWithoutTimeout: resourceGatewayRouteRead,
Expand All @@ -39,51 +39,53 @@ func ResourceGatewayRoute() *schema.Resource {
StateContext: resourceGatewayRouteImport,
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"created_date": {
Type: schema.TypeString,
Computed: true,
},
"last_updated_date": {
Type: schema.TypeString,
Computed: true,
},
"mesh_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
"mesh_owner": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: verify.ValidAccountID,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
"resource_owner": {
Type: schema.TypeString,
Computed: true,
},
"spec": resourceGatewayRouteSpecSchema(),
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"virtual_gateway_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"created_date": {
Type: schema.TypeString,
Computed: true,
},
"last_updated_date": {
Type: schema.TypeString,
Computed: true,
},
"mesh_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
"mesh_owner": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: verify.ValidAccountID,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
"resource_owner": {
Type: schema.TypeString,
Computed: true,
},
"spec": resourceGatewayRouteSpecSchema(),
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"virtual_gateway_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
}
},

CustomizeDiff: verify.SetTagsDiff,
Expand Down Expand Up @@ -536,7 +538,7 @@ func resourceGatewayRouteRead(ctx context.Context, d *schema.ResourceData, meta
conn := meta.(*conns.AWSClient).AppMeshConn(ctx)

outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (interface{}, error) {
return FindGatewayRouteByFourPartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get("virtual_gateway_name").(string), d.Get("name").(string))
return findGatewayRouteByFourPartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get("virtual_gateway_name").(string), d.Get("name").(string))
}, d.IsNewResource())

if !d.IsNewResource() && tfresource.NotFound(err) {
Expand Down Expand Up @@ -632,7 +634,7 @@ func resourceGatewayRouteImport(ctx context.Context, d *schema.ResourceData, met
virtualGatewayName := parts[1]
name := parts[2]

gatewayRoute, err := FindGatewayRouteByFourPartKey(ctx, conn, meshName, "", virtualGatewayName, name)
gatewayRoute, err := findGatewayRouteByFourPartKey(ctx, conn, meshName, "", virtualGatewayName, name)

if err != nil {
return nil, err
Expand All @@ -646,7 +648,7 @@ func resourceGatewayRouteImport(ctx context.Context, d *schema.ResourceData, met
return []*schema.ResourceData{d}, nil
}

func FindGatewayRouteByFourPartKey(ctx context.Context, conn *appmesh.AppMesh, meshName, meshOwner, virtualGatewayName, name string) (*appmesh.GatewayRouteData, error) {
func findGatewayRouteByFourPartKey(ctx context.Context, conn *appmesh.AppMesh, meshName, meshOwner, virtualGatewayName, name string) (*appmesh.GatewayRouteData, error) {
input := &appmesh.DescribeGatewayRouteInput{
GatewayRouteName: aws.String(name),
MeshName: aws.String(meshName),
Expand Down
80 changes: 41 additions & 39 deletions internal/service/appmesh/gateway_route_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,49 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKDataSource("aws_appmesh_gateway_route")
func DataSourceGatewayRoute() *schema.Resource {
// @SDKDataSource("aws_appmesh_gateway_route", name="Gateway Route")
func dataSourceGatewayRoute() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: dataSourceGatewayRouteRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"created_date": {
Type: schema.TypeString,
Computed: true,
},
"last_updated_date": {
Type: schema.TypeString,
Computed: true,
},
"mesh_name": {
Type: schema.TypeString,
Required: true,
},
"mesh_owner": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"resource_owner": {
Type: schema.TypeString,
Computed: true,
},
"spec": sdkv2.DataSourcePropertyFromResourceProperty(resourceGatewayRouteSpecSchema()),
names.AttrTags: tftags.TagsSchemaComputed(),
"virtual_gateway_name": {
Type: schema.TypeString,
Required: true,
},
SchemaFunc: func() map[string]*schema.Schema {
return map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"created_date": {
Type: schema.TypeString,
Computed: true,
},
"last_updated_date": {
Type: schema.TypeString,
Computed: true,
},
"mesh_name": {
Type: schema.TypeString,
Required: true,
},
"mesh_owner": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"resource_owner": {
Type: schema.TypeString,
Computed: true,
},
"spec": sdkv2.DataSourcePropertyFromResourceProperty(resourceGatewayRouteSpecSchema()),
names.AttrTags: tftags.TagsSchemaComputed(),
"virtual_gateway_name": {
Type: schema.TypeString,
Required: true,
},
}
},
}
}
Expand All @@ -68,7 +70,7 @@ func dataSourceGatewayRouteRead(ctx context.Context, d *schema.ResourceData, met
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

gatewayRouteName := d.Get("name").(string)
gatewayRoute, err := FindGatewayRouteByFourPartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get("virtual_gateway_name").(string), gatewayRouteName)
gatewayRoute, err := findGatewayRouteByFourPartKey(ctx, conn, d.Get("mesh_name").(string), d.Get("mesh_owner").(string), d.Get("virtual_gateway_name").(string), gatewayRouteName)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading App Mesh Gateway Route (%s): %s", gatewayRouteName, err)
Expand Down
Loading

0 comments on commit 1180ab8

Please sign in to comment.