Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS App Mesh service discovery using AWS Cloud Map #9271

Merged
merged 2 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions aws/resource_aws_appmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ func TestAccAWSAppmesh(t *testing.T) {
"tags": testAccAwsAppmeshRoute_tags,
},
"VirtualNode": {
"basic": testAccAwsAppmeshVirtualNode_basic,
"listenerHealthChecks": testAccAwsAppmeshVirtualNode_listenerHealthChecks,
"logging": testAccAwsAppmeshVirtualNode_logging,
"tags": testAccAwsAppmeshVirtualNode_tags,
"basic": testAccAwsAppmeshVirtualNode_basic,
"cloudMapServiceDiscovery": testAccAwsAppmeshVirtualNode_cloudMapServiceDiscovery,
"listenerHealthChecks": testAccAwsAppmeshVirtualNode_listenerHealthChecks,
"logging": testAccAwsAppmeshVirtualNode_logging,
"tags": testAccAwsAppmeshVirtualNode_tags,
},
"VirtualRouter": {
"basic": testAccAwsAppmeshVirtualRouter_basic,
Expand Down
37 changes: 33 additions & 4 deletions aws/resource_aws_appmesh_virtual_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,40 @@ func resourceAwsAppmeshVirtualNode() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"aws_cloud_map": {
Type: schema.TypeList,
Optional: true,
MinItems: 0,
MaxItems: 1,
ConflictsWith: []string{"spec.0.service_discovery.0.dns"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"attributes": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"namespace_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateServiceDiscoveryHttpNamespaceName,
},

"service_name": {
Type: schema.TypeString,
Required: true,
},
},
},
},

"dns": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
MaxItems: 1,
Type: schema.TypeList,
Optional: true,
MinItems: 0,
MaxItems: 1,
ConflictsWith: []string{"spec.0.service_discovery.0.aws_cloud_map"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_name": {
Expand Down
197 changes: 135 additions & 62 deletions aws/resource_aws_appmesh_virtual_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func testAccAwsAppmeshVirtualNode_basic(t *testing.T) {
var vn appmesh.VirtualNodeData
resourceName := "aws_appmesh_virtual_node.foo"
resourceName := "aws_appmesh_virtual_node.test"
meshName := fmt.Sprintf("tf-test-mesh-%d", acctest.RandInt())
vnName := fmt.Sprintf("tf-test-node-%d", acctest.RandInt())

Expand Down Expand Up @@ -49,9 +49,62 @@ func testAccAwsAppmeshVirtualNode_basic(t *testing.T) {
})
}

