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 routing policy and update the type of dns record #3273

Merged
merged 4 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions aws/resource_aws_service_discovery_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ func resourceAwsServiceDiscoveryService() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateServiceDiscoveryServiceDnsRecordsType,
ValidateFunc: validateStringIn("SRV", "A", "AAAA", "CNAME"),
},
},
},
},
"routing_policy": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateStringIn("MULTIVALUE", "WEIGHTED"),
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the API defaults to MULTIVALUE shouldn't we also set it as Default here to avoid diffs when the field is not defined?

},
},
},
Expand All @@ -81,7 +87,7 @@ func resourceAwsServiceDiscoveryService() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validateServiceDiscoveryServiceHealthCheckConfigType,
ValidateFunc: validateStringIn("HTTP", "HTTPS", "TCP"),
},
},
},
Expand Down Expand Up @@ -220,6 +226,9 @@ func expandServiceDiscoveryDnsConfig(configured map[string]interface{}) *service
drs[i] = dr
}
result.DnsRecords = drs
if v, ok := configured["routing_policy"]; ok && v != "" {
result.RoutingPolicy = aws.String(v.(string))
}

return result
}
Expand All @@ -228,6 +237,7 @@ func flattenServiceDiscoveryDnsConfig(config *servicediscovery.DnsConfig) []map[
result := map[string]interface{}{}

result["namespace_id"] = *config.NamespaceId
result["routing_policy"] = *config.RoutingPolicy
drs := make([]map[string]interface{}, 0)
for _, v := range config.DnsRecords {
dr := map[string]interface{}{}
Expand Down
5 changes: 5 additions & 0 deletions aws/resource_aws_service_discovery_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccAwsServiceDiscoveryService_private(t *testing.T) {
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"),
resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.routing_policy", "MULTIVALUE"),
resource.TestCheckResourceAttrSet("aws_service_discovery_service.test", "arn"),
),
},
Expand Down Expand Up @@ -58,6 +59,7 @@ func TestAccAwsServiceDiscoveryService_public(t *testing.T) {
resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_config.0.type", "HTTP"),
resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_config.0.failure_threshold", "5"),
resource.TestCheckResourceAttr("aws_service_discovery_service.test", "health_check_config.0.resource_path", "/path"),
resource.TestCheckResourceAttr("aws_service_discovery_service.test", "dns_config.0.routing_policy", "WEIGHTED"),
resource.TestCheckResourceAttrSet("aws_service_discovery_service.test", "arn"),
),
},
Expand Down Expand Up @@ -161,6 +163,7 @@ resource "aws_service_discovery_service" "test" {
ttl = 5
type = "A"
}
routing_policy = "MULTIVALUE"
}
}
`, rName, rName)
Expand Down Expand Up @@ -190,6 +193,7 @@ resource "aws_service_discovery_service" "test" {
ttl = 5
type = "AAAA"
}
routing_policy = "MULTIVALUE"
}
}
`, rName, rName)
Expand All @@ -210,6 +214,7 @@ resource "aws_service_discovery_service" "test" {
ttl = 5
type = "A"
}
routing_policy = "WEIGHTED"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some funny indentation here 👀

}
health_check_config {
failure_threshold = %d
Expand Down
24 changes: 0 additions & 24 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2146,30 +2146,6 @@ func validateAwsElastiCacheReplicationGroupAuthToken(v interface{}, k string) (w
return
}

func validateServiceDiscoveryServiceDnsRecordsType(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
validType := []string{"SRV", "A", "AAAA"}
for _, str := range validType {
if value == str {
return
}
}
errors = append(errors, fmt.Errorf("expected %s to be one of %v, got %s", k, validType, value))
return
}

func validateServiceDiscoveryServiceHealthCheckConfigType(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
validType := []string{"HTTP", "HTTPS", "TCP"}
for _, str := range validType {
if value == str {
return
}
}
errors = append(errors, fmt.Errorf("expected %s to be one of %v, got %s", k, validType, value))
return
}

func validateGameliftOperatingSystem(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
operatingSystems := map[string]bool{
Expand Down
50 changes: 0 additions & 50 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2949,56 +2949,6 @@ func TestValidateCognitoUserGroupName(t *testing.T) {
}
}

func TestValidateServiceDiscoveryServiceDnsRecordsType(t *testing.T) {
validTypes := []string{
"SRV",
"A",
"AAAA",
}
for _, v := range validTypes {
_, errors := validateServiceDiscoveryServiceDnsRecordsType(v, "")
if len(errors) != 0 {
t.Fatalf("%q should be a valid Service Discovery DNS Records Type: %q", v, errors)
}
}

invalidTypes := []string{
"hoge",
"srv",
}
for _, v := range invalidTypes {
_, errors := validateServiceDiscoveryServiceDnsRecordsType(v, "")
if len(errors) == 0 {
t.Fatalf("%q should be an invalid Service Discovery DNS Records Type", v)
}
}
}

func TestValidateServiceDiscoveryServiceHealthCheckConfigType(t *testing.T) {
validTypes := []string{
"HTTP",
"HTTPS",
"TCP",
}
for _, v := range validTypes {
_, errors := validateServiceDiscoveryServiceHealthCheckConfigType(v, "")
if len(errors) != 0 {
t.Fatalf("%q should be a valid Service Discovery Health Check Config Type: %q", v, errors)
}
}

invalidTypes := []string{
"hoge",
"tcp",
}
for _, v := range invalidTypes {
_, errors := validateServiceDiscoveryServiceHealthCheckConfigType(v, "")
if len(errors) == 0 {
t.Fatalf("%q should be an invalid Service Discovery Health Check Config Type", v)
}
}
}

func TestValidateCognitoUserPoolId(t *testing.T) {
validValues := []string{
"eu-west-1_Foo123",
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/service_discovery_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ resource "aws_service_discovery_service" "example" {
ttl = 10
type = "A"
}
routing_policy = "MULTIVALUE"
}
}
```
Expand Down Expand Up @@ -73,13 +74,14 @@ The following arguments are supported:

* `namespace_id` - (Required, ForceNew) The ID of the namespace to use for DNS configuration.
* `dns_records` - (Required) An array that contains one DnsRecord object for each resource record set.
* `routing_policy` - (Optional) The routing policy that you want to apply to all records that Route 53 creates when you register an instance and specify the service. Valid Values: MULTIVALUE, WEIGHTED

#### dns_records

The following arguments are supported:

* `ttl` - (Required) The amount of time, in seconds, that you want DNS resolvers to cache the settings for this resource record set.
* `type` - (Required, ForceNew) The type of the resource, which indicates the value that Amazon Route 53 returns in response to DNS queries. Valid Values: A, AAAA, SRV
* `type` - (Required, ForceNew) The type of the resource, which indicates the value that Amazon Route 53 returns in response to DNS queries. Valid Values: A, AAAA, SRV, CNAME

### health_check_config

Expand Down