Skip to content

Commit

Permalink
Merge pull request #9249 from kterada0509/feature/add-support-resourc…
Browse files Browse the repository at this point in the history
…e-tags-for-aws_appmesh_virtual_router-resource

Add support tags attribute for aws_appmesh_virtual_router resource
bflad authored Jul 8, 2019

Verified

This commit was signed with the committer’s verified signature.
Matovidlo Martin Vaško
2 parents 8847f0c + dfc04ef commit 0e0e742
Showing 4 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions aws/resource_aws_appmesh_test.go
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ func TestAccAWSAppmesh(t *testing.T) {
},
"VirtualRouter": {
"basic": testAccAwsAppmeshVirtualRouter_basic,
"tags": testAccAwsAppmeshVirtualRouter_tags,
},
"VirtualService": {
"virtualNode": testAccAwsAppmeshVirtualService_virtualNode,
23 changes: 23 additions & 0 deletions aws/resource_aws_appmesh_virtual_router.go
Original file line number Diff line number Diff line change
@@ -110,6 +110,8 @@ func resourceAwsAppmeshVirtualRouter() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsSchema(),
},
}
}
@@ -121,6 +123,7 @@ func resourceAwsAppmeshVirtualRouterCreate(d *schema.ResourceData, meta interfac
MeshName: aws.String(d.Get("mesh_name").(string)),
VirtualRouterName: aws.String(d.Get("name").(string)),
Spec: expandAppmeshVirtualRouterSpec(d.Get("spec").([]interface{})),
Tags: tagsFromMapAppmesh(d.Get("tags").(map[string]interface{})),
}

log.Printf("[DEBUG] Creating App Mesh virtual router: %#v", req)
@@ -165,6 +168,16 @@ func resourceAwsAppmeshVirtualRouterRead(d *schema.ResourceData, meta interface{
return fmt.Errorf("error setting spec: %s", err)
}

err = saveTagsAppmesh(conn, d, aws.StringValue(resp.VirtualRouter.Metadata.Arn))
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
log.Printf("[WARN] App Mesh virtual router (%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
}

@@ -186,6 +199,16 @@ func resourceAwsAppmeshVirtualRouterUpdate(d *schema.ResourceData, meta interfac
}
}

err := setTagsAppmesh(conn, d, d.Get("arn").(string))
if isAWSErr(err, appmesh.ErrCodeNotFoundException, "") {
log.Printf("[WARN] App Mesh virtual router (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
if err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

return resourceAwsAppmeshVirtualRouterRead(d, meta)
}

83 changes: 83 additions & 0 deletions aws/resource_aws_appmesh_virtual_router_test.go
Original file line number Diff line number Diff line change
@@ -151,6 +151,62 @@ func testAccAwsAppmeshVirtualRouter_basic(t *testing.T) {
})
}

func testAccAwsAppmeshVirtualRouter_tags(t *testing.T) {
var vr appmesh.VirtualRouterData
resourceName := "aws_appmesh_virtual_router.foo"
meshName := fmt.Sprintf("tf-test-mesh-%d", acctest.RandInt())
vrName := fmt.Sprintf("tf-test-router-%d", acctest.RandInt())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAppmeshVirtualRouterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAppmeshVirtualRouterConfig_tags(meshName, vrName, "foo", "bar", "good", "bad"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshVirtualRouterExists(
resourceName, &vr),
resource.TestCheckResourceAttr(
resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(
resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(
resourceName, "tags.good", "bad"),
),
},
{
Config: testAccAppmeshVirtualRouterConfig_tags(meshName, vrName, "foo2", "bar", "good", "bad2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshVirtualRouterExists(
resourceName, &vr),
resource.TestCheckResourceAttr(
resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(
resourceName, "tags.foo2", "bar"),
resource.TestCheckResourceAttr(
resourceName, "tags.good", "bad2"),
),
},
{
Config: testAccAppmeshVirtualRouterConfig_basic(meshName, vrName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshVirtualRouterExists(
resourceName, &vr),
resource.TestCheckResourceAttr(
resourceName, "tags.%", "0"),
),
},
{
ResourceName: resourceName,
ImportStateId: fmt.Sprintf("%s/%s", meshName, vrName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

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

@@ -244,3 +300,30 @@ resource "aws_appmesh_virtual_router" "foo" {
}
`, meshName, vrName)
}

func testAccAppmeshVirtualRouterConfig_tags(meshName, vrName, tagKey1, tagValue1, tagKey2, tagValue2 string) string {
return fmt.Sprintf(`
resource "aws_appmesh_mesh" "foo" {
name = "%[1]s"
}
resource "aws_appmesh_virtual_router" "foo" {
name = "%[2]s"
mesh_name = "${aws_appmesh_mesh.foo.id}"
spec {
listener {
port_mapping {
port = 8080
protocol = "http"
}
}
}
tags = {
%[3]s = %[4]q
%[5]s = %[6]q
}
}
`, meshName, vrName, tagKey1, tagValue1, tagKey2, tagValue2)
}
1 change: 1 addition & 0 deletions website/docs/r/appmesh_virtual_router.html.markdown
Original file line number Diff line number Diff line change
@@ -47,6 +47,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.
* `spec` - (Required) The virtual router specification to apply.
* `tags` - (Optional) A mapping of tags to assign to the resource.

The `spec` object supports the following:

0 comments on commit 0e0e742

Please sign in to comment.