From 37d411b1c176418dab357ed92e2392c541fcba5d Mon Sep 17 00:00:00 2001 From: Jeff Nappi Date: Thu, 5 Apr 2018 16:56:54 -0700 Subject: [PATCH] resource/aws_service_discovery_service: Support HealthCheckCustomConfig --- aws/resource_aws_service_discovery_service.go | 51 +++++++++++++++++++ ...urce_aws_service_discovery_service_test.go | 21 +++++--- .../r/service_discovery_service.html.markdown | 11 ++++ 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/aws/resource_aws_service_discovery_service.go b/aws/resource_aws_service_discovery_service.go index 38f07bb7377..25a8553e5eb 100644 --- a/aws/resource_aws_service_discovery_service.go +++ b/aws/resource_aws_service_discovery_service.go @@ -105,6 +105,21 @@ func resourceAwsServiceDiscoveryService() *schema.Resource { }, }, }, + "health_check_custom_config": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "failure_threshold": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + }, + }, + }, "arn": { Type: schema.TypeString, Computed: true, @@ -130,6 +145,11 @@ func resourceAwsServiceDiscoveryServiceCreate(d *schema.ResourceData, meta inter input.HealthCheckConfig = expandServiceDiscoveryHealthCheckConfig(hcconfig[0].(map[string]interface{})) } + healthCustomConfig := d.Get("health_check_custom_config").([]interface{}) + if len(healthCustomConfig) > 0 { + input.HealthCheckCustomConfig = expandServiceDiscoveryHealthCheckCustomConfig(healthCustomConfig[0].(map[string]interface{})) + } + resp, err := conn.CreateService(input) if err != nil { return err @@ -163,6 +183,7 @@ func resourceAwsServiceDiscoveryServiceRead(d *schema.ResourceData, meta interfa d.Set("description", service.Description) d.Set("dns_config", flattenServiceDiscoveryDnsConfig(service.DnsConfig)) d.Set("health_check_config", flattenServiceDiscoveryHealthCheckConfig(service.HealthCheckConfig)) + d.Set("health_check_custom_config", flattenServiceDiscoveryHealthCheckCustomConfig(service.HealthCheckCustomConfig)) return nil } @@ -322,3 +343,33 @@ func flattenServiceDiscoveryHealthCheckConfig(config *servicediscovery.HealthChe return []map[string]interface{}{result} } + +func expandServiceDiscoveryHealthCheckCustomConfig(configured map[string]interface{}) *servicediscovery.HealthCheckCustomConfig { + if len(configured) < 1 { + return nil + } + result := &servicediscovery.HealthCheckCustomConfig{} + + if v, ok := configured["failure_threshold"]; ok && v.(int) != 0 { + result.FailureThreshold = aws.Int64(int64(v.(int))) + } + + return result +} + +func flattenServiceDiscoveryHealthCheckCustomConfig(config *servicediscovery.HealthCheckCustomConfig) []map[string]interface{} { + if config == nil { + return nil + } + result := map[string]interface{}{} + + if config.FailureThreshold != nil { + result["failure_threshold"] = *config.FailureThreshold + } + + if len(result) < 1 { + return nil + } + + return []map[string]interface{}{result} +} diff --git a/aws/resource_aws_service_discovery_service_test.go b/aws/resource_aws_service_discovery_service_test.go index 851015a20d2..c752c3fb2df 100644 --- a/aws/resource_aws_service_discovery_service_test.go +++ b/aws/resource_aws_service_discovery_service_test.go @@ -19,9 +19,10 @@ func TestAccAWSServiceDiscoveryService_private(t *testing.T) { CheckDestroy: testAccCheckAwsServiceDiscoveryServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccServiceDiscoveryServiceConfig_private(rName), + Config: testAccServiceDiscoveryServiceConfig_private(rName, 5), Check: resource.ComposeTestCheckFunc( testAccCheckAwsServiceDiscoveryServiceExists("aws_service_discovery_service.test"), + resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_custom_config.0.failure_threshold", "5"), resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.#", "1"), resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.0.type", "A"), resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.0.ttl", "5"), @@ -30,7 +31,7 @@ func TestAccAWSServiceDiscoveryService_private(t *testing.T) { ), }, { - Config: testAccServiceDiscoveryServiceConfig_private_update(rName), + Config: testAccServiceDiscoveryServiceConfig_private_update(rName, 5), Check: resource.ComposeTestCheckFunc( testAccCheckAwsServiceDiscoveryServiceExists("aws_service_discovery_service.test"), resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.dns_records.#", "2"), @@ -86,7 +87,7 @@ func TestAccAWSServiceDiscoveryService_import(t *testing.T) { CheckDestroy: testAccCheckAwsServiceDiscoveryServiceDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccServiceDiscoveryServiceConfig_private(acctest.RandString(5)), + Config: testAccServiceDiscoveryServiceConfig_private(acctest.RandString(5), 5), }, resource.TestStep{ @@ -143,7 +144,7 @@ func testAccCheckAwsServiceDiscoveryServiceExists(name string) resource.TestChec } } -func testAccServiceDiscoveryServiceConfig_private(rName string) string { +func testAccServiceDiscoveryServiceConfig_private(rName string, th int) string { return fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -167,11 +168,14 @@ resource "aws_service_discovery_service" "test" { type = "A" } } + health_check_custom_config { + failure_threshold = %d + } } -`, rName, rName) +`, rName, rName, th) } -func testAccServiceDiscoveryServiceConfig_private_update(rName string) string { +func testAccServiceDiscoveryServiceConfig_private_update(rName string, th int) string { return fmt.Sprintf(` resource "aws_vpc" "test" { cidr_block = "10.0.0.0/16" @@ -200,8 +204,11 @@ resource "aws_service_discovery_service" "test" { } routing_policy = "MULTIVALUE" } + health_check_custom_config { + failure_threshold = %d + } } -`, rName, rName) +`, rName, rName, th) } func testAccServiceDiscoveryServiceConfig_public(rName string, th int, path string) string { diff --git a/website/docs/r/service_discovery_service.html.markdown b/website/docs/r/service_discovery_service.html.markdown index cb3768d9603..1c67cc46171 100644 --- a/website/docs/r/service_discovery_service.html.markdown +++ b/website/docs/r/service_discovery_service.html.markdown @@ -33,6 +33,10 @@ resource "aws_service_discovery_service" "example" { } routing_policy = "MULTIVALUE" } + + health_check_custom_config { + failure_threshold = 1 + } } ``` @@ -67,6 +71,7 @@ The following arguments are supported: * `description` - (Optional) The description of the service. * `dns_config` - (Required) A complex type that contains information about the resource record sets that you want Amazon Route 53 to create when you register an instance. * `health_check_config` - (Optional) A complex type that contains settings for an optional health check. Only for Public DNS namespaces. +* `health_check_custom_config` - (Optional, ForceNew) A complex type that contains settings for ECS managed health checks. ### dns_config @@ -91,6 +96,12 @@ The following arguments are supported: * `resource_path` - (Optional) An array that contains one DnsRecord object for each resource record set. * `type` - (Optional, ForceNew) An array that contains one DnsRecord object for each resource record set. +### health_check_custom_config + +The following arguments are supported: + +* `failure_threshold` - (Optional, ForceNew) The number of 30-second intervals that you want service discovery to wait before it changes the health status of a service instance. Maximum value of 10. + ## Attributes Reference The following attributes are exported: