From 9efb6314302102550a95bd16d33aaa318d792f4d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 23 Sep 2020 14:55:17 -0400 Subject: [PATCH] service/appmesh: Add 'mesh_owner' and 'resource_owner' attributes in 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 --- aws/resource_aws_appmesh_mesh.go | 21 ++++++- aws/resource_aws_appmesh_mesh_test.go | 2 + aws/resource_aws_appmesh_route.go | 30 +++++++++- aws/resource_aws_appmesh_route_test.go | 20 +++++++ aws/resource_aws_appmesh_virtual_node.go | 30 +++++++++- aws/resource_aws_appmesh_virtual_node_test.go | 10 ++++ aws/resource_aws_appmesh_virtual_router.go | 30 +++++++++- ...esource_aws_appmesh_virtual_router_test.go | 60 +++++++------------ aws/resource_aws_appmesh_virtual_service.go | 30 +++++++++- ...source_aws_appmesh_virtual_service_test.go | 6 ++ website/docs/r/appmesh_mesh.html.markdown | 2 + website/docs/r/appmesh_route.html.markdown | 4 ++ .../docs/r/appmesh_virtual_node.html.markdown | 4 ++ .../r/appmesh_virtual_router.html.markdown | 4 ++ .../r/appmesh_virtual_service.html.markdown | 4 ++ 15 files changed, 209 insertions(+), 48 deletions(-) diff --git a/aws/resource_aws_appmesh_mesh.go b/aws/resource_aws_appmesh_mesh.go index 883b3f01b2c8..ce374d70303f 100644 --- a/aws/resource_aws_appmesh_mesh.go +++ b/aws/resource_aws_appmesh_mesh.go @@ -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(), }, } @@ -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("") @@ -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) diff --git a/aws/resource_aws_appmesh_mesh_test.go b/aws/resource_aws_appmesh_mesh_test.go index 673be6a056ec..42762f14086d 100644 --- a/aws/resource_aws_appmesh_mesh_test.go +++ b/aws/resource_aws_appmesh_mesh_test.go @@ -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/.+`)), ), }, diff --git a/aws/resource_aws_appmesh_route.go b/aws/resource_aws_appmesh_route.go index f592c8977347..43b1e4738092 100644 --- a/aws/resource_aws_appmesh_route.go +++ b/aws/resource_aws_appmesh_route.go @@ -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, @@ -285,6 +293,11 @@ func resourceAwsAppmeshRoute() *schema.Resource { Computed: true, }, + "resource_owner": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tagsSchema(), }, } @@ -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) @@ -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("") @@ -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) @@ -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) diff --git a/aws/resource_aws_appmesh_route_test.go b/aws/resource_aws_appmesh_route_test.go index 5410a592650a..3470641e75cf 100644 --- a/aws/resource_aws_appmesh_route_test.go +++ b/aws/resource_aws_appmesh_route_test.go @@ -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"), @@ -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)), ), }, @@ -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"), @@ -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)), ), }, @@ -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"), @@ -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)), ), }, @@ -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"), @@ -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)), ), }, @@ -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"), @@ -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)), ), }, @@ -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"), @@ -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)), ), }, @@ -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"), @@ -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)), ), }, @@ -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"), @@ -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)), ), }, @@ -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"), @@ -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)), ), }, @@ -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"), @@ -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)), ), }, diff --git a/aws/resource_aws_appmesh_virtual_node.go b/aws/resource_aws_appmesh_virtual_node.go index 6c052df52a9a..7f1ba854a893 100644 --- a/aws/resource_aws_appmesh_virtual_node.go +++ b/aws/resource_aws_appmesh_virtual_node.go @@ -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, @@ -277,6 +285,11 @@ func resourceAwsAppmeshVirtualNode() *schema.Resource { Computed: true, }, + "resource_owner": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tagsSchema(), }, } @@ -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) @@ -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("") @@ -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) @@ -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) diff --git a/aws/resource_aws_appmesh_virtual_node_test.go b/aws/resource_aws_appmesh_virtual_node_test.go index b5c6590f466c..fc3ceb7d8e8e 100644 --- a/aws/resource_aws_appmesh_virtual_node_test.go +++ b/aws/resource_aws_appmesh_virtual_node_test.go @@ -96,6 +96,7 @@ func testAccAwsAppmeshVirtualNode_basic(t *testing.T) { testAccCheckAppmeshVirtualNodeExists(resourceName, &vn), resource.TestCheckResourceAttr(resourceName, "name", vnName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.backend.#", "0"), resource.TestCheckResourceAttr(resourceName, "spec.0.listener.#", "0"), @@ -103,6 +104,7 @@ func testAccAwsAppmeshVirtualNode_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.#", "0"), resource.TestCheckResourceAttrSet(resourceName, "created_date"), resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"), + testAccCheckResourceAttrAccountID(resourceName, "resource_owner"), testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualNode/%s", meshName, vnName)), ), }, @@ -136,6 +138,7 @@ func testAccAwsAppmeshVirtualNode_cloudMapServiceDiscovery(t *testing.T) { testAccCheckAppmeshVirtualNodeExists(resourceName, &vn), resource.TestCheckResourceAttr(resourceName, "name", vnName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.aws_cloud_map.#", "1"), @@ -151,6 +154,7 @@ func testAccAwsAppmeshVirtualNode_cloudMapServiceDiscovery(t *testing.T) { testAccCheckAppmeshVirtualNodeExists(resourceName, &vn), resource.TestCheckResourceAttr(resourceName, "name", vnName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.aws_cloud_map.#", "1"), @@ -187,6 +191,7 @@ func testAccAwsAppmeshVirtualNode_listenerHealthChecks(t *testing.T) { testAccCheckAppmeshVirtualNodeExists(resourceName, &vn), resource.TestCheckResourceAttr(resourceName, "name", vnName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.backend.#", "1"), tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "spec.0.backend.*", map[string]string{ @@ -211,6 +216,7 @@ func testAccAwsAppmeshVirtualNode_listenerHealthChecks(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.dns.0.hostname", "serviceb.simpleapp.local"), resource.TestCheckResourceAttrSet(resourceName, "created_date"), resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"), + testAccCheckResourceAttrAccountID(resourceName, "resource_owner"), testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualNode/%s", meshName, vnName)), ), }, @@ -220,6 +226,7 @@ func testAccAwsAppmeshVirtualNode_listenerHealthChecks(t *testing.T) { testAccCheckAppmeshVirtualNodeExists(resourceName, &vn), resource.TestCheckResourceAttr(resourceName, "name", vnName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.backend.#", "2"), tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "spec.0.backend.*", map[string]string{ @@ -247,6 +254,7 @@ func testAccAwsAppmeshVirtualNode_listenerHealthChecks(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.dns.0.hostname", "serviceb1.simpleapp.local"), resource.TestCheckResourceAttrSet(resourceName, "created_date"), resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"), + testAccCheckResourceAttrAccountID(resourceName, "resource_owner"), testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualNode/%s", meshName, vnName)), ), }, @@ -277,6 +285,7 @@ func testAccAwsAppmeshVirtualNode_logging(t *testing.T) { testAccCheckAppmeshVirtualNodeExists(resourceName, &vn), resource.TestCheckResourceAttr(resourceName, "name", vnName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.logging.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.#", "1"), @@ -290,6 +299,7 @@ func testAccAwsAppmeshVirtualNode_logging(t *testing.T) { testAccCheckAppmeshVirtualNodeExists(resourceName, &vn), resource.TestCheckResourceAttr(resourceName, "name", vnName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.0.logging.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.logging.0.access_log.0.file.#", "1"), diff --git a/aws/resource_aws_appmesh_virtual_router.go b/aws/resource_aws_appmesh_virtual_router.go index 770c2d0e113f..e9082ae60c64 100644 --- a/aws/resource_aws_appmesh_virtual_router.go +++ b/aws/resource_aws_appmesh_virtual_router.go @@ -42,6 +42,14 @@ func resourceAwsAppmeshVirtualRouter() *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, @@ -102,6 +110,11 @@ func resourceAwsAppmeshVirtualRouter() *schema.Resource { Computed: true, }, + "resource_owner": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tagsSchema(), }, } @@ -116,6 +129,9 @@ func resourceAwsAppmeshVirtualRouterCreate(d *schema.ResourceData, meta interfac Spec: expandAppmeshVirtualRouterSpec(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 router: %#v", req) resp, err := conn.CreateVirtualRouter(req) @@ -132,10 +148,15 @@ func resourceAwsAppmeshVirtualRouterRead(d *schema.ResourceData, meta interface{ conn := meta.(*AWSClient).appmeshconn ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig - resp, err := conn.DescribeVirtualRouter(&appmesh.DescribeVirtualRouterInput{ + req := &appmesh.DescribeVirtualRouterInput{ MeshName: aws.String(d.Get("mesh_name").(string)), VirtualRouterName: aws.String(d.Get("name").(string)), - }) + } + if v, ok := d.GetOk("mesh_owner"); ok { + req.MeshOwner = aws.String(v.(string)) + } + + resp, err := conn.DescribeVirtualRouter(req) if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") { log.Printf("[WARN] App Mesh virtual router (%s) not found, removing from state", d.Id()) d.SetId("") @@ -153,9 +174,11 @@ func resourceAwsAppmeshVirtualRouterRead(d *schema.ResourceData, meta interface{ arn := aws.StringValue(resp.VirtualRouter.Metadata.Arn) d.Set("name", resp.VirtualRouter.VirtualRouterName) d.Set("mesh_name", resp.VirtualRouter.MeshName) + d.Set("mesh_owner", resp.VirtualRouter.Metadata.MeshOwner) d.Set("arn", arn) d.Set("created_date", resp.VirtualRouter.Metadata.CreatedAt.Format(time.RFC3339)) d.Set("last_updated_date", resp.VirtualRouter.Metadata.LastUpdatedAt.Format(time.RFC3339)) + d.Set("resource_owner", resp.VirtualRouter.Metadata.ResourceOwner) err = d.Set("spec", flattenAppmeshVirtualRouterSpec(resp.VirtualRouter.Spec)) if err != nil { return fmt.Errorf("error setting spec: %s", err) @@ -184,6 +207,9 @@ func resourceAwsAppmeshVirtualRouterUpdate(d *schema.ResourceData, meta interfac VirtualRouterName: aws.String(d.Get("name").(string)), Spec: expandAppmeshVirtualRouterSpec(v.([]interface{})), } + if v, ok := d.GetOk("mesh_owner"); ok { + req.MeshOwner = aws.String(v.(string)) + } log.Printf("[DEBUG] Updating App Mesh virtual router: %#v", req) _, err := conn.UpdateVirtualRouter(req) diff --git a/aws/resource_aws_appmesh_virtual_router_test.go b/aws/resource_aws_appmesh_virtual_router_test.go index 39428f079745..ad92738a3278 100644 --- a/aws/resource_aws_appmesh_virtual_router_test.go +++ b/aws/resource_aws_appmesh_virtual_router_test.go @@ -95,49 +95,33 @@ func testAccAwsAppmeshVirtualRouter_basic(t *testing.T) { { Config: testAccAppmeshVirtualRouterConfig_basic(meshName, vrName), Check: resource.ComposeTestCheckFunc( - testAccCheckAppmeshVirtualRouterExists( - resourceName, &vr), - resource.TestCheckResourceAttr( - resourceName, "name", vrName), - resource.TestCheckResourceAttr( - resourceName, "mesh_name", meshName), - resource.TestCheckResourceAttr( - resourceName, "spec.#", "1"), - resource.TestCheckResourceAttr( - resourceName, "spec.0.listener.#", "1"), - resource.TestCheckResourceAttr( - resourceName, "spec.0.listener.0.port_mapping.#", "1"), - resource.TestCheckResourceAttr( - resourceName, "spec.0.listener.0.port_mapping.0.port", "8080"), - resource.TestCheckResourceAttr( - resourceName, "spec.0.listener.0.port_mapping.0.protocol", "http"), - resource.TestCheckResourceAttrSet( - resourceName, "created_date"), - resource.TestCheckResourceAttrSet( - resourceName, "last_updated_date"), - testAccCheckResourceAttrRegionalARN( - resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualRouter/%s", meshName, vrName)), + testAccCheckAppmeshVirtualRouterExists(resourceName, &vr), + resource.TestCheckResourceAttr(resourceName, "name", vrName), + resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), + resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.listener.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.port_mapping.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.port_mapping.0.port", "8080"), + resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.port_mapping.0.protocol", "http"), + 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", meshName, vrName)), ), }, { Config: testAccAppmeshVirtualRouterConfig_updated(meshName, vrName), Check: resource.ComposeTestCheckFunc( - testAccCheckAppmeshVirtualRouterExists( - resourceName, &vr), - resource.TestCheckResourceAttr( - resourceName, "name", vrName), - resource.TestCheckResourceAttr( - resourceName, "mesh_name", meshName), - resource.TestCheckResourceAttr( - resourceName, "spec.#", "1"), - resource.TestCheckResourceAttr( - resourceName, "spec.0.listener.#", "1"), - resource.TestCheckResourceAttr( - resourceName, "spec.0.listener.0.port_mapping.#", "1"), - resource.TestCheckResourceAttr( - resourceName, "spec.0.listener.0.port_mapping.0.port", "8081"), - resource.TestCheckResourceAttr( - resourceName, "spec.0.listener.0.port_mapping.0.protocol", "http"), + testAccCheckAppmeshVirtualRouterExists(resourceName, &vr), + resource.TestCheckResourceAttr(resourceName, "name", vrName), + resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), + resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.listener.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.port_mapping.#", "1"), + resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.port_mapping.0.port", "8081"), + resource.TestCheckResourceAttr(resourceName, "spec.0.listener.0.port_mapping.0.protocol", "http"), ), }, { diff --git a/aws/resource_aws_appmesh_virtual_service.go b/aws/resource_aws_appmesh_virtual_service.go index a3446ab07127..94b71d7bf704 100644 --- a/aws/resource_aws_appmesh_virtual_service.go +++ b/aws/resource_aws_appmesh_virtual_service.go @@ -38,6 +38,14 @@ func resourceAwsAppmeshVirtualService() *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, @@ -107,6 +115,11 @@ func resourceAwsAppmeshVirtualService() *schema.Resource { Computed: true, }, + "resource_owner": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tagsSchema(), }, } @@ -121,6 +134,9 @@ func resourceAwsAppmeshVirtualServiceCreate(d *schema.ResourceData, meta interfa Spec: expandAppmeshVirtualServiceSpec(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 service: %#v", req) resp, err := conn.CreateVirtualService(req) @@ -137,10 +153,15 @@ func resourceAwsAppmeshVirtualServiceRead(d *schema.ResourceData, meta interface conn := meta.(*AWSClient).appmeshconn ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig - resp, err := conn.DescribeVirtualService(&appmesh.DescribeVirtualServiceInput{ + req := &appmesh.DescribeVirtualServiceInput{ MeshName: aws.String(d.Get("mesh_name").(string)), VirtualServiceName: aws.String(d.Get("name").(string)), - }) + } + if v, ok := d.GetOk("mesh_owner"); ok { + req.MeshOwner = aws.String(v.(string)) + } + + resp, err := conn.DescribeVirtualService(req) if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") { log.Printf("[WARN] App Mesh virtual service (%s) not found, removing from state", d.Id()) d.SetId("") @@ -158,9 +179,11 @@ func resourceAwsAppmeshVirtualServiceRead(d *schema.ResourceData, meta interface arn := aws.StringValue(resp.VirtualService.Metadata.Arn) d.Set("name", resp.VirtualService.VirtualServiceName) d.Set("mesh_name", resp.VirtualService.MeshName) + d.Set("mesh_owner", resp.VirtualService.Metadata.MeshOwner) d.Set("arn", arn) d.Set("created_date", resp.VirtualService.Metadata.CreatedAt.Format(time.RFC3339)) d.Set("last_updated_date", resp.VirtualService.Metadata.LastUpdatedAt.Format(time.RFC3339)) + d.Set("resource_owner", resp.VirtualService.Metadata.ResourceOwner) err = d.Set("spec", flattenAppmeshVirtualServiceSpec(resp.VirtualService.Spec)) if err != nil { return fmt.Errorf("error setting spec: %s", err) @@ -189,6 +212,9 @@ func resourceAwsAppmeshVirtualServiceUpdate(d *schema.ResourceData, meta interfa VirtualServiceName: aws.String(d.Get("name").(string)), Spec: expandAppmeshVirtualServiceSpec(v.([]interface{})), } + if v, ok := d.GetOk("mesh_owner"); ok { + req.MeshOwner = aws.String(v.(string)) + } log.Printf("[DEBUG] Updating App Mesh virtual service: %#v", req) _, err := conn.UpdateVirtualService(req) diff --git a/aws/resource_aws_appmesh_virtual_service_test.go b/aws/resource_aws_appmesh_virtual_service_test.go index e636592787fe..7b67ef31d673 100644 --- a/aws/resource_aws_appmesh_virtual_service_test.go +++ b/aws/resource_aws_appmesh_virtual_service_test.go @@ -97,12 +97,14 @@ func testAccAwsAppmeshVirtualService_virtualNode(t *testing.T) { testAccCheckAppmeshVirtualServiceExists(resourceName, &vs), resource.TestCheckResourceAttr(resourceName, "name", vsName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.0.virtual_node.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.0.virtual_node.0.virtual_node_name", vnName1), resource.TestCheckResourceAttrSet(resourceName, "created_date"), resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"), + testAccCheckResourceAttrAccountID(resourceName, "resource_owner"), testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualService/%s", meshName, vsName)), ), }, @@ -112,6 +114,7 @@ func testAccAwsAppmeshVirtualService_virtualNode(t *testing.T) { testAccCheckAppmeshVirtualServiceExists(resourceName, &vs), resource.TestCheckResourceAttr(resourceName, "name", vsName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.0.virtual_node.#", "1"), @@ -147,12 +150,14 @@ func testAccAwsAppmeshVirtualService_virtualRouter(t *testing.T) { testAccCheckAppmeshVirtualServiceExists(resourceName, &vs), resource.TestCheckResourceAttr(resourceName, "name", vsName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.0.virtual_router.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.0.virtual_router.0.virtual_router_name", vrName1), resource.TestCheckResourceAttrSet(resourceName, "created_date"), resource.TestCheckResourceAttrSet(resourceName, "last_updated_date"), + testAccCheckResourceAttrAccountID(resourceName, "resource_owner"), testAccCheckResourceAttrRegionalARN(resourceName, "arn", "appmesh", fmt.Sprintf("mesh/%s/virtualService/%s", meshName, vsName))), }, { @@ -161,6 +166,7 @@ func testAccAwsAppmeshVirtualService_virtualRouter(t *testing.T) { testAccCheckAppmeshVirtualServiceExists(resourceName, &vs), resource.TestCheckResourceAttr(resourceName, "name", vsName), resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName), + testAccCheckResourceAttrAccountID(resourceName, "mesh_owner"), resource.TestCheckResourceAttr(resourceName, "spec.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.#", "1"), resource.TestCheckResourceAttr(resourceName, "spec.0.provider.0.virtual_router.#", "1"), diff --git a/website/docs/r/appmesh_mesh.html.markdown b/website/docs/r/appmesh_mesh.html.markdown index eff25cdc41c9..d340feb6a2e6 100644 --- a/website/docs/r/appmesh_mesh.html.markdown +++ b/website/docs/r/appmesh_mesh.html.markdown @@ -59,6 +59,8 @@ In addition to all arguments above, the following attributes are exported: * `arn` - The ARN of the service mesh. * `created_date` - The creation date of the service mesh. * `last_updated_date` - The last update date of the service mesh. +* `mesh_owner` - The AWS account ID of the service mesh's owner. +* `resource_owner` - The resource owner's AWS account ID. ## Import diff --git a/website/docs/r/appmesh_route.html.markdown b/website/docs/r/appmesh_route.html.markdown index b2350cc672cf..3dcd6180ca53 100644 --- a/website/docs/r/appmesh_route.html.markdown +++ b/website/docs/r/appmesh_route.html.markdown @@ -104,6 +104,7 @@ The following arguments are supported: * `name` - (Required) The name to use for the route. * `mesh_name` - (Required) The name of the service mesh in which to create the route. +* `mesh_owner` - (Optional) The AWS account ID of the service mesh's owner. Defaults to the account ID the [AWS provider][1] is currently connected to. * `virtual_router_name` - (Required) The name of the virtual router in which to create the route. * `spec` - (Required) The route specification to apply. * `tags` - (Optional) A map of tags to assign to the resource. @@ -169,6 +170,7 @@ In addition to all arguments above, the following attributes are exported: * `arn` - The ARN of the route. * `created_date` - The creation date of the route. * `last_updated_date` - The last update date of the route. +* `resource_owner` - The resource owner's AWS account ID. ## Import @@ -178,3 +180,5 @@ e.g. ``` $ terraform import aws_appmesh_virtual_route.serviceb simpleapp/serviceB/serviceB-route ``` + +[1]: /docs/providers/aws/index.html diff --git a/website/docs/r/appmesh_virtual_node.html.markdown b/website/docs/r/appmesh_virtual_node.html.markdown index b6a71b8f168d..0878e3a36a84 100644 --- a/website/docs/r/appmesh_virtual_node.html.markdown +++ b/website/docs/r/appmesh_virtual_node.html.markdown @@ -175,6 +175,7 @@ The following arguments are supported: * `name` - (Required) The name to use for the virtual node. * `mesh_name` - (Required) The name of the service mesh in which to create the virtual node. +* `mesh_owner` - (Optional) The AWS account ID of the service mesh's owner. Defaults to the account ID the [AWS provider][1] is currently connected to. * `spec` - (Required) The virtual node specification to apply. * `tags` - (Optional) A map of tags to assign to the resource. @@ -249,6 +250,7 @@ In addition to all arguments above, the following attributes are exported: * `arn` - The ARN of the virtual node. * `created_date` - The creation date of the virtual node. * `last_updated_date` - The last update date of the virtual node. +* `resource_owner` - The resource owner's AWS account ID. ## Import @@ -258,3 +260,5 @@ e.g. ``` $ terraform import aws_appmesh_virtual_node.serviceb1 simpleapp/serviceBv1 ``` + +[1]: /docs/providers/aws/index.html diff --git a/website/docs/r/appmesh_virtual_router.html.markdown b/website/docs/r/appmesh_virtual_router.html.markdown index 137a1d601018..0e5d0bf89fd6 100644 --- a/website/docs/r/appmesh_virtual_router.html.markdown +++ b/website/docs/r/appmesh_virtual_router.html.markdown @@ -46,6 +46,7 @@ The following arguments are supported: * `name` - (Required) The name to use for the virtual router. * `mesh_name` - (Required) The name of the service mesh in which to create the virtual router. +* `mesh_owner` - (Optional) The AWS account ID of the service mesh's owner. Defaults to the account ID the [AWS provider][1] is currently connected to. * `spec` - (Required) The virtual router specification to apply. * `tags` - (Optional) A map of tags to assign to the resource. @@ -71,6 +72,7 @@ In addition to all arguments above, the following attributes are exported: * `arn` - The ARN of the virtual router. * `created_date` - The creation date of the virtual router. * `last_updated_date` - The last update date of the virtual router. +* `resource_owner` - The resource owner's AWS account ID. ## Import @@ -80,3 +82,5 @@ e.g. ``` $ terraform import aws_appmesh_virtual_router.serviceb simpleapp/serviceB ``` + +[1]: /docs/providers/aws/index.html diff --git a/website/docs/r/appmesh_virtual_service.html.markdown b/website/docs/r/appmesh_virtual_service.html.markdown index 0ec90aa5c04a..8cb0cb970e23 100644 --- a/website/docs/r/appmesh_virtual_service.html.markdown +++ b/website/docs/r/appmesh_virtual_service.html.markdown @@ -52,6 +52,7 @@ The following arguments are supported: * `name` - (Required) The name to use for the virtual service. * `mesh_name` - (Required) The name of the service mesh in which to create the virtual service. +* `mesh_owner` - (Optional) The AWS account ID of the service mesh's owner. Defaults to the account ID the [AWS provider][1] is currently connected to. * `spec` - (Required) The virtual service specification to apply. * `tags` - (Optional) A map of tags to assign to the resource. @@ -80,6 +81,7 @@ In addition to all arguments above, the following attributes are exported: * `arn` - The ARN of the virtual service. * `created_date` - The creation date of the virtual service. * `last_updated_date` - The last update date of the virtual service. +* `resource_owner` - The resource owner's AWS account ID. ## Import @@ -89,3 +91,5 @@ e.g. ``` $ terraform import aws_appmesh_virtual_service.servicea simpleapp/servicea.simpleapp.local ``` + +[1]: /docs/providers/aws/index.html