Skip to content

Commit

Permalink
Merge pull request #7858 from ewbankkit/issue-7659
Browse files Browse the repository at this point in the history
 AWS AppMesh resource changes based on 2019/01/25 API version
  • Loading branch information
bflad authored Mar 15, 2019
2 parents 8bd377c + 6f9a3c2 commit 7870397
Show file tree
Hide file tree
Showing 42 changed files with 5,390 additions and 1,104 deletions.
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ func Provider() terraform.ResourceProvider {
"aws_appmesh_route": resourceAwsAppmeshRoute(),
"aws_appmesh_virtual_node": resourceAwsAppmeshVirtualNode(),
"aws_appmesh_virtual_router": resourceAwsAppmeshVirtualRouter(),
"aws_appmesh_virtual_service": resourceAwsAppmeshVirtualService(),
"aws_appsync_api_key": resourceAwsAppsyncApiKey(),
"aws_appsync_datasource": resourceAwsAppsyncDatasource(),
"aws_appsync_graphql_api": resourceAwsAppsyncGraphqlApi(),
Expand Down
16 changes: 8 additions & 8 deletions aws/resource_aws_appmesh_mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func resourceAwsAppmeshMeshRead(d *schema.ResourceData, meta interface{}) error
resp, err := conn.DescribeMesh(&appmesh.DescribeMeshInput{
MeshName: aws.String(d.Id()),
})
if isAWSErr(err, "NotFoundException", "") {
log.Printf("[WARN] App Mesh service mesh (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
if err != nil {
if isAWSErr(err, "NotFoundException", "") {
log.Printf("[WARN] App Mesh service mesh (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
return fmt.Errorf("error reading App Mesh service mesh: %s", err)
}
if aws.StringValue(resp.Mesh.Status.Status) == appmesh.MeshStatusCodeDeleted {
Expand All @@ -100,10 +100,10 @@ func resourceAwsAppmeshMeshDelete(d *schema.ResourceData, meta interface{}) erro
_, err := conn.DeleteMesh(&appmesh.DeleteMeshInput{
MeshName: aws.String(d.Id()),
})
if isAWSErr(err, "NotFoundException", "") {
return nil
}
if err != nil {
if isAWSErr(err, "NotFoundException", "") {
return nil
}
return fmt.Errorf("error deleting App Mesh service mesh: %s", err)
}

Expand Down
6 changes: 3 additions & 3 deletions aws/resource_aws_appmesh_mesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ func testAccCheckAppmeshMeshDestroy(s *terraform.State) error {
_, err := conn.DescribeMesh(&appmesh.DescribeMeshInput{
MeshName: aws.String(rs.Primary.Attributes["name"]),
})
if isAWSErr(err, "NotFoundException", "") {
continue
}
if err != nil {
if isAWSErr(err, "NotFoundException", "") {
return nil
}
return err
}
return fmt.Errorf("still exist.")
Expand Down
58 changes: 48 additions & 10 deletions aws/resource_aws_appmesh_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"regexp"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -20,6 +21,9 @@ func resourceAwsAppmeshRoute() *schema.Resource {
Read: resourceAwsAppmeshRouteRead,
Update: resourceAwsAppmeshRouteUpdate,
Delete: resourceAwsAppmeshRouteDelete,
Importer: &schema.ResourceImporter{
State: resourceAwsAppmeshRouteImport,
},

Schema: map[string]*schema.Schema{
"name": {
Expand Down Expand Up @@ -157,12 +161,12 @@ func resourceAwsAppmeshRouteRead(d *schema.ResourceData, meta interface{}) error
RouteName: aws.String(d.Get("name").(string)),
VirtualRouterName: aws.String(d.Get("virtual_router_name").(string)),
})
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
log.Printf("[WARN] App Mesh route (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
if err != nil {
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
log.Printf("[WARN] App Mesh route (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
return fmt.Errorf("error reading App Mesh route: %s", err)
}
if aws.StringValue(resp.Route.Status.Status) == appmesh.RouteStatusCodeDeleted {
Expand All @@ -177,8 +181,12 @@ func resourceAwsAppmeshRouteRead(d *schema.ResourceData, meta interface{}) error
d.Set("arn", resp.Route.Metadata.Arn)
d.Set("created_date", resp.Route.Metadata.CreatedAt.Format(time.RFC3339))
d.Set("last_updated_date", resp.Route.Metadata.LastUpdatedAt.Format(time.RFC3339))
err1 := d.Set("spec", flattenAppmeshRouteSpec(resp.Route.Spec))
return err1
err = d.Set("spec", flattenAppmeshRouteSpec(resp.Route.Spec))
if err != nil {
return fmt.Errorf("error setting spec: %s", err)
}

return nil
}

func resourceAwsAppmeshRouteUpdate(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -212,16 +220,46 @@ func resourceAwsAppmeshRouteDelete(d *schema.ResourceData, meta interface{}) err
RouteName: aws.String(d.Get("name").(string)),
VirtualRouterName: aws.String(d.Get("virtual_router_name").(string)),
})
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
return nil
}
if err != nil {
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
return nil
}
return fmt.Errorf("error deleting App Mesh route: %s", err)
}

return nil
}

func resourceAwsAppmeshRouteImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "/")
if len(parts) != 3 {
return []*schema.ResourceData{}, fmt.Errorf("Wrong format of resource: %s. Please follow 'mesh-name/virtual-router-name/route-name'", d.Id())
}

mesh := parts[0]
vrName := parts[1]
name := parts[2]
log.Printf("[DEBUG] Importing App Mesh route %s from mesh %s/virtual router %s ", name, mesh, vrName)

conn := meta.(*AWSClient).appmeshconn

resp, err := conn.DescribeRoute(&appmesh.DescribeRouteInput{
MeshName: aws.String(mesh),
RouteName: aws.String(name),
VirtualRouterName: aws.String(vrName),
})
if err != nil {
return nil, err
}

d.SetId(aws.StringValue(resp.Route.Metadata.Uid))
d.Set("name", resp.Route.RouteName)
d.Set("mesh_name", resp.Route.MeshName)
d.Set("virtual_router_name", resp.Route.VirtualRouterName)

return []*schema.ResourceData{d}, nil
}

func appmeshRouteWeightedTargetHash(v interface{}) int {
var buf bytes.Buffer
m := v.(map[string]interface{})
Expand Down
33 changes: 27 additions & 6 deletions aws/resource_aws_appmesh_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func testAccAwsAppmeshRoute_basic(t *testing.T) {
resourceName, "arn", regexp.MustCompile(fmt.Sprintf("^arn:[^:]+:appmesh:[^:]+:\\d{12}:mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName))),
),
},
{
ResourceName: resourceName,
ImportStateId: fmt.Sprintf("%s/%s/%s", meshName, vrName, rName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -230,10 +236,10 @@ func testAccCheckAppmeshRouteDestroy(s *terraform.State) error {
RouteName: aws.String(rs.Primary.Attributes["name"]),
VirtualRouterName: aws.String(rs.Primary.Attributes["virtual_router_name"]),
})
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
continue
}
if err != nil {
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
return nil
}
return err
}
return fmt.Errorf("still exist.")
Expand Down Expand Up @@ -280,7 +286,12 @@ resource "aws_appmesh_virtual_router" "foo" {
mesh_name = "${aws_appmesh_mesh.foo.id}"
spec {
service_names = ["serviceb.simpleapp.local"]
listener {
port_mapping {
port = 8080
protocol = "http"
}
}
}
}
Expand All @@ -305,7 +316,12 @@ resource "aws_appmesh_virtual_router" "foo" {
mesh_name = "${aws_appmesh_mesh.foo.id}"
spec {
service_names = ["serviceb.simpleapp.local"]
listener {
port_mapping {
port = 8080
protocol = "http"
}
}
}
}
Expand Down Expand Up @@ -357,7 +373,12 @@ resource "aws_appmesh_virtual_router" "foo" {
mesh_name = "${aws_appmesh_mesh.foo.id}"
spec {
service_names = ["serviceb.simpleapp.local"]
listener {
port_mapping {
port = 8080
protocol = "http"
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions aws/resource_aws_appmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TestAccAWSAppmesh(t *testing.T) {
"VirtualRouter": {
"basic": testAccAwsAppmeshVirtualRouter_basic,
},
"VirtualService": {
"virtualNode": testAccAwsAppmeshVirtualService_virtualNode,
"virtualRouter": testAccAwsAppmeshVirtualService_virtualRouter,
},
}

for group, m := range testCases {
Expand Down
Loading

0 comments on commit 7870397

Please sign in to comment.