Skip to content

Commit

Permalink
service/appmesh: Add 'mesh_owner' and 'resource_owner' attributes in …
Browse files Browse the repository at this point in the history
…support of cross-account AppMesh mesh sharing (#14349)

* r/aws_appmesh_route: Add 'mesh_owner' and 'resource_owner' attributes in support of cross-account mesh sharing.

Acceptance test output:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/Route'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSAppmesh/Route -timeout 120m
=== RUN   TestAccAWSAppmesh_serial
=== RUN   TestAccAWSAppmesh_serial/Route
=== RUN   TestAccAWSAppmesh_serial/Route/httpHeader
=== RUN   TestAccAWSAppmesh_serial/Route/httpRoute
=== RUN   TestAccAWSAppmesh_serial/Route/tcpRoute
=== RUN   TestAccAWSAppmesh_serial/Route/routePriority
=== RUN   TestAccAWSAppmesh_serial/Route/tags
=== RUN   TestAccAWSAppmesh_serial/VirtualRouter
=== RUN   TestAccAWSAppmesh_serial/VirtualRouter/basic
=== RUN   TestAccAWSAppmesh_serial/VirtualRouter/tags
--- PASS: TestAccAWSAppmesh_serial (223.84s)
    --- PASS: TestAccAWSAppmesh_serial/Route (169.52s)
        --- PASS: TestAccAWSAppmesh_serial/Route/httpHeader (27.91s)
        --- PASS: TestAccAWSAppmesh_serial/Route/httpRoute (37.76s)
        --- PASS: TestAccAWSAppmesh_serial/Route/tcpRoute (37.54s)
        --- PASS: TestAccAWSAppmesh_serial/Route/routePriority (27.71s)
        --- PASS: TestAccAWSAppmesh_serial/Route/tags (38.61s)
    --- PASS: TestAccAWSAppmesh_serial/VirtualRouter (54.32s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualRouter/basic (22.79s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualRouter/tags (31.53s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	223.931s

* r/aws_appmesh_virtual_node: Add 'mesh_owner' and 'resource_owner' attributes in support of cross-account mesh sharing.

Acceptance test output:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/VirtualNode'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSAppmesh/VirtualNode -timeout 120m
=== RUN   TestAccAWSAppmesh_serial
=== RUN   TestAccAWSAppmesh_serial/VirtualNode
=== RUN   TestAccAWSAppmesh_serial/VirtualNode/logging
=== RUN   TestAccAWSAppmesh_serial/VirtualNode/tags
=== RUN   TestAccAWSAppmesh_serial/VirtualNode/basic
=== RUN   TestAccAWSAppmesh_serial/VirtualNode/cloudMapServiceDiscovery
=== RUN   TestAccAWSAppmesh_serial/VirtualNode/listenerHealthChecks
--- PASS: TestAccAWSAppmesh_serial (189.22s)
    --- PASS: TestAccAWSAppmesh_serial/VirtualNode (189.22s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualNode/logging (23.33s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualNode/tags (33.05s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualNode/basic (14.57s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualNode/cloudMapServiceDiscovery (95.31s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualNode/listenerHealthChecks (22.95s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	189.280s

* r/aws_appmesh_virtual_router: Add 'mesh_owner' and 'resource_owner' attributes in support of cross-account mesh sharing.

Acceptance test output:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/VirtualRouter'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSAppmesh/VirtualRouter -timeout 120m
=== RUN   TestAccAWSAppmesh_serial
=== RUN   TestAccAWSAppmesh_serial/VirtualRouter
=== RUN   TestAccAWSAppmesh_serial/VirtualRouter/basic
=== RUN   TestAccAWSAppmesh_serial/VirtualRouter/tags
--- PASS: TestAccAWSAppmesh_serial (53.74s)
    --- PASS: TestAccAWSAppmesh_serial/VirtualRouter (53.74s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualRouter/basic (22.57s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualRouter/tags (31.18s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	53.793s

* r/aws_appmesh_virtual_service: Add 'mesh_owner' and 'resource_owner' attributes in support of cross-account mesh sharing.

Acceptance test output:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/VirtualService'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSAppmesh/VirtualService -timeout 120m
=== RUN   TestAccAWSAppmesh_serial
=== RUN   TestAccAWSAppmesh_serial/VirtualService
=== RUN   TestAccAWSAppmesh_serial/VirtualService/virtualNode
=== RUN   TestAccAWSAppmesh_serial/VirtualService/virtualRouter
=== RUN   TestAccAWSAppmesh_serial/VirtualService/tags
--- PASS: TestAccAWSAppmesh_serial (90.76s)
    --- PASS: TestAccAWSAppmesh_serial/VirtualService (90.76s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualService/virtualNode (27.38s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualService/virtualRouter (25.29s)
        --- PASS: TestAccAWSAppmesh_serial/VirtualService/tags (38.08s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	90.827s

* r/aws_appmesh_mesh: Add 'mesh_owner' and 'resource_owner' attributes in support of cross-account mesh sharing.

Acceptance test output:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSAppmesh/Mesh'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSAppmesh/Mesh -timeout 120m
=== RUN   TestAccAWSAppmesh_serial
=== RUN   TestAccAWSAppmesh_serial/Mesh
=== RUN   TestAccAWSAppmesh_serial/Mesh/tags
=== RUN   TestAccAWSAppmesh_serial/Mesh/basic
=== RUN   TestAccAWSAppmesh_serial/Mesh/egressFilter
--- PASS: TestAccAWSAppmesh_serial (58.23s)
    --- PASS: TestAccAWSAppmesh_serial/Mesh (58.23s)
        --- PASS: TestAccAWSAppmesh_serial/Mesh/tags (25.62s)
        --- PASS: TestAccAWSAppmesh_serial/Mesh/basic (10.61s)
        --- PASS: TestAccAWSAppmesh_serial/Mesh/egressFilter (21.99s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	58.329s
  • Loading branch information
ewbankkit authored Sep 23, 2020
1 parent d5900d5 commit 9efb631
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 48 deletions.
21 changes: 19 additions & 2 deletions aws/resource_aws_appmesh_mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ func resourceAwsAppmeshMesh() *schema.Resource {
Computed: true,
},

"mesh_owner": {
Type: schema.TypeString,
Computed: true,
},

"resource_owner": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsSchema(),
},
}
Expand Down Expand Up @@ -106,9 +116,14 @@ func resourceAwsAppmeshMeshRead(d *schema.ResourceData, meta interface{}) error
conn := meta.(*AWSClient).appmeshconn
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

resp, err := conn.DescribeMesh(&appmesh.DescribeMeshInput{
req := &appmesh.DescribeMeshInput{
MeshName: aws.String(d.Id()),
})
}
if v, ok := d.GetOk("mesh_owner"); ok {
req.MeshOwner = aws.String(v.(string))
}

resp, err := conn.DescribeMesh(req)
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
log.Printf("[WARN] App Mesh service mesh (%s) not found, removing from state", d.Id())
d.SetId("")
Expand All @@ -128,6 +143,8 @@ func resourceAwsAppmeshMeshRead(d *schema.ResourceData, meta interface{}) error
d.Set("arn", arn)
d.Set("created_date", resp.Mesh.Metadata.CreatedAt.Format(time.RFC3339))
d.Set("last_updated_date", resp.Mesh.Metadata.LastUpdatedAt.Format(time.RFC3339))
d.Set("mesh_owner", resp.Mesh.Metadata.MeshOwner)
d.Set("resource_owner", resp.Mesh.Metadata.ResourceOwner)
err = d.Set("spec", flattenAppmeshMeshSpec(resp.Mesh.Spec))
if err != nil {
return fmt.Errorf("error setting spec: %s", err)
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_appmesh_mesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func testAccAwsAppmeshMesh_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "appmesh", regexp.MustCompile(`mesh/.+`)),
),
},
Expand Down
30 changes: 28 additions & 2 deletions aws/resource_aws_appmesh_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ func resourceAwsAppmeshRoute() *schema.Resource {
ValidateFunc: validation.StringLenBetween(1, 255),
},

"mesh_owner": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validateAwsAccountId,
},

"virtual_router_name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -285,6 +293,11 @@ func resourceAwsAppmeshRoute() *schema.Resource {
Computed: true,
},

"resource_owner": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsSchema(),
},
}
Expand All @@ -300,6 +313,9 @@ func resourceAwsAppmeshRouteCreate(d *schema.ResourceData, meta interface{}) err
Spec: expandAppmeshRouteSpec(d.Get("spec").([]interface{})),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().AppmeshTags(),
}
if v, ok := d.GetOk("mesh_owner"); ok {
req.MeshOwner = aws.String(v.(string))
}

log.Printf("[DEBUG] Creating App Mesh route: %#v", req)
resp, err := conn.CreateRoute(req)
Expand All @@ -316,11 +332,16 @@ func resourceAwsAppmeshRouteRead(d *schema.ResourceData, meta interface{}) error
conn := meta.(*AWSClient).appmeshconn
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

resp, err := conn.DescribeRoute(&appmesh.DescribeRouteInput{
req := &appmesh.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 v, ok := d.GetOk("mesh_owner"); ok {
req.MeshOwner = aws.String(v.(string))
}

resp, err := conn.DescribeRoute(req)
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
log.Printf("[WARN] App Mesh route (%s) not found, removing from state", d.Id())
d.SetId("")
Expand All @@ -338,10 +359,12 @@ func resourceAwsAppmeshRouteRead(d *schema.ResourceData, meta interface{}) error
arn := aws.StringValue(resp.Route.Metadata.Arn)
d.Set("name", resp.Route.RouteName)
d.Set("mesh_name", resp.Route.MeshName)
d.Set("mesh_owner", resp.Route.Metadata.MeshOwner)
d.Set("virtual_router_name", resp.Route.VirtualRouterName)
d.Set("arn", arn)
d.Set("created_date", resp.Route.Metadata.CreatedAt.Format(time.RFC3339))
d.Set("last_updated_date", resp.Route.Metadata.LastUpdatedAt.Format(time.RFC3339))
d.Set("resource_owner", resp.Route.Metadata.ResourceOwner)
err = d.Set("spec", flattenAppmeshRouteSpec(resp.Route.Spec))
if err != nil {
return fmt.Errorf("error setting spec: %s", err)
Expand Down Expand Up @@ -371,6 +394,9 @@ func resourceAwsAppmeshRouteUpdate(d *schema.ResourceData, meta interface{}) err
VirtualRouterName: aws.String(d.Get("virtual_router_name").(string)),
Spec: expandAppmeshRouteSpec(v.([]interface{})),
}
if v, ok := d.GetOk("mesh_owner"); ok {
req.MeshOwner = aws.String(v.(string))
}

log.Printf("[DEBUG] Updating App Mesh route: %#v", req)
_, err := conn.UpdateRoute(req)
Expand Down
20 changes: 20 additions & 0 deletions aws/resource_aws_appmesh_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func testAccAwsAppmeshRoute_httpRoute(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "1"),
Expand All @@ -134,6 +135,7 @@ func testAccAwsAppmeshRoute_httpRoute(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand All @@ -143,6 +145,7 @@ func testAccAwsAppmeshRoute_httpRoute(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "1"),
Expand All @@ -157,6 +160,7 @@ func testAccAwsAppmeshRoute_httpRoute(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand All @@ -166,6 +170,7 @@ func testAccAwsAppmeshRoute_httpRoute(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "1"),
Expand All @@ -180,6 +185,7 @@ func testAccAwsAppmeshRoute_httpRoute(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand Down Expand Up @@ -213,6 +219,7 @@ func testAccAwsAppmeshRoute_tcpRoute(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "0"),
Expand All @@ -222,6 +229,7 @@ func testAccAwsAppmeshRoute_tcpRoute(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.0.action.0.weighted_target.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand All @@ -231,6 +239,7 @@ func testAccAwsAppmeshRoute_tcpRoute(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "0"),
Expand All @@ -240,6 +249,7 @@ func testAccAwsAppmeshRoute_tcpRoute(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.0.action.0.weighted_target.#", "2"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand All @@ -249,6 +259,7 @@ func testAccAwsAppmeshRoute_tcpRoute(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "0"),
Expand All @@ -258,6 +269,7 @@ func testAccAwsAppmeshRoute_tcpRoute(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.0.action.0.weighted_target.#", "2"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand Down Expand Up @@ -340,6 +352,7 @@ func testAccAwsAppmeshRoute_httpHeader(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "1"),
Expand All @@ -359,6 +372,7 @@ func testAccAwsAppmeshRoute_httpHeader(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand All @@ -368,6 +382,7 @@ func testAccAwsAppmeshRoute_httpHeader(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "1"),
Expand Down Expand Up @@ -399,6 +414,7 @@ func testAccAwsAppmeshRoute_httpHeader(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand Down Expand Up @@ -432,6 +448,7 @@ func testAccAwsAppmeshRoute_routePriority(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "1"),
Expand All @@ -446,6 +463,7 @@ func testAccAwsAppmeshRoute_routePriority(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand All @@ -455,6 +473,7 @@ func testAccAwsAppmeshRoute_routePriority(t *testing.T) {
testAccCheckAppmeshRouteExists(resourceName, &r),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"),
resource.TestCheckResourceAttr(resourceName, "virtual_router_name", vrName),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.http_route.#", "1"),
Expand All @@ -469,6 +488,7 @@ func testAccAwsAppmeshRoute_routePriority(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "spec.0.tcp_route.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "created_date"),
resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"),
testAccCheckResourceAttrAccountID(resourceName, "resource_owner"),
testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s/route/%s", meshName, vrName, rName)),
),
},
Expand Down
30 changes: 28 additions & 2 deletions aws/resource_aws_appmesh_virtual_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ func resourceAwsAppmeshVirtualNode() *schema.Resource {
ValidateFunc: validation.StringLenBetween(1, 255),
},

"mesh_owner": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validateAwsAccountId,
},

"spec": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -277,6 +285,11 @@ func resourceAwsAppmeshVirtualNode() *schema.Resource {
Computed: true,
},

"resource_owner": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsSchema(),
},
}
Expand All @@ -291,6 +304,9 @@ func resourceAwsAppmeshVirtualNodeCreate(d *schema.ResourceData, meta interface{
Spec: expandAppmeshVirtualNodeSpec(d.Get("spec").([]interface{})),
Tags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().AppmeshTags(),
}
if v, ok := d.GetOk("mesh_owner"); ok {
req.MeshOwner = aws.String(v.(string))
}

log.Printf("[DEBUG] Creating App Mesh virtual node: %#v", req)
resp, err := conn.CreateVirtualNode(req)
Expand All @@ -307,10 +323,15 @@ func resourceAwsAppmeshVirtualNodeRead(d *schema.ResourceData, meta interface{})
conn := meta.(*AWSClient).appmeshconn
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

resp, err := conn.DescribeVirtualNode(&appmesh.DescribeVirtualNodeInput{
req := &appmesh.DescribeVirtualNodeInput{
MeshName: aws.String(d.Get("mesh_name").(string)),
VirtualNodeName: aws.String(d.Get("name").(string)),
})
}
if v, ok := d.GetOk("mesh_owner"); ok {
req.MeshOwner = aws.String(v.(string))
}

resp, err := conn.DescribeVirtualNode(req)
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
log.Printf("[WARN] App Mesh virtual node (%s) not found, removing from state", d.Id())
d.SetId("")
Expand All @@ -328,9 +349,11 @@ func resourceAwsAppmeshVirtualNodeRead(d *schema.ResourceData, meta interface{})
arn := aws.StringValue(resp.VirtualNode.Metadata.Arn)
d.Set("name", resp.VirtualNode.VirtualNodeName)
d.Set("mesh_name", resp.VirtualNode.MeshName)
d.Set("mesh_owner", resp.VirtualNode.Metadata.MeshOwner)
d.Set("arn", arn)
d.Set("created_date", resp.VirtualNode.Metadata.CreatedAt.Format(time.RFC3339))
d.Set("last_updated_date", resp.VirtualNode.Metadata.LastUpdatedAt.Format(time.RFC3339))
d.Set("resource_owner", resp.VirtualNode.Metadata.ResourceOwner)
err = d.Set("spec", flattenAppmeshVirtualNodeSpec(resp.VirtualNode.Spec))
if err != nil {
return fmt.Errorf("error setting spec: %s", err)
Expand Down Expand Up @@ -359,6 +382,9 @@ func resourceAwsAppmeshVirtualNodeUpdate(d *schema.ResourceData, meta interface{
VirtualNodeName: aws.String(d.Get("name").(string)),
Spec: expandAppmeshVirtualNodeSpec(v.([]interface{})),
}
if v, ok := d.GetOk("mesh_owner"); ok {
req.MeshOwner = aws.String(v.(string))
}

log.Printf("[DEBUG] Updating App Mesh virtual node: %#v", req)
_, err := conn.UpdateVirtualNode(req)
Expand Down
Loading

0 comments on commit 9efb631

Please sign in to comment.