Skip to content

Commit

Permalink
r/aws_appmesh_route: 'appmesh' -> 'appmeshpreview'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kit Ewbank authored and Kit Ewbank committed Jul 23, 2019
1 parent 5cffd04 commit 69f78ad
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 63 deletions.
90 changes: 45 additions & 45 deletions aws/resource_aws_appmesh_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appmesh"
"github.com/aws/aws-sdk-go/service/appmeshpreview"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand Down Expand Up @@ -182,14 +182,14 @@ func resourceAwsAppmeshRoute() *schema.Resource {
}

func resourceAwsAppmeshRouteCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).appmeshconn
conn := meta.(*AWSClient).appmeshpreviewconn

req := &appmesh.CreateRouteInput{
req := &appmeshpreview.CreateRouteInput{
MeshName: aws.String(d.Get("mesh_name").(string)),
RouteName: aws.String(d.Get("name").(string)),
VirtualRouterName: aws.String(d.Get("virtual_router_name").(string)),
Spec: expandAppmeshRouteSpec(d.Get("spec").([]interface{})),
Tags: tagsFromMapAppmesh(d.Get("tags").(map[string]interface{})),
// Tags: tagsFromMapAppmesh(d.Get("tags").(map[string]interface{})),
}

log.Printf("[DEBUG] Creating App Mesh route: %#v", req)
Expand All @@ -204,22 +204,22 @@ func resourceAwsAppmeshRouteCreate(d *schema.ResourceData, meta interface{}) err
}

func resourceAwsAppmeshRouteRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).appmeshconn
conn := meta.(*AWSClient).appmeshpreviewconn