func testAccAwsAppmeshVirtualNode_cloudMapServiceDiscovery(t *testing.T) {
var vn appmesh.VirtualNodeData
resourceName := "aws_appmesh_virtual_node.test"
nsResourceName := "aws_service_discovery_http_namespace.test"
meshName := fmt.Sprintf("tf-test-mesh-%d", acctest.RandInt())
vnName := fmt.Sprintf("tf-test-node-%d", acctest.RandInt())
rName := fmt.Sprintf("tf-testacc-appmeshvn-%s", acctest.RandStringFromCharSet(11, acctest.CharSetAlphaNum))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAppmeshVirtualNodeDestroy,
Steps: []resource.TestStep{
{
Config: testAccAppmeshVirtualNodeConfig_cloudMapServiceDiscovery(meshName, vnName, rName, "Key1", "Value1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshVirtualNodeExists(resourceName, &vn),
resource.TestCheckResourceAttr(resourceName, "name", vnName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
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"),
resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.aws_cloud_map.0.attributes.%", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.aws_cloud_map.0.attributes.Key1", "Value1"),
resource.TestCheckResourceAttrPair(resourceName, "spec.0.service_discovery.0.aws_cloud_map.0.namespace_name", nsResourceName, "name"),
resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.aws_cloud_map.0.service_name", rName),
),
},
{
Config: testAccAppmeshVirtualNodeConfig_cloudMapServiceDiscovery(meshName, vnName, rName, "Key1", "Value2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshVirtualNodeExists(resourceName, &vn),
resource.TestCheckResourceAttr(resourceName, "name", vnName),
resource.TestCheckResourceAttr(resourceName, "mesh_name", meshName),
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"),
resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.aws_cloud_map.0.attributes.%", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.aws_cloud_map.0.attributes.Key1", "Value2"),
resource.TestCheckResourceAttrPair(resourceName, "spec.0.service_discovery.0.aws_cloud_map.0.namespace_name", nsResourceName, "name"),
resource.TestCheckResourceAttr(resourceName, "spec.0.service_discovery.0.aws_cloud_map.0.service_name", rName),
),
},
{
ResourceName: resourceName,
ImportStateId: fmt.Sprintf("%s/%s", meshName, vnName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccAwsAppmeshVirtualNode_listenerHealthChecks(t *testing.T) {
var vn appmesh.VirtualNodeData
resourceName := "aws_appmesh_virtual_node.foo"
resourceName := "aws_appmesh_virtual_node.test"
meshName := fmt.Sprintf("tf-test-mesh-%d", acctest.RandInt())
vnName := fmt.Sprintf("tf-test-node-%d", acctest.RandInt())

Expand Down Expand Up @@ -135,7 +188,7 @@ func testAccAwsAppmeshVirtualNode_listenerHealthChecks(t *testing.T) {

func testAccAwsAppmeshVirtualNode_logging(t *testing.T) {
var vn appmesh.VirtualNodeData
resourceName := "aws_appmesh_virtual_node.foo"
resourceName := "aws_appmesh_virtual_node.test"
meshName := fmt.Sprintf("tf-test-mesh-%d", acctest.RandInt())
vnName := fmt.Sprintf("tf-test-node-%d", acctest.RandInt())

Expand Down Expand Up @@ -181,7 +234,7 @@ func testAccAwsAppmeshVirtualNode_logging(t *testing.T) {

func testAccAwsAppmeshVirtualNode_tags(t *testing.T) {
var vn appmesh.VirtualNodeData
resourceName := "aws_appmesh_virtual_node.foo"
resourceName := "aws_appmesh_virtual_node.test"
meshName := fmt.Sprintf("tf-test-mesh-%d", acctest.RandInt())
vnName := fmt.Sprintf("tf-test-node-%d", acctest.RandInt())

Expand All @@ -194,32 +247,25 @@ func testAccAwsAppmeshVirtualNode_tags(t *testing.T) {
Config: testAccAppmeshVirtualNodeConfig_tags(meshName, vnName, "foo", "bar", "good", "bad"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshVirtualNodeExists(resourceName, &vn),
resource.TestCheckResourceAttr(
resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(
resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(
resourceName, "tags.good", "bad"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "tags.good", "bad"),
),
},
{
Config: testAccAppmeshVirtualNodeConfig_tags(meshName, vnName, "foo2", "bar", "good", "bad2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshVirtualNodeExists(resourceName, &vn),
resource.TestCheckResourceAttr(
resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(
resourceName, "tags.foo2", "bar"),
resource.TestCheckResourceAttr(
resourceName, "tags.good", "bad2"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.foo2", "bar"),
resource.TestCheckResourceAttr(resourceName, "tags.good", "bad2"),
),
},
{
Config: testAccAppmeshVirtualNodeConfig_basic(meshName, vnName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppmeshVirtualNodeExists(resourceName, &vn),
resource.TestCheckResourceAttr(
resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
{
Expand Down Expand Up @@ -282,30 +328,69 @@ func testAccCheckAppmeshVirtualNodeExists(name string, v *appmesh.VirtualNodeDat
}
}

func testAccAppmeshVirtualNodeConfig_basic(meshName, vnName string) string {
func testAccAppmeshVirtualNodeConfig_mesh(rName string) string {
return fmt.Sprintf(`
resource "aws_appmesh_mesh" "foo" {
resource "aws_appmesh_mesh" "test" {
name = %[1]q
}
`, rName)
}

resource "aws_appmesh_virtual_node" "foo" {
name = %[2]q
mesh_name = "${aws_appmesh_mesh.foo.id}"
func testAccAppmeshVirtualNodeConfig_basic(meshName, vnName string) string {
return testAccAppmeshVirtualNodeConfig_mesh(meshName) + fmt.Sprintf(`
resource "aws_appmesh_virtual_node" "test" {
name = %[1]q
mesh_name = "${aws_appmesh_mesh.test.id}"

spec {}
}
`, meshName, vnName)
`, vnName)
}

func testAccAppmeshVirtualNodeConfig_listenerHealthChecks(meshName, vnName string) string {
return fmt.Sprintf(`
resource "aws_appmesh_mesh" "foo" {
name = %[1]q
func testAccAppmeshVirtualNodeConfig_cloudMapServiceDiscovery(meshName, vnName, rName, attrKey, attrValue string) string {
return testAccAppmeshVirtualNodeConfig_mesh(meshName) + fmt.Sprintf(`
resource "aws_service_discovery_http_namespace" "test" {
name = %[2]q
}

resource "aws_appmesh_virtual_node" "test" {
name = %[1]q
mesh_name = "${aws_appmesh_mesh.test.id}"

spec {
backend {
virtual_service {
virtual_service_name = "servicea.simpleapp.local"
}
}

listener {
port_mapping {
port = 8080
protocol = "http"
}
}

service_discovery {
aws_cloud_map {
attributes = {
%[3]s = %[4]q
}

service_name = %[2]q
namespace_name = "${aws_service_discovery_http_namespace.test.name}"
}
}
}
}
`, vnName, rName, attrKey, attrValue)
}

resource "aws_appmesh_virtual_node" "foo" {
name = %[2]q
mesh_name = "${aws_appmesh_mesh.foo.id}"
func testAccAppmeshVirtualNodeConfig_listenerHealthChecks(meshName, vnName string) string {
return testAccAppmeshVirtualNodeConfig_mesh(meshName) + fmt.Sprintf(`
resource "aws_appmesh_virtual_node" "test" {
name = %[1]q
mesh_name = "${aws_appmesh_mesh.test.id}"

spec {
backend {
Expand Down Expand Up @@ -337,18 +422,14 @@ resource "aws_appmesh_virtual_node" "foo" {
}
}
}
`, meshName, vnName)
`, vnName)
}

func testAccAppmeshVirtualNodeConfig_listenerHealthChecksUpdated(meshName, vnName string) string {
return fmt.Sprintf(`
resource "aws_appmesh_mesh" "foo" {
name = %[1]q
}

resource "aws_appmesh_virtual_node" "foo" {
name = %[2]q
mesh_name = "${aws_appmesh_mesh.foo.id}"
return testAccAppmeshVirtualNodeConfig_mesh(meshName) + fmt.Sprintf(`
resource "aws_appmesh_virtual_node" "test" {
name = %[1]q
mesh_name = "${aws_appmesh_mesh.test.id}"

spec {
backend {
Expand Down Expand Up @@ -386,18 +467,14 @@ resource "aws_appmesh_virtual_node" "foo" {
}
}
}
`, meshName, vnName)
`, vnName)
}

func testAccAppmeshVirtualNodeConfig_logging(meshName, vnName, path string) string {
return fmt.Sprintf(`
resource "aws_appmesh_mesh" "foo" {
name = %[1]q
}

resource "aws_appmesh_virtual_node" "foo" {
name = %[2]q
mesh_name = "${aws_appmesh_mesh.foo.id}"
return testAccAppmeshVirtualNodeConfig_mesh(meshName) + fmt.Sprintf(`
resource "aws_appmesh_virtual_node" "test" {
name = %[1]q
mesh_name = "${aws_appmesh_mesh.test.id}"

spec {
backend {
Expand All @@ -416,7 +493,7 @@ resource "aws_appmesh_virtual_node" "foo" {
logging {
access_log {
file {
path = %[3]q
path = %[2]q
}
}
}
Expand All @@ -428,25 +505,21 @@ resource "aws_appmesh_virtual_node" "foo" {
}
}
}
`, meshName, vnName, path)
`, vnName, path)
}

func testAccAppmeshVirtualNodeConfig_tags(meshName, vnName, tagKey1, tagValue1, tagKey2, tagValue2 string) string {
return fmt.Sprintf(`
resource "aws_appmesh_mesh" "foo" {
name = %[1]q
}

resource "aws_appmesh_virtual_node" "foo" {
name = %[2]q
mesh_name = "${aws_appmesh_mesh.foo.id}"
return testAccAppmeshVirtualNodeConfig_mesh(meshName) + fmt.Sprintf(`
resource "aws_appmesh_virtual_node" "test" {
name = %[1]q
mesh_name = "${aws_appmesh_mesh.test.id}"

spec {}

tags = {
%[3]s = %[4]q
%[5]s = %[6]q
%[2]s = %[3]q
%[4]s = %[5]q
}
}
`, meshName, vnName, tagKey1, tagValue1, tagKey2, tagValue2)
`, vnName, tagKey1, tagValue1, tagKey2, tagValue2)
}
Loading