From 3f41ea6972fb44390416d4991ad3239c36b6aa1b Mon Sep 17 00:00:00 2001 From: Atsushi Ishibashi Date: Thu, 5 Apr 2018 12:14:52 +0900 Subject: [PATCH] review --- aws/resource_aws_ecs_service.go | 20 +++++++++++--------- aws/resource_aws_ecs_service_test.go | 12 +++++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/aws/resource_aws_ecs_service.go b/aws/resource_aws_ecs_service.go index 380dc04a7bf..7de62c2c5d5 100644 --- a/aws/resource_aws_ecs_service.go +++ b/aws/resource_aws_ecs_service.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" ) var taskDefinitionRE = regexp.MustCompile("^([a-zA-Z0-9_-]+):([0-9]+)$") @@ -213,12 +214,14 @@ func resourceAwsEcsService() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "port": { - Type: schema.TypeInt, - Optional: true, + Type: schema.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 65536), }, "registry_arn": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validateArn, }, }, }, @@ -567,12 +570,11 @@ func flattenServiceRegistries(srs []*ecs.ServiceRegistry) []map[string]interface } results := make([]map[string]interface{}, 0) for _, sr := range srs { - c := make(map[string]interface{}) - if sr.Port != nil { - c["port"] = *sr.Port + c := map[string]interface{}{ + "registry_arn": aws.StringValue(sr.RegistryArn), } - if sr.RegistryArn != nil { - c["registry_arn"] = *sr.RegistryArn + if sr.Port != nil { + c["port"] = int(aws.Int64Value(sr.Port)) } results = append(results, c) } diff --git a/aws/resource_aws_ecs_service_test.go b/aws/resource_aws_ecs_service_test.go index a54dc51bdb7..27d4c87a7ec 100644 --- a/aws/resource_aws_ecs_service_test.go +++ b/aws/resource_aws_ecs_service_test.go @@ -102,6 +102,7 @@ func TestAccAWSEcsService_withARN(t *testing.T) { Config: testAccAWSEcsService(clusterName, tdName, svcName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcsServiceExists("aws_ecs_service.mongo", &service), + resource.TestCheckResourceAttr("aws_ecs_service.mongo", "service_registries.#", "0"), ), }, @@ -109,6 +110,7 @@ func TestAccAWSEcsService_withARN(t *testing.T) { Config: testAccAWSEcsServiceModified(clusterName, tdName, svcName), Check: resource.ComposeTestCheckFunc( testAccCheckAWSEcsServiceExists("aws_ecs_service.mongo", &service), + resource.TestCheckResourceAttr("aws_ecs_service.mongo", "service_registries.#", "0"), ), }, }, @@ -1750,7 +1752,7 @@ resource "aws_service_discovery_service" "test" { name = "tf-acc-sd-%s" dns_config { namespace_id = "${aws_service_discovery_private_dns_namespace.test.id}" - dns_records { + dns_records { ttl = 5 type = "SRV" } @@ -1763,7 +1765,7 @@ resource "aws_ecs_cluster" "test" { resource "aws_ecs_task_definition" "test" { family = "%s" - network_mode = "awsvpc" + network_mode = "awsvpc" container_definitions = <