resp, err := conn.DescribeRoute(&appmesh.DescribeRouteInput{
resp, err := conn.DescribeRoute(&appmeshpreview.DescribeRouteInput{
MeshName: aws.String(d.Get("mesh_name").(string)),
RouteName: aws.String(d.Get("name").(string)),
VirtualRouterName: aws.String(d.Get("virtual_router_name").(string)),
})
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
if isAWSErr(err, appmeshpreview.ErrCodeNotFoundException, "") {
log.Printf("[WARN] App Mesh route (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
if err != nil {
return fmt.Errorf("error reading App Mesh route: %s", err)
}
if aws.StringValue(resp.Route.Status.Status) == appmesh.RouteStatusCodeDeleted {
if aws.StringValue(resp.Route.Status.Status) == appmeshpreview.RouteStatusCodeDeleted {
log.Printf("[WARN] App Mesh route (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
Expand All @@ -236,25 +236,25 @@ func resourceAwsAppmeshRouteRead(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("error setting spec: %s", err)
}

err = saveTagsAppmesh(conn, d, aws.StringValue(resp.Route.Metadata.Arn))
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 {
return fmt.Errorf("error saving tags: %s", err)
}
// err = saveTagsAppmesh(conn, d, aws.StringValue(resp.Route.Metadata.Arn))
// if isAWSErr(err, appmeshpreview.ErrCodeNotFoundException, "") {
// log.Printf("[WARN] App Mesh route (%s) not found, removing from state", d.Id())
// d.SetId("")
// return nil
// }
// if err != nil {
// return fmt.Errorf("error saving tags: %s", err)
// }

return nil
}

func resourceAwsAppmeshRouteUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).appmeshconn
conn := meta.(*AWSClient).appmeshpreviewconn

if d.HasChange("spec") {
_, v := d.GetChange("spec")
req := &appmesh.UpdateRouteInput{
req := &appmeshpreview.UpdateRouteInput{
MeshName: aws.String(d.Get("mesh_name").(string)),
RouteName: aws.String(d.Get("name").(string)),
VirtualRouterName: aws.String(d.Get("virtual_router_name").(string)),
Expand All @@ -268,29 +268,29 @@ func resourceAwsAppmeshRouteUpdate(d *schema.ResourceData, meta interface{}) err
}
}

err := setTagsAppmesh(conn, d, d.Get("arn").(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 {
return fmt.Errorf("error setting tags: %s", err)
}
// err := setTagsAppmesh(conn, d, d.Get("arn").(string))
// if isAWSErr(err, appmeshpreview.ErrCodeNotFoundException, "") {
// log.Printf("[WARN] App Mesh route (%s) not found, removing from state", d.Id())
// d.SetId("")
// return nil
// }
// if err != nil {
// return fmt.Errorf("error setting tags: %s", err)
// }

return resourceAwsAppmeshRouteRead(d, meta)
}

func resourceAwsAppmeshRouteDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).appmeshconn
conn := meta.(*AWSClient).appmeshpreviewconn

log.Printf("[DEBUG] Deleting App Mesh route: %s", d.Id())
_, err := conn.DeleteRoute(&appmesh.DeleteRouteInput{
_, err := conn.DeleteRoute(&appmeshpreview.DeleteRouteInput{
MeshName: aws.String(d.Get("mesh_name").(string)),
RouteName: aws.String(d.Get("name").(string)),
VirtualRouterName: aws.String(d.Get("virtual_router_name").(string)),
})
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
if isAWSErr(err, appmeshpreview.ErrCodeNotFoundException, "") {
return nil
}
if err != nil {
Expand All @@ -311,9 +311,9 @@ func resourceAwsAppmeshRouteImport(d *schema.ResourceData, meta interface{}) ([]
name := parts[2]
log.Printf("[DEBUG] Importing App Mesh route %s from mesh %s/virtual router %s ", name, mesh, vrName)

conn := meta.(*AWSClient).appmeshconn
conn := meta.(*AWSClient).appmeshpreviewconn

resp, err := conn.DescribeRoute(&appmesh.DescribeRouteInput{
resp, err := conn.DescribeRoute(&appmeshpreview.DescribeRouteInput{
MeshName: aws.String(mesh),
RouteName: aws.String(name),
VirtualRouterName: aws.String(vrName),
Expand All @@ -330,8 +330,8 @@ func resourceAwsAppmeshRouteImport(d *schema.ResourceData, meta interface{}) ([]
return []*schema.ResourceData{d}, nil
}

func expandAppmeshRouteSpec(vSpec []interface{}) *appmesh.RouteSpec {
spec := &appmesh.RouteSpec{}
func expandAppmeshRouteSpec(vSpec []interface{}) *appmeshpreview.RouteSpec {
spec := &appmeshpreview.RouteSpec{}

if len(vSpec) == 0 || vSpec[0] == nil {
// Empty Spec is allowed.
Expand All @@ -342,16 +342,16 @@ func expandAppmeshRouteSpec(vSpec []interface{}) *appmesh.RouteSpec {
if vHttpRoute, ok := mSpec["http_route"].([]interface{}); ok && len(vHttpRoute) > 0 && vHttpRoute[0] != nil {
mHttpRoute := vHttpRoute[0].(map[string]interface{})

spec.HttpRoute = &appmesh.HttpRoute{}
spec.HttpRoute = &appmeshpreview.HttpRoute{}

if vHttpRouteAction, ok := mHttpRoute["action"].([]interface{}); ok && len(vHttpRouteAction) > 0 && vHttpRouteAction[0] != nil {
mHttpRouteAction := vHttpRouteAction[0].(map[string]interface{})

if vWeightedTargets, ok := mHttpRouteAction["weighted_target"].(*schema.Set); ok && vWeightedTargets.Len() > 0 {
weightedTargets := []*appmesh.WeightedTarget{}
weightedTargets := []*appmeshpreview.WeightedTarget{}

for _, vWeightedTarget := range vWeightedTargets.List() {
weightedTarget := &appmesh.WeightedTarget{}
weightedTarget := &appmeshpreview.WeightedTarget{}

mWeightedTarget := vWeightedTarget.(map[string]interface{})

Expand All @@ -365,7 +365,7 @@ func expandAppmeshRouteSpec(vSpec []interface{}) *appmesh.RouteSpec {
weightedTargets = append(weightedTargets, weightedTarget)
}

spec.HttpRoute.Action = &appmesh.HttpRouteAction{
spec.HttpRoute.Action = &appmeshpreview.HttpRouteAction{
WeightedTargets: weightedTargets,
}
}
Expand All @@ -375,7 +375,7 @@ func expandAppmeshRouteSpec(vSpec []interface{}) *appmesh.RouteSpec {
mHttpRouteMatch := vHttpRouteMatch[0].(map[string]interface{})

if vPrefix, ok := mHttpRouteMatch["prefix"].(string); ok && vPrefix != "" {
spec.HttpRoute.Match = &appmesh.HttpRouteMatch{
spec.HttpRoute.Match = &appmeshpreview.HttpRouteMatch{
Prefix: aws.String(vPrefix),
}
}
Expand All @@ -385,16 +385,16 @@ func expandAppmeshRouteSpec(vSpec []interface{}) *appmesh.RouteSpec {
if vTcpRoute, ok := mSpec["tcp_route"].([]interface{}); ok && len(vTcpRoute) > 0 && vTcpRoute[0] != nil {
mTcpRoute := vTcpRoute[0].(map[string]interface{})

spec.TcpRoute = &appmesh.TcpRoute{}
spec.TcpRoute = &appmeshpreview.TcpRoute{}

if vTcpRouteAction, ok := mTcpRoute["action"].([]interface{}); ok && len(vTcpRouteAction) > 0 && vTcpRouteAction[0] != nil {
mTcpRouteAction := vTcpRouteAction[0].(map[string]interface{})

if vWeightedTargets, ok := mTcpRouteAction["weighted_target"].(*schema.Set); ok && vWeightedTargets.Len() > 0 {
weightedTargets := []*appmesh.WeightedTarget{}
weightedTargets := []*appmeshpreview.WeightedTarget{}

for _, vWeightedTarget := range vWeightedTargets.List() {
weightedTarget := &appmesh.WeightedTarget{}
weightedTarget := &appmeshpreview.WeightedTarget{}

mWeightedTarget := vWeightedTarget.(map[string]interface{})

Expand All @@ -408,7 +408,7 @@ func expandAppmeshRouteSpec(vSpec []interface{}) *appmesh.RouteSpec {
weightedTargets = append(weightedTargets, weightedTarget)
}

spec.TcpRoute.Action = &appmesh.TcpRouteAction{
spec.TcpRoute.Action = &appmeshpreview.TcpRouteAction{
WeightedTargets: weightedTargets,
}
}
Expand All @@ -418,7 +418,7 @@ func expandAppmeshRouteSpec(vSpec []interface{}) *appmesh.RouteSpec {
return spec
}

func flattenAppmeshRouteSpec(spec *appmesh.RouteSpec) []interface{} {
func flattenAppmeshRouteSpec(spec *appmeshpreview.RouteSpec) []interface{} {
if spec == nil {
return []interface{}{}
}
Expand Down
34 changes: 17 additions & 17 deletions aws/resource_aws_appmesh_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appmesh"
"github.com/aws/aws-sdk-go/service/appmeshpreview"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
Expand All @@ -25,38 +25,38 @@ func testSweepAppmeshRoutes(region string) error {
if err != nil {
return fmt.Errorf("error getting client: %s", err)
}
conn := client.(*AWSClient).appmeshconn
conn := client.(*AWSClient).appmeshpreviewconn

err = conn.ListMeshesPages(&appmesh.ListMeshesInput{}, func(page *appmesh.ListMeshesOutput, isLast bool) bool {
err = conn.ListMeshesPages(&appmeshpreview.ListMeshesInput{}, func(page *appmeshpreview.ListMeshesOutput, isLast bool) bool {
if page == nil {
return !isLast
}

for _, mesh := range page.Meshes {
listVirtualRoutersInput := &appmesh.ListVirtualRoutersInput{
listVirtualRoutersInput := &appmeshpreview.ListVirtualRoutersInput{
MeshName: mesh.MeshName,
}
meshName := aws.StringValue(mesh.MeshName)

err := conn.ListVirtualRoutersPages(listVirtualRoutersInput, func(page *appmesh.ListVirtualRoutersOutput, isLast bool) bool {
err := conn.ListVirtualRoutersPages(listVirtualRoutersInput, func(page *appmeshpreview.ListVirtualRoutersOutput, isLast bool) bool {
if page == nil {
return !isLast
}

for _, virtualRouter := range page.VirtualRouters {
listRoutesInput := &appmesh.ListRoutesInput{
listRoutesInput := &appmeshpreview.ListRoutesInput{
MeshName: mesh.MeshName,
VirtualRouterName: virtualRouter.VirtualRouterName,
}
virtualRouterName := aws.StringValue(virtualRouter.VirtualRouterName)

err := conn.ListRoutesPages(listRoutesInput, func(page *appmesh.ListRoutesOutput, isLast bool) bool {
err := conn.ListRoutesPages(listRoutesInput, func(page *appmeshpreview.ListRoutesOutput, isLast bool) bool {
if page == nil {
return !isLast
}

for _, route := range page.Routes {
input := &appmesh.DeleteRouteInput{
input := &appmeshpreview.DeleteRouteInput{
MeshName: mesh.MeshName,
RouteName: route.RouteName,
VirtualRouterName: virtualRouter.VirtualRouterName,
Expand Down Expand Up @@ -101,7 +101,7 @@ func testSweepAppmeshRoutes(region string) error {
}

func testAccAwsAppmeshRoute_httpRoute(t *testing.T) {
var r appmesh.RouteData
var r appmeshpreview.RouteData
resourceName := "aws_appmesh_route.foo"
meshName := fmt.Sprintf("tf-test-mesh-%d", acctest.RandInt())
vrName := fmt.Sprintf("tf-test-router-%d", acctest.RandInt())
Expand Down Expand Up @@ -161,7 +161,7 @@ func testAccAwsAppmeshRoute_httpRoute(t *testing.T) {
}

func testAccAwsAppmeshRoute_tcpRoute(t *testing.T) {
var r appmesh.RouteData
var r appmeshpreview.RouteData
resourceName := "aws_appmesh_route.foo"
meshName := fmt.Sprintf("tf-test-mesh-%d", acctest.RandInt())
vrName := fmt.Sprintf("tf-test-router-%d", acctest.RandInt())
Expand Down Expand Up @@ -217,7 +217,7 @@ func testAccAwsAppmeshRoute_tcpRoute(t *testing.T) {
}

func testAccAwsAppmeshRoute_tags(t *testing.T) {
var r appmesh.RouteData
var r appmeshpreview.RouteData
resourceName := "aws_appmesh_route.foo"
meshName := fmt.Sprintf("tf-test-mesh-%d", acctest.RandInt())
vrName := fmt.Sprintf("tf-test-router-%d", acctest.RandInt())
Expand Down Expand Up @@ -273,19 +273,19 @@ func testAccAwsAppmeshRoute_tags(t *testing.T) {
}

func testAccCheckAppmeshRouteDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).appmeshconn
conn := testAccProvider.Meta().(*AWSClient).appmeshpreviewconn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_appmesh_route" {
continue
}

_, err := conn.DescribeRoute(&appmesh.DescribeRouteInput{
_, err := conn.DescribeRoute(&appmeshpreview.DescribeRouteInput{
MeshName: aws.String(rs.Primary.Attributes["mesh_name"]),
RouteName: aws.String(rs.Primary.Attributes["name"]),
VirtualRouterName: aws.String(rs.Primary.Attributes["virtual_router_name"]),
})
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
if isAWSErr(err, appmeshpreview.ErrCodeNotFoundException, "") {
continue
}
if err != nil {
Expand All @@ -297,9 +297,9 @@ func testAccCheckAppmeshRouteDestroy(s *terraform.State) error {
return nil
}

func testAccCheckAppmeshRouteExists(name string, v *appmesh.RouteData) resource.TestCheckFunc {
func testAccCheckAppmeshRouteExists(name string, v *appmeshpreview.RouteData) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).appmeshconn
conn := testAccProvider.Meta().(*AWSClient).appmeshpreviewconn

rs, ok := s.RootModule().Resources[name]
if !ok {
Expand All @@ -309,7 +309,7 @@ func testAccCheckAppmeshRouteExists(name string, v *appmesh.RouteData) resource.
return fmt.Errorf("No ID is set")
}

resp, err := conn.DescribeRoute(&appmesh.DescribeRouteInput{
resp, err := conn.DescribeRoute(&appmeshpreview.DescribeRouteInput{
MeshName: aws.String(rs.Primary.Attributes["mesh_name"]),
RouteName: aws.String(rs.Primary.Attributes["name"]),
VirtualRouterName: aws.String(rs.Primary.Attributes["virtual_router_name"]),
Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_appmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAccAWSAppmesh(t *testing.T) {
"Route": {
"httpRoute": testAccAwsAppmeshRoute_httpRoute,
"tcpRoute": testAccAwsAppmeshRoute_tcpRoute,
"tags": testAccAwsAppmeshRoute_tags,
// "tags": testAccAwsAppmeshRoute_tags,
},
"VirtualNode": {
"basic": testAccAwsAppmeshVirtualNode_basic,
Expand Down

0 comments on commit 69f78ad

Please sign in to comment.