Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushi-ishibashi committed Apr 5, 2018
1 parent f0a4347 commit 3f41ea6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
20 changes: 11 additions & 9 deletions aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)$")
Expand Down Expand Up @@ -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,
},
},
},
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 7 additions & 5 deletions aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ 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"),
),
},

{
Config: testAccAWSEcsServiceModified(clusterName, tdName, svcName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists("aws_ecs_service.mongo", &service),
resource.TestCheckResourceAttr("aws_ecs_service.mongo", "service_registries.#", "0"),
),
},
},
Expand Down Expand Up @@ -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"
}
Expand All @@ -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 = <<DEFINITION
[
{
Expand All @@ -1784,9 +1786,9 @@ resource "aws_ecs_service" "test" {
desired_count = 1
service_registries {
port = 34567
registry_arn = "${aws_service_discovery_service.test.arn}"
}
network_configuration {
registry_arn = "${aws_service_discovery_service.test.arn}"
}
network_configuration {
security_groups = ["${aws_security_group.test.id}"]
subnets = ["${aws_subnet.test.*.id}"]
}
Expand Down

0 comments on commit 3f41ea6

Please sign in to comment.