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

resource/aws_service_discovery_service: Support HealthCheckCustomConfig #4083

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
51 changes: 51 additions & 0 deletions aws/resource_aws_service_discovery_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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}
}
21 changes: 14 additions & 7 deletions aws/resource_aws_service_discovery_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions website/docs/r/service_discovery_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ resource "aws_service_discovery_service" "example" {
}
routing_policy = "MULTIVALUE"
}

health_check_custom_config {
failure_threshold = 1
}
}
```

Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down